From 6028d052da40765ac07fedbe12612590a605e185 Mon Sep 17 00:00:00 2001 From: Wilamaxin <63302372+Wilamaxin@users.noreply.github.com> Date: Thu, 25 May 2023 22:42:39 +0200 Subject: [PATCH 1/4] "Follows You" update to feature version 2 This feature has some visibility issues when used along with Scratch Addons addon "Profile Banner". I couldn't fix that. Any ideas on how to fix that are welcome. --- features/features.json | 34 +++++------------------ features/follows-you/data.json | 12 +++++++++ features/follows-you/script.js | 49 ++++++++++++++++++++++++++++++++++ features/follows-you/style.css | 7 +++++ 4 files changed, 75 insertions(+), 27 deletions(-) create mode 100644 features/follows-you/data.json create mode 100644 features/follows-you/script.js create mode 100644 features/follows-you/style.css diff --git a/features/features.json b/features/features.json index f3b5ed09..1488ccad 100644 --- a/features/features.json +++ b/features/features.json @@ -179,17 +179,8 @@ "type": ["Website"] }, { - "title": "Show if Following on Profile", - "description": "If a user is following you, it will show next to their username when you visit their profile.", - "credits": ["Bob the Potato with Drip", "TimMcCool"], - "urls": [ - "https://scratch.mit.edu/users/JefferyTheSuperKat/", - "https://scratch.mit.edu/users/TimMcCool/" - ], - "file": "follows-you", - "type": ["Website"], - "tags": ["Featured"], - "dynamic": true + "version": 2, + "id": "follows-you" }, { "title": "Custom Studio Section", @@ -203,15 +194,9 @@ { "id": "Studio ID", "name": "Studio ID", "default": "27205657" } ] }, - { - "title": "Highlight Unanswered Forum Topics", - "description": "Adds a blue highlight to topics in the forums that have no replies.", - "credits": ["rgantzos"], - "urls": ["https://scratch.mit.edu/users/rgantzos/"], - "file": "highlight-unanswered", - "type": ["Website"], - "tags": ["New", "Recommended"], - "dynamic": true + { + "version": 2, + "id": "highlight-unanswered" }, { "title": "Hide Project Tags", @@ -764,13 +749,8 @@ "type": ["Website"] }, { - "title": "Go to Parent Button", - "description": "In the editor for any project that is a remix, you can click a button to go to the editor in the parent project.", - "credits": ["rgantzos"], - "urls": ["https://scratch.mit.edu/users/rgantzos/"], - "file": "go-to-parent", - "tags": [], - "type": ["Editor"] + "version": 2, + "id": "go-to-parent" }, { "title": "Most Popular Project", diff --git a/features/follows-you/data.json b/features/follows-you/data.json new file mode 100644 index 00000000..34a81bb8 --- /dev/null +++ b/features/follows-you/data.json @@ -0,0 +1,12 @@ +{ + "title": "Show if Following on Profile", + "description": "If a user is following you, it will show next to their username when you visit their profile.", + "credits": [ + { "username": "Bob the Potato with Drip", "url": "https://scratch.mit.edu/users/JefferyTheSuperKat/" }, + { "username": "TimMcCool", "url": "https://scratch.mit.edu/users/TimMcCool/" } + ], + "type": ["Website"], + "tags": ["Featured"], + "styles": [{ "file": "style.css", "runOn": "/users/*" }], + "scripts": [{ "file": "script.js", "runOn": "/users/*" }] +} \ No newline at end of file diff --git a/features/follows-you/script.js b/features/follows-you/script.js new file mode 100644 index 00000000..77c4186c --- /dev/null +++ b/features/follows-you/script.js @@ -0,0 +1,49 @@ +async function getFollowing(user1, user2) { + var notFound = true; + var isFollowing = false; + var offset = 0; + while (notFound) { + var response = await fetch( + `https://api.scratch.mit.edu/users/${user2}/following/?limit=40&offset=${offset.toString()}` + ); + var data = await response.json(); + if (data.length === 0) { + notFound = false; + } + data.forEach(function (el) { + if (el.username.toLowerCase() === user1.toLowerCase()) { + notFound = false; + isFollowing = true; + ScratchTools.waitForElements(".header-text", function (element) { + if (!document.querySelector(".scratchtoolsFollowsYou")) { + var span = element.insertBefore( + document.createElement("span"), + document.querySelector(".profile-details") + ); + span.className = "scratchtoolsFollowsYou"; + span.textContent = "Follows You"; + } + }); + } + }); + offset = offset + 40; + } +} +if ( + window.location.href + .toLowerCase() + .startsWith("https://scratch.mit.edu/users/") +) { + getFollowing( + Scratch.INIT_DATA.LOGGED_IN_USER.model.username, + window.location.href + .toLowerCase() + .split("https://scratch.mit.edu/users/")[1] + .split("/")[0] + ); +} +ScratchTools.setDisable("follows-you", function () { + if (document.querySelector(".scratchtoolsFollowsYou")) { + document.querySelector(".scratchtoolsFollowsYou").remove(); + } +}); \ No newline at end of file diff --git a/features/follows-you/style.css b/features/follows-you/style.css new file mode 100644 index 00000000..925c45f2 --- /dev/null +++ b/features/follows-you/style.css @@ -0,0 +1,7 @@ +.scratchtoolsFollowsYou { + opacity: .5; + font-size: .8rem; +} +.header-text > h2 { + display: inline-block; +} \ No newline at end of file From f708f7819d42a8364137c2d2b16b9e6fe2fb4c17 Mon Sep 17 00:00:00 2001 From: Wilamaxin <63302372+Wilamaxin@users.noreply.github.com> Date: Thu, 25 May 2023 22:46:06 +0200 Subject: [PATCH 2/4] Delete follows-you.js --- features/follows-you.js | 53 ----------------------------------------- 1 file changed, 53 deletions(-) delete mode 100644 features/follows-you.js diff --git a/features/follows-you.js b/features/follows-you.js deleted file mode 100644 index 76cca14b..00000000 --- a/features/follows-you.js +++ /dev/null @@ -1,53 +0,0 @@ -async function getFollowing(user1, user2) { - var notFound = true; - var isFollowing = false; - var offset = 0; - while (notFound) { - var response = await fetch( - `https://api.scratch.mit.edu/users/${user2}/following/?limit=40&offset=${offset.toString()}` - ); - var data = await response.json(); - if (data.length === 0) { - notFound = false; - } - data.forEach(function (el) { - if (el.username.toLowerCase() === user1.toLowerCase()) { - notFound = false; - isFollowing = true; - ScratchTools.waitForElements(".header-text", function (element) { - if (!document.querySelector(".scratchtoolsFollowsYou")) { - var span = element.insertBefore( - document.createElement("span"), - document.querySelector(".profile-details") - ); - span.className = "scratchtoolsFollowsYou"; - span.textContent = "Follows You"; - span.style.opacity = ".5"; - span.style.fontSize = ".8rem"; - element.querySelector("h2").style.display = "inline-block"; - } - }); - } - }); - offset = offset + 40; - } -} -if ( - window.location.href - .toLowerCase() - .startsWith("https://scratch.mit.edu/users/") -) { - getFollowing( - Scratch.INIT_DATA.LOGGED_IN_USER.model.username, - window.location.href - .toLowerCase() - .split("https://scratch.mit.edu/users/")[1] - .split("/")[0] - ); -} - -ScratchTools.setDisable("follows-you", function () { - if (document.querySelector(".scratchtoolsFollowsYou")) { - document.querySelector(".scratchtoolsFollowsYou").remove(); - } -}); From f1b38dd62f6dec9a5c5b3bc6d447fc52fbb7afc9 Mon Sep 17 00:00:00 2001 From: Wilamaxin <63302372+Wilamaxin@users.noreply.github.com> Date: Sat, 27 May 2023 18:37:22 +0200 Subject: [PATCH 3/4] Fix visibility issue Fixes visibility issue that occurred when used with Scratch Addons addon "Profile Banner" enabled. --- features/follows-you/script.js | 8 +++++++- features/follows-you/style.css | 5 +++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/features/follows-you/script.js b/features/follows-you/script.js index 77c4186c..c7a71233 100644 --- a/features/follows-you/script.js +++ b/features/follows-you/script.js @@ -20,9 +20,15 @@ async function getFollowing(user1, user2) { document.createElement("span"), document.querySelector(".profile-details") ); + if (typeof scratchAddons !== 'undefined') { + for(var i = 0; i < scratchAddons.eventTargets.self.length; i++) { + if(scratchAddons.eventTargets.self[i].id == "better-featured-project"){ + span.style.color = "white"; + } + }} span.className = "scratchtoolsFollowsYou"; span.textContent = "Follows You"; - } + } }); } }); diff --git a/features/follows-you/style.css b/features/follows-you/style.css index 925c45f2..a7b95e43 100644 --- a/features/follows-you/style.css +++ b/features/follows-you/style.css @@ -1,6 +1,7 @@ .scratchtoolsFollowsYou { - opacity: .5; - font-size: .8rem; + opacity: .6; + text-shadow: rgba(0, 0, 0, 0.5) 0 0 10px; + font-size: .9rem; } .header-text > h2 { display: inline-block; From 8b75ffa2f9f859daa291769192636e9840a82be6 Mon Sep 17 00:00:00 2001 From: rgantzos Date: Wed, 31 May 2023 10:33:42 -0700 Subject: [PATCH 4/4] Update features.json --- features/features.json | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/features/features.json b/features/features.json index 1488ccad..9a434187 100644 --- a/features/features.json +++ b/features/features.json @@ -194,9 +194,15 @@ { "id": "Studio ID", "name": "Studio ID", "default": "27205657" } ] }, - { - "version": 2, - "id": "highlight-unanswered" + { + "title": "Highlight Unanswered Forum Topics", + "description": "Adds a blue highlight to topics in the forums that have no replies.", + "credits": ["rgantzos"], + "urls": ["https://scratch.mit.edu/users/rgantzos/"], + "file": "highlight-unanswered", + "type": ["Website"], + "tags": ["New", "Recommended"], + "dynamic": true }, { "title": "Hide Project Tags", @@ -749,8 +755,13 @@ "type": ["Website"] }, { - "version": 2, - "id": "go-to-parent" + "title": "Go to Parent Button", + "description": "In the editor for any project that is a remix, you can click a button to go to the editor in the parent project.", + "credits": ["rgantzos"], + "urls": ["https://scratch.mit.edu/users/rgantzos/"], + "file": "go-to-parent", + "tags": [], + "type": ["Editor"] }, { "title": "Most Popular Project",