Skip to content

Commit 3229de6

Browse files
rgantzosMaterArc
andauthored
Merge pull request #747 from STForScratch/MaterArc-patch-16
Consolidate Project Tags Co-authored-by: MaterArc <105017592+materarc@users.noreply.github.com>
2 parents 3f7af91 + 9284978 commit 3229de6

4 files changed

Lines changed: 84 additions & 25 deletions

File tree

features/features.json

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
[
2+
{
3+
"version": 2,
4+
"id": "hide-project-tags",
5+
"versionAdded": "v3.9.0"
6+
},
27
{
38
"version": 2,
49
"id": "snap-to-grid",
@@ -517,16 +522,6 @@
517522
"tags": ["New", "Recommended"],
518523
"dynamic": true
519524
},
520-
{
521-
"title": "Hide Project Tags",
522-
"description": "Hides all linked tags in the Instructions/Notes and Credits of projects.",
523-
"credits": ["rgantzos"],
524-
"urls": ["https://scratch.mit.edu/users/rgantzos/"],
525-
"file": "hide-project-tags",
526-
"type": ["Website"],
527-
"tags": ["New"],
528-
"dynamic": true
529-
},
530525
{
531526
"title": "Search Assets",
532527
"description": "Search through costume and sound assets in the editor.",

features/hide-project-tags.js

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"title": "Hide Project Tags",
3+
"description": "Hides all linked tags in the Instructions/Notes and Credits of projects.",
4+
"credits": [
5+
{
6+
"username": "MaterArc",
7+
"url": "https://scratch.mit.edu/users/MaterArc/"
8+
},
9+
{
10+
"username": "rgantzos",
11+
"url": "https://scratch.mit.edu/users/rgantzos/"
12+
}
13+
],
14+
"type": [
15+
"Website"
16+
],
17+
"tags": [
18+
"New",
19+
"Featured"
20+
],
21+
"scripts": [
22+
{
23+
"file": "script.js",
24+
"runOn": "/projects/*"
25+
}
26+
],
27+
"dynamic": true,
28+
"options": [{ "id": "remove-dupes", "name": "Hide Duplicate Tags", "type": 1 }]
29+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
export default async function ({ feature, console }) {
2+
let ALL_TAGS = []
3+
4+
ScratchTools.waitForElements('.project-description a[href*="/search/projects?q="]:not(.scratchtoolsTag)', function (tag) {
5+
if (tag.textContent?.startsWith("#")) {
6+
ALL_TAGS.push({
7+
tag,
8+
content: tag.textContent.toLowerCase(),
9+
})
10+
11+
update()
12+
}
13+
})
14+
15+
function update() {
16+
if (feature.self.enabled) {
17+
let dupesOnly = feature.settings.get("remove-dupes")
18+
19+
if (dupesOnly) {
20+
for (var i in ALL_TAGS) {
21+
if (ALL_TAGS.filter((tag) => tag.content === ALL_TAGS[i].content)[0].tag === ALL_TAGS[i].tag) {
22+
if (ALL_TAGS[i].tag?.style) {
23+
ALL_TAGS[i].tag.style.display = null
24+
}
25+
} else {
26+
if (ALL_TAGS[i].tag?.style) {
27+
ALL_TAGS[i].tag.style.display = "none"
28+
}
29+
}
30+
}
31+
} else {
32+
for (var i in ALL_TAGS) {
33+
if (ALL_TAGS[i].tag?.style) {
34+
ALL_TAGS[i].tag.style.display = "none"
35+
}
36+
}
37+
}
38+
} else {
39+
for (var i in ALL_TAGS) {
40+
if (ALL_TAGS[i].tag?.style) {
41+
ALL_TAGS[i].tag.style.display = null
42+
}
43+
}
44+
}
45+
}
46+
47+
feature.settings.addEventListener("changed", update)
48+
feature.addEventListener("disabled", update)
49+
feature.addEventListener("enabled", update)
50+
}

0 commit comments

Comments
 (0)