From 86c7c9856d870965344de87bf2377d50284d0a01 Mon Sep 17 00:00:00 2001 From: Samq64 <81489795+Samq64@users.noreply.github.com> Date: Wed, 30 Aug 2023 12:54:44 -0400 Subject: [PATCH] Port anti-generic to V2 --- features/anti-generic.js | 252 -------------------------------- features/anti-generic/data.json | 28 ++++ features/anti-generic/script.js | 117 +++++++++++++++ features/features.json | 19 +-- 4 files changed, 149 insertions(+), 267 deletions(-) delete mode 100644 features/anti-generic.js create mode 100644 features/anti-generic/data.json create mode 100644 features/anti-generic/script.js diff --git a/features/anti-generic.js b/features/anti-generic.js deleted file mode 100644 index 973263f0..00000000 --- a/features/anti-generic.js +++ /dev/null @@ -1,252 +0,0 @@ -function cleanUp() { - if (allowCleanUp) { - var titles = []; - document.querySelectorAll("div.thumbnail.project").forEach(function (el) { - var title = el - .querySelector("div.thumbnail-title") - .firstChild.textContent.toLowerCase(); - if (title.includes("part ")) { - el.style.display = "none"; - } - if (title.includes("#trending")) { - el.style.display = "none"; - } - if (title.includes("test")) { - el.style.display = "none"; - } - if (title.includes("gf")) { - el.style.display = "none"; - } - if (title.includes("bf")) { - el.style.display = "none"; - } - if (title.includes("girlfriend")) { - el.style.display = "none"; - } - if (title.includes("boyfriend")) { - - el.style.display = "none"; - } - if (title.includes("doors")) { - - el.style.display = "none"; - } - if (title.includes("scp")) { - - el.style.display = "none"; - } - if (title.includes("speedrun platformer")) { - - el.style.display = "none"; - } - if (title.includes("cave platformer")) { - - el.style.display = "none"; - } - if (title.includes("dark platformer")) { - - el.style.display = "none"; - } - if (title.includes("jungle platformer")) { - - el.style.display = "none"; - } - if (title.includes("platformer 1")) { - - el.style.display = "none"; - } - if (title.includes("platformer 2")) { - - el.style.display = "none"; - } - if (title.includes("platformer 3")) { - - el.style.display = "none"; - } - if (title.includes("fnf")) { - - el.style.display = "none"; - } - if (title.includes("funkin")) { - - el.style.display = "none"; - } - if (title.includes("vs")) { - - el.style.display = "none"; - } - if (title.includes("Add yourself")) { - - el.style.display = "none"; - } - if (title.includes("your oc")) { - - el.style.display = "none"; - } - if (title.includes("scratch's smooth saturday")) { - - el.style.display = "none"; - } - if (title.includes("dave")) { - - el.style.display = "none"; - } - if (title.includes("bambi")) { - - el.style.display = "none"; - } - if (title.includes("fnf vs")) { - - el.style.display = "none"; - } - if (title.includes("friday night funkin")) { - - el.style.display = "none"; - } - if (title.includes("funk")) { - - el.style.display = "none"; - } - if (title.includes("sarvente")) { - - el.style.display = "none"; - } - if (title.includes("singing")) { - - el.style.display = "none"; - } - if (title.includes("ays")) { - - el.style.display = "none"; - } - if (title.includes("ays/oc")) { - - el.style.display = "none"; - } - if (title.includes("friday night")) { - - el.style.display = "none"; - } - if (title.includes("scratched out")) { - - el.style.display = "none"; - } - if (title.includes("dave and bambi")) { - - el.style.display = "none"; - } - if (title.includes("dark") && title.includes("platformer")) { - - el.style.display = "none"; - } - if (title.includes("friday night") && title.includes("funkin")) { - - el.style.display = "none"; - } - if (title.includes("dave") && title.includes("bambi")) { - - el.style.display = "none"; - } - if (title.includes("fnf") && title.includes("vs")) { - - el.style.display = "none"; - } - if (title.includes("funkin") && title.includes("vs")) { - - el.style.display = "none"; - } - if (title.includes("generic") && title.includes("platformer")) { - - el.style.display = "none"; - } - if (title.includes("jungle") && title.includes("platformer")) { - - el.style.display = "none"; - } - if (title.includes("night") && title.includes("platformer")) { - - el.style.display = "none"; - } - if (title.includes("OST")) { - - el.style.display = "none"; - } - if (countInstances(title, "#") > 3) { - - el.style.display = "none"; - } - if (title.includes("alphabet") && title.includes("lore")) { - - el.style.display = "none"; - } - titles.forEach(function (el2) { - if (similarity(el2, title) > 0.5) { - if (el !== undefined && el !== null) { - - el.style.display = "none"; - } - } - }); - titles.push(title); - }); - - function countInstances(string, word) { - return string.split(word).length - 1; - } - - function editDistance(s1, s2) { - s1 = s1.toLowerCase(); - s2 = s2.toLowerCase(); - - var costs = new Array(); - for (var i = 0; i <= s1.length; i++) { - var lastValue = i; - for (var j = 0; j <= s2.length; j++) { - if (i == 0) costs[j] = j; - else { - if (j > 0) { - var newValue = costs[j - 1]; - if (s1.charAt(i - 1) != s2.charAt(j - 1)) - newValue = - Math.min(Math.min(newValue, lastValue), costs[j]) + 1; - costs[j - 1] = lastValue; - lastValue = newValue; - } - } - } - if (i > 0) costs[s2.length] = lastValue; - } - return costs[s2.length]; - } - - function similarity(s1, s2) { - var longer = s1; - var shorter = s2; - if (s1.length < s2.length) { - longer = s2; - shorter = s1; - } - var longerLength = longer.length; - if (longerLength == 0) { - return 1.0; - } - return ( - (longerLength - editDistance(longer, shorter)) / - parseFloat(longerLength) - ); - } - if (window.location.href.includes("https://scratch.mit.edu/explore/")) { - setTimeout(cleanUp, 200); - } - } -} -if (window.location.href.includes("https://scratch.mit.edu/explore/")) { - var allowCleanUp = true; - cleanUp(); - ScratchTools.setDisable("anti-generic", function () { - allowCleanUp = false; - document.querySelectorAll("div.thumbnail.project").forEach(function (el) { - el.style.display = null; - }); - }); -} diff --git a/features/anti-generic/data.json b/features/anti-generic/data.json new file mode 100644 index 00000000..b2ecc9f4 --- /dev/null +++ b/features/anti-generic/data.json @@ -0,0 +1,28 @@ +{ + "title": "Anti Generic", + "description": "On the explore and trending pages, this beta feature automatically hides repetitive projects, along with projects that it expects are generic. This includes projects with a lot of tags, common names, and project duplicates.", + "credits": [ + { + "username": "Bob the Potato wit Drip Jr.", + "url": "https://scratch.mit.edu/users/JefferyTheSuperKat/" + }, + { + "username": "rgantzos", + "url": "https://scratch.mit.edu/users/rgantzos/" + }, + { + "username": "mrfurretguy", + "url": "https://scratch.mit.edu/users/MrAK2006/" + } + ], + "scripts": [ + { + "file": "script.js", + "runOn": "/explore/*" + } + ], + "tags": ["Beta", "Featured"], + "type": ["Website", "Theme"], + "dynamic": true, + "warning": "This feature uses an algorithm that ScratchTools developed, so it may not work every time." +} diff --git a/features/anti-generic/script.js b/features/anti-generic/script.js new file mode 100644 index 00000000..c1fbd6ad --- /dev/null +++ b/features/anti-generic/script.js @@ -0,0 +1,117 @@ +export default async function ({ feature, console }) { + let allowCleanUp = true; + + function cleanUp() { + if (!allowCleanUp) return; + let titles = []; + document.querySelectorAll("div.thumbnail.project").forEach((el) => { + const title = el + .querySelector("div.thumbnail-title") + .firstChild.textContent.toLowerCase(); + if ( + title.includes("part ") || + title.includes("#trending") || + title.includes("test") || + title.includes("gf") || + title.includes("bf") || + title.includes("girlfriend") || + title.includes("boyfriend") || + title.includes("doors") || + title.includes("scp") || + title.includes("speedrun platformer") || + title.includes("cave platformer") || + title.includes("platformer 1") || + title.includes("platformer 2") || + title.includes("platformer 3") || + title.includes("friday night") || + title.includes("fnf") || + title.includes("funk") || + title.includes("vs") || + title.includes("Add yourself") || + title.includes("ays") || + title.includes("your oc") || + title.includes("scratch's smooth saturday") || + title.includes("dave") || + title.includes("bambi") || + title.includes("sarvente") || + title.includes("singing") || + title.includes("scratched out") || + title.includes("ost") || + (title.includes("dark") && title.includes("platformer")) || + (title.includes("generic") && title.includes("platformer")) || + (title.includes("jungle") && title.includes("platformer")) || + (title.includes("night") && title.includes("platformer")) || + (title.includes("alphabet") && title.includes("lore")) || + countInstances(title, "#") > 3 + ) + el.style.display = "none"; + + titles.forEach(function (el2) { + if (similarity(el2, title) > 0.5) { + if (el !== undefined && el !== null) { + el.style.display = "none"; + } + } + }); + titles.push(title); + }); + + function countInstances(string, word) { + return string.split(word).length - 1; + } + + function editDistance(s1, s2) { + s1 = s1.toLowerCase(); + s2 = s2.toLowerCase(); + + var costs = new Array(); + for (var i = 0; i <= s1.length; i++) { + var lastValue = i; + for (var j = 0; j <= s2.length; j++) { + if (i == 0) costs[j] = j; + else { + if (j > 0) { + var newValue = costs[j - 1]; + if (s1.charAt(i - 1) != s2.charAt(j - 1)) + newValue = + Math.min(Math.min(newValue, lastValue), costs[j]) + 1; + costs[j - 1] = lastValue; + lastValue = newValue; + } + } + } + if (i > 0) costs[s2.length] = lastValue; + } + return costs[s2.length]; + } + + function similarity(s1, s2) { + var longer = s1; + var shorter = s2; + if (s1.length < s2.length) { + longer = s2; + shorter = s1; + } + var longerLength = longer.length; + if (longerLength == 0) { + return 1.0; + } + return ( + (longerLength - editDistance(longer, shorter)) / + parseFloat(longerLength) + ); + } + } + + cleanUp(); + document + .querySelector("#projectBox button") + .addEventListener("click", () => cleanUp()); + + ScratchTools.setDisable("anti-generic", () => { + allowCleanUp = false; + document.querySelectorAll("div.thumbnail.project").forEach((el) => { + el.style.display = "block"; + }); + }); +} diff --git a/features/features.json b/features/features.json index 69c34886..39fe2000 100644 --- a/features/features.json +++ b/features/features.json @@ -217,6 +217,10 @@ "version": 2, "id": "box-shadows" }, + { + "version": 2, + "id": "anti-generic" +}, { "title": "Nicknames", "description": "Set nicknames for other Scratchers. Only you can see the nicknames, and their username will be replaced with the nickname when you see their name.", @@ -711,21 +715,6 @@ "tags": ["Featured"], "type": ["Website"] }, - { - "title": "Anti Generic", - "description": "On the explore and trending pages, this beta feature automatically hides repetitive projects, along with projects that it expects are generic. This includes projects with a lot of tags, common names, and project duplicates.", - "credits": ["Bob the Potato wit Drip Jr.", "rgantzos", "mrfurretguy"], - "urls": [ - "https://scratch.mit.edu/users/JefferyTheSuperKat/", - "https://scratch.mit.edu/users/rgantzos/", - "https://scratch.mit.edu/users/MrAK2006/" - ], - "file": "anti-generic", - "tags": ["Beta", "Featured"], - "type": ["Website", "Theme"], - "dynamic": true, - "warning": "This feature uses an algorithm that ScratchTools developed. That does not mean that it will work every time." - }, { "title": "Collapse Blocks", "description": "Right-click block menus in the editor include a button that will let you collapse the selected block.",