From 9872d1f4224f5def0bdeef284a8ec67caab83f88 Mon Sep 17 00:00:00 2001 From: MaterArc <105017592+MaterArc@users.noreply.github.com> Date: Wed, 2 Jul 2025 12:59:56 -0400 Subject: [PATCH 1/3] Compare languages Improve the feature to compare users by language instead of just the country, so users from different countries that share the same language (eg: US, UK, Australia) are included correctly. --- features/localized-explore/script.js | 29 +++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/features/localized-explore/script.js b/features/localized-explore/script.js index 90091f65..417794e6 100644 --- a/features/localized-explore/script.js +++ b/features/localized-explore/script.js @@ -9,9 +9,27 @@ export default async function ({ feature, console }) { ).json() ).profile.country; - ScratchTools.waitForElements("div.thumbnail.project", detectCountry); + async function getLanguage(country) { + try { + const res = await fetch( + `https://restcountries.com/v3.1/name/${encodeURIComponent(country)}?fullText=true` + ); + if (!res.ok) return null; + const data = await res.json(); + if (data && data[0] && data[0].languages) { + return Object.values(data[0].languages)[0]; + } + return null; + } catch { + return null; + } + } - async function detectCountry(element) { + const myLanguage = await getLanguage(myCountry); + + ScratchTools.waitForElements("div.thumbnail.project", detectLanguage); + + async function detectLanguage(element) { let author = element.querySelector(".thumbnail-creator a"); let data = await ( @@ -23,7 +41,9 @@ export default async function ({ feature, console }) { ) ).json(); - if (data.profile.country !== myCountry) { + const authorLanguage = await getLanguage(data.profile.country); + + if (authorLanguage !== myLanguage) { element.classList.add("ste-outside-country"); if (feature.settings.get("hide-completely")) { element.classList.add("ste-country-hide"); @@ -35,7 +55,6 @@ export default async function ({ feature, console }) { feature.settings.addEventListener("changed", function ({ key, value }) { if (key === "hide-completely") { - console.log(value); if (value) { document .querySelectorAll(".ste-outside-country") @@ -51,6 +70,6 @@ export default async function ({ feature, console }) { }); feature.addEventListener("enabled", function() { - ScratchTools.waitForElements("div.thumbnail.project", detectCountry); + ScratchTools.waitForElements("div.thumbnail.project", detectLanguage); }) } From b93c5e7721120222fc743e42711edd09cb7f725a Mon Sep 17 00:00:00 2001 From: rgantzos <86856959+rgantzos@users.noreply.github.com> Date: Sat, 2 Aug 2025 10:07:53 -0700 Subject: [PATCH 2/3] Use ScratchTools API instead --- features/localized-explore/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/localized-explore/script.js b/features/localized-explore/script.js index 417794e6..439f35a0 100644 --- a/features/localized-explore/script.js +++ b/features/localized-explore/script.js @@ -12,7 +12,7 @@ export default async function ({ feature, console }) { async function getLanguage(country) { try { const res = await fetch( - `https://restcountries.com/v3.1/name/${encodeURIComponent(country)}?fullText=true` + `https://data.scratchtools.app/language/${encodeURIComponent(country)}?fullText=true` ); if (!res.ok) return null; const data = await res.json(); From caadf787a761e4c2302479b54e0de8435fc0f6da Mon Sep 17 00:00:00 2001 From: rgantzos <86856959+rgantzos@users.noreply.github.com> Date: Sat, 2 Aug 2025 10:08:46 -0700 Subject: [PATCH 3/3] Update data.json with credits and description --- features/localized-explore/data.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/features/localized-explore/data.json b/features/localized-explore/data.json index 2ed32d0c..4f74e433 100644 --- a/features/localized-explore/data.json +++ b/features/localized-explore/data.json @@ -1,7 +1,8 @@ { "title": "Projects from Country", - "description": "On the explore page, makes projects from other countries less visible. This is to only show projects in languages that you understand.", + "description": "On the explore page, makes projects from countries that speak other languages less visible.", "credits": [ + { "username": "MaterArc", "url": "https://scratch.mit.edu/users/MaterArc/" }, { "username": "KitsunLilly", "url": "https://scratch.mit.edu/users/KitsunLilly/" }, { "username": "rgantzos", "url": "https://scratch.mit.edu/users/rgantzos/" } ],