From 22603005e8022050505713b41790af5e3f10ffb3 Mon Sep 17 00:00:00 2001 From: MaterArc <105017592+MaterArc@users.noreply.github.com> Date: Sun, 29 Dec 2024 12:43:40 -0500 Subject: [PATCH 1/5] Recent Followers and Following New feature to revert the recent Scratch update that displayed old followers and followings, restoring the view of the most recent ones --- .../recent-followers-and-following/data.json | 15 +++ .../recent-followers-and-following/script.js | 112 ++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 features/recent-followers-and-following/data.json create mode 100644 features/recent-followers-and-following/script.js diff --git a/features/recent-followers-and-following/data.json b/features/recent-followers-and-following/data.json new file mode 100644 index 00000000..240263c2 --- /dev/null +++ b/features/recent-followers-and-following/data.json @@ -0,0 +1,15 @@ +{ + "title": "Show Recent Followers and Followings", + "description": "Displays the most recent followers and followings of a user on their profile page.", + "credits": [ + { + "username": "-Brass_Glass-", + "url": "https://scratch.mit.edu/users/-Brass_Glass-/" + }, + { "username": "MaterArc", "url": "https://scratch.mit.edu/users/MaterArc/" } + ], + "type": ["Website"], + "tags": ["New", "Featured"], + "dynamic": true, + "scripts": [{ "file": "script.js", "runOn": "/users/*" }] +} diff --git a/features/recent-followers-and-following/script.js b/features/recent-followers-and-following/script.js new file mode 100644 index 00000000..db82ea36 --- /dev/null +++ b/features/recent-followers-and-following/script.js @@ -0,0 +1,112 @@ +export default async function ({ feature, console }) { + const username = window.location.pathname.split('/')[2]; + if (!username) return; + + const followersEndpoint = `https://api.scratch.mit.edu/users/${username}/followers/`; + const followingEndpoint = `https://api.scratch.mit.edu/users/${username}/following/`; + + try { + const followersResponse = await fetch(followersEndpoint); + if (!followersResponse.ok) return; + + const followersData = await followersResponse.json(); + if (!Array.isArray(followersData)) return; + + const mostRecentFollowers = followersData + .slice(0, 9) + .filter(follower => follower.username && follower.profile && follower.profile.images) + .map(follower => ({ + username: follower.username, + profileImage: follower.profile.images['90x90'] || follower.profile.images['50x50'] || '', + })); + + const followingResponse = await fetch(followingEndpoint); + if (!followingResponse.ok) return; + + const followingData = await followingResponse.json(); + if (!Array.isArray(followingData)) return; + + const mostRecentFollowing = followingData + .slice(0, 9) + .filter(follow => follow.username && follow.profile && follow.profile.images) + .map(follow => ({ + username: follow.username, + profileImage: follow.profile.images['90x90'] || follow.profile.images['50x50'] || '', + })); + + ScratchTools.waitForElements("#featured", function (allFeaturedElements) { + if (allFeaturedElements.length === 0) return; + + const lastFeaturedElement = allFeaturedElements[allFeaturedElements.length - 1]; + lastFeaturedElement.innerHTML = ""; + + mostRecentFollowers.forEach(follower => { + const li = document.createElement("li"); + li.className = "user thumb item"; + + const link = document.createElement("a"); + link.href = `/users/${follower.username}/`; + link.title = follower.username; + + const img = document.createElement("img"); + img.className = "lazy"; + img.src = follower.profileImage; + img.alt = follower.username; + img.width = 60; + img.height = 60; + + const span = document.createElement("span"); + span.className = "title"; + + const spanLink = document.createElement("a"); + spanLink.href = `/users/${follower.username}/`; + spanLink.textContent = follower.username; + + link.appendChild(img); + span.appendChild(spanLink); + li.appendChild(link); + li.appendChild(span); + + lastFeaturedElement.appendChild(li); + }); + + if (allFeaturedElements.length > 1) { + const secondLastFeaturedElement = allFeaturedElements[allFeaturedElements.length - 2]; + secondLastFeaturedElement.innerHTML = ""; + + mostRecentFollowing.forEach(follow => { + const li = document.createElement("li"); + li.className = "user thumb item"; + + const link = document.createElement("a"); + link.href = `/users/${follow.username}/`; + link.title = follow.username; + + const img = document.createElement("img"); + img.className = "lazy"; + img.src = follow.profileImage; + img.alt = follow.username; + img.width = 60; + img.height = 60; + + const span = document.createElement("span"); + span.className = "title"; + + const spanLink = document.createElement("a"); + spanLink.href = `/users/${follow.username}/`; + spanLink.textContent = follow.username; + + link.appendChild(img); + span.appendChild(spanLink); + li.appendChild(link); + li.appendChild(span); + + secondLastFeaturedElement.appendChild(li); + }); + } + }); + } catch (error) { + return; + } + } + \ No newline at end of file From d66081dcd7a01bf4b14b8a4c01adf084c1eeab02 Mon Sep 17 00:00:00 2001 From: MaterArc <105017592+MaterArc@users.noreply.github.com> Date: Sun, 29 Dec 2024 12:44:50 -0500 Subject: [PATCH 2/5] Update features.json --- features/features.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/features/features.json b/features/features.json index caa770ce..ce8ae54e 100644 --- a/features/features.json +++ b/features/features.json @@ -1,4 +1,9 @@ [ + { + "version": 2, + "id": "recent-followers-and-following", + "versionAdded": "v4.0.0" + }, { "version": 2, "id": "outline-shape-options", From f2de1e57ec0764dd012b7bc3ab3758aea723e260 Mon Sep 17 00:00:00 2001 From: MaterArc <105017592+MaterArc@users.noreply.github.com> Date: Sun, 29 Dec 2024 15:38:47 -0500 Subject: [PATCH 3/5] Update script.js --- features/recent-followers-and-following/script.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/recent-followers-and-following/script.js b/features/recent-followers-and-following/script.js index db82ea36..d5dac9eb 100644 --- a/features/recent-followers-and-following/script.js +++ b/features/recent-followers-and-following/script.js @@ -34,7 +34,7 @@ export default async function ({ feature, console }) { profileImage: follow.profile.images['90x90'] || follow.profile.images['50x50'] || '', })); - ScratchTools.waitForElements("#featured", function (allFeaturedElements) { + const allFeaturedElements = document.querySelectorAll("#featured"); if (allFeaturedElements.length === 0) return; const lastFeaturedElement = allFeaturedElements[allFeaturedElements.length - 1]; @@ -109,4 +109,4 @@ export default async function ({ feature, console }) { return; } } - \ No newline at end of file + From d8322ae9b9ffc7c3cc3e60e12850ac9da3c14ccb Mon Sep 17 00:00:00 2001 From: MaterArc <105017592+MaterArc@users.noreply.github.com> Date: Fri, 3 Jan 2025 16:17:21 -0500 Subject: [PATCH 4/5] Fix Syntax Error --- .../recent-followers-and-following/script.js | 214 +++++++++--------- 1 file changed, 106 insertions(+), 108 deletions(-) diff --git a/features/recent-followers-and-following/script.js b/features/recent-followers-and-following/script.js index d5dac9eb..f50ca063 100644 --- a/features/recent-followers-and-following/script.js +++ b/features/recent-followers-and-following/script.js @@ -1,112 +1,110 @@ export default async function ({ feature, console }) { - const username = window.location.pathname.split('/')[2]; - if (!username) return; - - const followersEndpoint = `https://api.scratch.mit.edu/users/${username}/followers/`; - const followingEndpoint = `https://api.scratch.mit.edu/users/${username}/following/`; - - try { - const followersResponse = await fetch(followersEndpoint); - if (!followersResponse.ok) return; - - const followersData = await followersResponse.json(); - if (!Array.isArray(followersData)) return; - - const mostRecentFollowers = followersData - .slice(0, 9) - .filter(follower => follower.username && follower.profile && follower.profile.images) - .map(follower => ({ - username: follower.username, - profileImage: follower.profile.images['90x90'] || follower.profile.images['50x50'] || '', - })); - - const followingResponse = await fetch(followingEndpoint); - if (!followingResponse.ok) return; - - const followingData = await followingResponse.json(); - if (!Array.isArray(followingData)) return; - - const mostRecentFollowing = followingData - .slice(0, 9) - .filter(follow => follow.username && follow.profile && follow.profile.images) - .map(follow => ({ - username: follow.username, - profileImage: follow.profile.images['90x90'] || follow.profile.images['50x50'] || '', - })); - - const allFeaturedElements = document.querySelectorAll("#featured"); - if (allFeaturedElements.length === 0) return; - - const lastFeaturedElement = allFeaturedElements[allFeaturedElements.length - 1]; - lastFeaturedElement.innerHTML = ""; - - mostRecentFollowers.forEach(follower => { - const li = document.createElement("li"); - li.className = "user thumb item"; - - const link = document.createElement("a"); - link.href = `/users/${follower.username}/`; - link.title = follower.username; - - const img = document.createElement("img"); - img.className = "lazy"; - img.src = follower.profileImage; - img.alt = follower.username; - img.width = 60; - img.height = 60; - - const span = document.createElement("span"); - span.className = "title"; - - const spanLink = document.createElement("a"); - spanLink.href = `/users/${follower.username}/`; - spanLink.textContent = follower.username; - - link.appendChild(img); - span.appendChild(spanLink); - li.appendChild(link); - li.appendChild(span); - - lastFeaturedElement.appendChild(li); - }); - - if (allFeaturedElements.length > 1) { - const secondLastFeaturedElement = allFeaturedElements[allFeaturedElements.length - 2]; - secondLastFeaturedElement.innerHTML = ""; - - mostRecentFollowing.forEach(follow => { - const li = document.createElement("li"); - li.className = "user thumb item"; - - const link = document.createElement("a"); - link.href = `/users/${follow.username}/`; - link.title = follow.username; - - const img = document.createElement("img"); - img.className = "lazy"; - img.src = follow.profileImage; - img.alt = follow.username; - img.width = 60; - img.height = 60; - - const span = document.createElement("span"); - span.className = "title"; - - const spanLink = document.createElement("a"); - spanLink.href = `/users/${follow.username}/`; - spanLink.textContent = follow.username; - - link.appendChild(img); - span.appendChild(spanLink); - li.appendChild(link); - li.appendChild(span); - - secondLastFeaturedElement.appendChild(li); - }); - } + const username = window.location.pathname.split('/')[2]; + if (!username) return; + + const followersEndpoint = `https://api.scratch.mit.edu/users/${username}/followers/`; + const followingEndpoint = `https://api.scratch.mit.edu/users/${username}/following/`; + + try { + const followersResponse = await fetch(followersEndpoint); + if (!followersResponse.ok) return; + + const followersData = await followersResponse.json(); + if (!Array.isArray(followersData)) return; + + const mostRecentFollowers = followersData + .slice(0, 9) + .filter(follower => follower.username && follower.profile && follower.profile.images) + .map(follower => ({ + username: follower.username, + profileImage: follower.profile.images['90x90'] || follower.profile.images['50x50'] || '', + })); + + const followingResponse = await fetch(followingEndpoint); + if (!followingResponse.ok) return; + + const followingData = await followingResponse.json(); + if (!Array.isArray(followingData)) return; + + const mostRecentFollowing = followingData + .slice(0, 9) + .filter(follow => follow.username && follow.profile && follow.profile.images) + .map(follow => ({ + username: follow.username, + profileImage: follow.profile.images['90x90'] || follow.profile.images['50x50'] || '', + })); + + const allFeaturedElements = document.querySelectorAll("#featured"); + if (allFeaturedElements.length === 0) return; + + const lastFeaturedElement = allFeaturedElements[allFeaturedElements.length - 1]; + lastFeaturedElement.innerHTML = ""; + + mostRecentFollowers.forEach(follower => { + const li = document.createElement("li"); + li.className = "user thumb item"; + + const link = document.createElement("a"); + link.href = `/users/${follower.username}/`; + link.title = follower.username; + + const img = document.createElement("img"); + img.className = "lazy"; + img.src = follower.profileImage; + img.alt = follower.username; + img.width = 60; + img.height = 60; + + const span = document.createElement("span"); + span.className = "title"; + + const spanLink = document.createElement("a"); + spanLink.href = `/users/${follower.username}/`; + spanLink.textContent = follower.username; + + link.appendChild(img); + span.appendChild(spanLink); + li.appendChild(link); + li.appendChild(span); + + lastFeaturedElement.appendChild(li); + }); + + if (allFeaturedElements.length > 1) { + const secondLastFeaturedElement = allFeaturedElements[allFeaturedElements.length - 2]; + secondLastFeaturedElement.innerHTML = ""; + + mostRecentFollowing.forEach(follow => { + const li = document.createElement("li"); + li.className = "user thumb item"; + + const link = document.createElement("a"); + link.href = `/users/${follow.username}/`; + link.title = follow.username; + + const img = document.createElement("img"); + img.className = "lazy"; + img.src = follow.profileImage; + img.alt = follow.username; + img.width = 60; + img.height = 60; + + const span = document.createElement("span"); + span.className = "title"; + + const spanLink = document.createElement("a"); + spanLink.href = `/users/${follow.username}/`; + spanLink.textContent = follow.username; + + link.appendChild(img); + span.appendChild(spanLink); + li.appendChild(link); + li.appendChild(span); + + secondLastFeaturedElement.appendChild(li); }); - } catch (error) { - return; } + } catch (error) { + return; } - +} From 906cc44e8336fd7627965cdcb7f13149e1ee030d Mon Sep 17 00:00:00 2001 From: rgantzos <86856959+rgantzos@users.noreply.github.com> Date: Tue, 28 Jan 2025 09:37:05 -0800 Subject: [PATCH 5/5] Update features.json --- features/features.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/features.json b/features/features.json index 9751fe02..8667e36c 100644 --- a/features/features.json +++ b/features/features.json @@ -2,7 +2,7 @@ { "version": 2, "id": "recent-followers-and-following", - "versionAdded": "v4.0.0" + "versionAdded": "v4.1.0" }, { "version": 2,