Skip to content

Commit e167e9d

Browse files
authored
Merge branch 'STForScratch:main' into main
2 parents 700751a + fad15de commit e167e9d

9 files changed

Lines changed: 191 additions & 273 deletions

File tree

extras/feature-locales/en.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

features/anti-generic.js

Lines changed: 0 additions & 252 deletions
This file was deleted.

features/anti-generic/data.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"title": "Anti Generic",
3+
"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.",
4+
"credits": [
5+
{
6+
"username": "Bob the Potato wit Drip Jr.",
7+
"url": "https://scratch.mit.edu/users/JefferyTheSuperKat/"
8+
},
9+
{
10+
"username": "rgantzos",
11+
"url": "https://scratch.mit.edu/users/rgantzos/"
12+
},
13+
{
14+
"username": "mrfurretguy",
15+
"url": "https://scratch.mit.edu/users/MrAK2006/"
16+
}
17+
],
18+
"scripts": [
19+
{
20+
"file": "script.js",
21+
"runOn": "/explore/*"
22+
}
23+
],
24+
"tags": ["Beta", "Featured"],
25+
"type": ["Website", "Theme"],
26+
"dynamic": true,
27+
"warning": "This feature uses an algorithm that ScratchTools developed, so it may not work every time."
28+
}

features/anti-generic/script.js

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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

Comments
 (0)