From 2bff0eae7607c7eca3f3dba7d461003ee1ff2289 Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Sat, 6 Jun 2020 12:32:36 -0400 Subject: [PATCH] Allow configuration of the blacklist --- background.js | 3 +++ config.css | 2 ++ config.html | 15 +++++++++++++++ config.js | 17 +++++++++++++++++ filter.js | 2 +- inject.js | 9 ++------- manifest.json | 17 ++++++++++++++++- run-filter.js | 11 +++++++++++ 8 files changed, 67 insertions(+), 9 deletions(-) create mode 100644 background.js create mode 100644 config.css create mode 100644 config.html create mode 100644 config.js create mode 100644 run-filter.js diff --git a/background.js b/background.js new file mode 100644 index 0000000..0bdcea6 --- /dev/null +++ b/background.js @@ -0,0 +1,3 @@ +chrome.runtime.onInstalled.addListener(() => { + chrome.storage.sync.set({"blacklist": JSON.stringify(["reminder"])}); +}); \ No newline at end of file diff --git a/config.css b/config.css new file mode 100644 index 0000000..f616292 --- /dev/null +++ b/config.css @@ -0,0 +1,2 @@ +#blacklist { +} \ No newline at end of file diff --git a/config.html b/config.html new file mode 100644 index 0000000..f6defc5 --- /dev/null +++ b/config.html @@ -0,0 +1,15 @@ + + + FurAffinity Filter + + + + + Blacklisted words: + + + + + \ No newline at end of file diff --git a/config.js b/config.js new file mode 100644 index 0000000..3f48c48 --- /dev/null +++ b/config.js @@ -0,0 +1,17 @@ +document.addEventListener("DOMContentLoaded", e => { + const textArea = document.querySelector("#blacklist"); + + chrome.storage.sync.get("blacklist", result => { + if (result.blacklist) { + textArea.value = JSON.parse(result.blacklist).join("\n"); + } else { + textArea.value = ""; + } + }); + + textArea.addEventListener("change", e => { + const blacklist = e.target.value.toLowerCase().split("\n").map(line => line.trim()).filter(line => line.length > 0); + + chrome.storage.sync.set({"blacklist": JSON.stringify(blacklist)}); + }); +}); \ No newline at end of file diff --git a/filter.js b/filter.js index 5e37273..12b72b8 100644 --- a/filter.js +++ b/filter.js @@ -3,4 +3,4 @@ const script = document.createElement("script"); script.src = chrome.extension.getURL("inject.js"); (document.head || document.documentElement).appendChild(script); -script.onload = script.remove; \ No newline at end of file +script.onload = script.remove; diff --git a/inject.js b/inject.js index 63091a2..5ff2b26 100644 --- a/inject.js +++ b/inject.js @@ -1,15 +1,10 @@ "use strict"; -_fajs.push(['fa_filter_execute']); - -function fa_filter_execute() { +function fa_filter_execute(blacklist) { + console.log(blacklist); const gallery = document.querySelector("#gallery-frontpage-submissions"); const submissions = gallery.querySelectorAll("figure"); - const blacklist = [ - "reminder", - ] - submissions.forEach(sub => { const title = sub.querySelector("figcaption > p > a").title.toLowerCase(); diff --git a/manifest.json b/manifest.json index ea1a2a6..c9dd7e6 100644 --- a/manifest.json +++ b/manifest.json @@ -2,16 +2,31 @@ "name": "FurAffinity Filter", "version": "0.1", "description": "Filters out reminder/YCH/adopt spam from the front page", - "permissions": ["tabs", "*://www.furaffinity.net/"], + "permissions": [ + "tabs", + "*://www.furaffinity.net/", + "storage" + ], "web_accessible_resources": [ "inject.js" ], + "background": { + "scripts": ["background.js"] + }, "content_scripts": [ { "run_at": "document_start", "matches": ["*://www.furaffinity.net/"], "js": ["filter.js"] + }, + { + "run_at": "document_end", + "matches": ["*://www.furaffinity.net/"], + "js": ["run-filter.js"] } ], + "browser_action": { + "default_popup": "config.html" + }, "manifest_version": 2 } \ No newline at end of file diff --git a/run-filter.js b/run-filter.js new file mode 100644 index 0000000..0f73056 --- /dev/null +++ b/run-filter.js @@ -0,0 +1,11 @@ + +chrome.storage.sync.get("blacklist", result => { + const runScript = document.createElement("script"); + console.log("Result: " + result.blacklist); + console.log(JSON.parse(result.blacklist)); + runScript.textContent = "(" + function(blacklist) { + console.log(blacklist) + fa_filter_execute(blacklist); + } + ")(" + result.blacklist + ")"; + (document.head || document.documentElement).appendChild(runScript); +}); \ No newline at end of file