diff --git a/scripts/clean-spams.js b/scripts/clean-spams.js
index b2f89ac..ff5a850 100644
--- a/scripts/clean-spams.js
+++ b/scripts/clean-spams.js
@@ -65,7 +65,7 @@ const restoreText = "⟲ Restore comment";
const hideText = "⟳ Hide spam"
function createRestoreButton(node, restoreKey) {
- const restoreButton = htmlToElement(``);
+ const restoreButton = htmlToElement(`${restoreText}`);
restoreButton.addEventListener("click", () => {
swapStoredContent(node, restoreKey);
restoreButton.innerText = restoreButton.innerText === restoreText ? hideText : restoreText;
@@ -73,6 +73,16 @@ function createRestoreButton(node, restoreKey) {
return restoreButton;
}
+function createBlackListButton(spamDomain) {
+ const button = htmlToElement(`✖ Blacklist domain`);
+ button.addEventListener("click", async () => {
+ let { banDomains } = await browser.storage.local.get(["banDomains"]);
+ banDomains = Array.from(new Set([...banDomains, spamDomain]));
+ await browser.storage.local.set({ banDomains });
+ });
+ return button;
+}
+
// Actions
function remove(node) {
@@ -170,8 +180,32 @@ async function cleanSpams() {
.map(count);
console.log(`Found ${spamCount} spams`);
+
+ addBlackListButtons();
}
+function addBlackListButtons() {
+ let links = window.document.querySelectorAll("._3-8y:not(.spam-comment-root) ._5mdd a");
+ links = Array.from(new Set(links));
+ links
+ .forEach((node) => {
+ try {
+ const spamLink = new URL(node.href).searchParams.get("u");
+ const spamDomain = spamLink ? new URL(spamLink).host : node.href;
+
+ const buttonContainer = getAncestor(node, 9, "_3-8y").querySelector("._2vq9");
+ if (!buttonContainer.querySelector(".additional-button")) {
+ buttonContainer.appendChild(htmlToElement(` · `));
+ buttonContainer.appendChild(createBlackListButton(spamDomain));
+ }
+ } catch (e) {
+ console.error(e);
+ console.log(node.href);
+ }
+ })
+}
+
+
cleanSpams().catch(console.error);
browser.storage.local.get(["clearSpamInterval"])
.then(({ clearSpamInterval }) => setInterval(cleanSpams, clearSpamInterval))
diff --git a/scripts/service-worker.js b/scripts/service-worker.js
index c7b8fb0..d48cce0 100644
--- a/scripts/service-worker.js
+++ b/scripts/service-worker.js
@@ -105,8 +105,8 @@ browser.runtime.onInstalled.addListener(async () => {
installedVersion = installedVersion || "0.1";
for (let [ver, migrate] of migrations) {
if (installedVersion < ver) {
- console.log(`Migrating to version ${ver}`)
- await migrate()
+ console.log(`Migrating to version ${ver}`);
+ await migrate();
}
}
} catch (e) {
diff --git a/styles/facebook-comment-plugin.css b/styles/facebook-comment-plugin.css
index c7b864e..25473f3 100644
--- a/styles/facebook-comment-plugin.css
+++ b/styles/facebook-comment-plugin.css
@@ -2,12 +2,12 @@
background-color: #ececec;
}
-.restore-comment {
+.additional-button {
cursor: pointer;
font-weight: bold;
color: #3b64b6;
}
-.restore-comment:hover {
+.additional-button:hover {
text-decoration: underline;
}