From 61ca7d6a7f17c488b2be08705969319d08291622 Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Sat, 6 Jun 2020 11:19:21 -0400 Subject: [PATCH] Reflow the gallery; inject the filter script so it can do so --- filter.js | 22 ++++------------------ inject.js | 26 ++++++++++++++++++++++++++ manifest.json | 5 ++++- 3 files changed, 34 insertions(+), 19 deletions(-) create mode 100644 inject.js diff --git a/filter.js b/filter.js index dec69aa..5e37273 100644 --- a/filter.js +++ b/filter.js @@ -1,20 +1,6 @@ "use strict"; -const gallery = document.querySelector("#gallery-frontpage-submissions"); -const submissions = gallery.querySelectorAll("figure"); - -const blacklist = [ - "ych", - "adopt", - "reminder", - "auction" -] - -submissions.forEach(sub => { - const title = sub.querySelector("figcaption > p > a").title.toLowerCase(); - console.log(title); - - if (blacklist.some(word => title.indexOf(word) != -1)) { - gallery.removeChild(sub); - } -}); \ No newline at end of file +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 diff --git a/inject.js b/inject.js new file mode 100644 index 0000000..63091a2 --- /dev/null +++ b/inject.js @@ -0,0 +1,26 @@ +"use strict"; + +_fajs.push(['fa_filter_execute']); + +function fa_filter_execute() { + 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(); + + if (blacklist.some(word => title.indexOf(word) != -1)) { + gallery.removeChild(sub); + } else if (sub.style.display == "none") { + sub.style.display = ""; + } + + + }); + + _reflow_gallery(gallery); +} diff --git a/manifest.json b/manifest.json index 856d79d..ea1a2a6 100644 --- a/manifest.json +++ b/manifest.json @@ -3,9 +3,12 @@ "version": "0.1", "description": "Filters out reminder/YCH/adopt spam from the front page", "permissions": ["tabs", "*://www.furaffinity.net/"], + "web_accessible_resources": [ + "inject.js" + ], "content_scripts": [ { - "run_at": "document_idle", + "run_at": "document_start", "matches": ["*://www.furaffinity.net/"], "js": ["filter.js"] }