|
| 1 | +export default async function ({ feature, console }) { |
| 2 | + let allowCleanUp = true; |
| 3 | + |
| 4 | + function cleanUp() { |
| 5 | + if (!allowCleanUp) return; |
| 6 | + let titles = []; |
| 7 | + document.querySelectorAll("div.thumbnail.project").forEach((el) => { |
| 8 | + const title = el |
| 9 | + .querySelector("div.thumbnail-title") |
| 10 | + .firstChild.textContent.toLowerCase(); |
| 11 | + if ( |
| 12 | + title.includes("part ") || |
| 13 | + title.includes("#trending") || |
| 14 | + title.includes("test") || |
| 15 | + title.includes("gf") || |
| 16 | + title.includes("bf") || |
| 17 | + title.includes("girlfriend") || |
| 18 | + title.includes("boyfriend") || |
| 19 | + title.includes("doors") || |
| 20 | + title.includes("scp") || |
| 21 | + title.includes("speedrun platformer") || |
| 22 | + title.includes("cave platformer") || |
| 23 | + title.includes("platformer 1") || |
| 24 | + title.includes("platformer 2") || |
| 25 | + title.includes("platformer 3") || |
| 26 | + title.includes("friday night") || |
| 27 | + title.includes("fnf") || |
| 28 | + title.includes("funk") || |
| 29 | + title.includes("vs") || |
| 30 | + title.includes("Add yourself") || |
| 31 | + title.includes("ays") || |
| 32 | + title.includes("your oc") || |
| 33 | + title.includes("scratch's smooth saturday") || |
| 34 | + title.includes("dave") || |
| 35 | + title.includes("bambi") || |
| 36 | + title.includes("sarvente") || |
| 37 | + title.includes("singing") || |
| 38 | + title.includes("scratched out") || |
| 39 | + title.includes("ost") || |
| 40 | + (title.includes("dark") && title.includes("platformer")) || |
| 41 | + (title.includes("generic") && title.includes("platformer")) || |
| 42 | + (title.includes("jungle") && title.includes("platformer")) || |
| 43 | + (title.includes("night") && title.includes("platformer")) || |
| 44 | + (title.includes("alphabet") && title.includes("lore")) || |
| 45 | + countInstances(title, "#") > 3 |
| 46 | + ) |
| 47 | + el.style.display = "none"; |
| 48 | + |
| 49 | + titles.forEach(function (el2) { |
| 50 | + if (similarity(el2, title) > 0.5) { |
| 51 | + if (el !== undefined && el !== null) { |
| 52 | + el.style.display = "none"; |
| 53 | + } |
| 54 | + } |
| 55 | + }); |
| 56 | + titles.push(title); |
| 57 | + }); |
| 58 | + |
| 59 | + function countInstances(string, word) { |
| 60 | + return string.split(word).length - 1; |
| 61 | + } |
| 62 | + |
| 63 | + function editDistance(s1, s2) { |
| 64 | + s1 = s1.toLowerCase(); |
| 65 | + s2 = s2.toLowerCase(); |
| 66 | + |
| 67 | + var costs = new Array(); |
| 68 | + for (var i = 0; i <= s1.length; i++) { |
| 69 | + var lastValue = i; |
| 70 | + for (var j = 0; j <= s2.length; j++) { |
| 71 | + if (i == 0) costs[j] = j; |
| 72 | + else { |
| 73 | + if (j > 0) { |
| 74 | + var newValue = costs[j - 1]; |
| 75 | + if (s1.charAt(i - 1) != s2.charAt(j - 1)) |
| 76 | + newValue = |
| 77 | + Math.min(Math.min(newValue, lastValue), costs[j]) + 1; |
| 78 | + costs[j - 1] = lastValue; |
| 79 | + lastValue = newValue; |
| 80 | + } |
| 81 | + } |
| 82 | + } |
| 83 | + if (i > 0) costs[s2.length] = lastValue; |
| 84 | + } |
| 85 | + return costs[s2.length]; |
| 86 | + } |
| 87 | + |
| 88 | + function similarity(s1, s2) { |
| 89 | + var longer = s1; |
| 90 | + var shorter = s2; |
| 91 | + if (s1.length < s2.length) { |
| 92 | + longer = s2; |
| 93 | + shorter = s1; |
| 94 | + } |
| 95 | + var longerLength = longer.length; |
| 96 | + if (longerLength == 0) { |
| 97 | + return 1.0; |
| 98 | + } |
| 99 | + return ( |
| 100 | + (longerLength - editDistance(longer, shorter)) / |
| 101 | + parseFloat(longerLength) |
| 102 | + ); |
| 103 | + } |
| 104 | + } |
| 105 | + |
| 106 | + cleanUp(); |
| 107 | + document |
| 108 | + .querySelector("#projectBox button") |
| 109 | + .addEventListener("click", () => cleanUp()); |
| 110 | + |
| 111 | + ScratchTools.setDisable("anti-generic", () => { |
| 112 | + allowCleanUp = false; |
| 113 | + document.querySelectorAll("div.thumbnail.project").forEach((el) => { |
| 114 | + el.style.display = "block"; |
| 115 | + }); |
| 116 | + }); |
| 117 | +} |
0 commit comments