Skip to content

Commit 55c8c84

Browse files
committed
2 parents 61248cb + c441798 commit 55c8c84

File tree

21 files changed

+589
-26
lines changed

21 files changed

+589
-26
lines changed

.github/workflows/extract-classnames.yml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88

99
permissions:
1010
contents: write
11+
pull-requests: write
1112

1213
jobs:
1314
extract:
@@ -25,10 +26,23 @@ jobs:
2526
- name: Run extraction script
2627
run: node .github/scripts/extract-classnames.js
2728

28-
- name: Commit and push updated class-names.json
29+
- name: Check for changes
30+
id: git-diff
2931
run: |
30-
git config user.name "github-actions[bot]"
31-
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
32-
git add class-names.json
33-
git commit -m "Update class-names.json" || echo "No changes"
34-
git push
32+
if git diff --quiet --exit-code class-names.json; then
33+
echo "changed=false" >> $GITHUB_OUTPUT
34+
else
35+
echo "changed=true" >> $GITHUB_OUTPUT
36+
fi
37+
38+
- name: Create or Update Pull Request
39+
if: steps.git-diff.outputs.changed == 'true'
40+
uses: peter-evans/create-pull-request@v6
41+
with:
42+
commit-message: "Update class-names.json"
43+
branch: update-class-names
44+
title: "Update class names"
45+
body: "Automated update of class-names.json"
46+
labels: automated
47+
assignees: rgantzos
48+
delete-branch: true

api/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ ScratchTools.waitForElements(
426426
scratchClass("menu_hoverable_");
427427

428428
var div = document.createElement("div");
429-
div.className = "settings-menu_option_3rMur";
429+
div.className = "settings-menu_option_GGukG";
430430

431431
var icon = document.createElement("img");
432432
icon.src = ScratchTools.icons.main;

class-names.json

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,44 @@
1-
[]
1+
[
2+
{
3+
"className": "ste-search-user",
4+
"features": [
5+
"advanced-search"
6+
]
7+
},
8+
{
9+
"className": "ste-search-user-pfp",
10+
"features": [
11+
"advanced-search"
12+
]
13+
},
14+
{
15+
"className": "ste-search-user-data",
16+
"features": [
17+
"advanced-search"
18+
]
19+
},
20+
{
21+
"className": "ste-search-user-username",
22+
"features": [
23+
"advanced-search"
24+
]
25+
},
26+
{
27+
"className": "ste-search-user-bio",
28+
"features": [
29+
"advanced-search"
30+
]
31+
},
32+
{
33+
"className": "ste-search-user-btn",
34+
"features": [
35+
"advanced-search"
36+
]
37+
},
38+
{
39+
"className": "ste-search-border-top",
40+
"features": [
41+
"advanced-search"
42+
]
43+
}
44+
]

extras/feature-locales/en.json

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

features/align-to-center/script.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
export default async function ({ feature, console }) {
22
const availableWidth = 405;
3+
const blankChar = "\u2800";
34

45
function getSpaceWidth() {
56
const span = document.createElement("span");
67
span.style.visibility = "hidden";
78
span.style.whiteSpace = "pre";
8-
span.textContent = " ";
9+
span.textContent = blankChar;
910
document.body.appendChild(span);
1011
const spaceWidth = span.getBoundingClientRect().width;
1112
document.body.removeChild(span);
@@ -26,7 +27,7 @@ export default async function ({ feature, console }) {
2627
function clearCenterAlignment(textarea) {
2728
const lines = textarea.value.split("\n");
2829
const uncenteredLines = lines.map((line) => {
29-
return line.replace(/^\s+/, "");
30+
return line.replace(/^[\s\u2800]+/, "");
3031
});
3132
textarea.value = uncenteredLines.join("\n");
3233
}
@@ -49,7 +50,7 @@ export default async function ({ feature, console }) {
4950
const textWidth = getTextWidth(line);
5051
const totalSpaces = (availableWidth - textWidth) / spaceWidth / 2;
5152
const spaces =
52-
totalSpaces > 0 ? " ".repeat(Math.floor(totalSpaces)) : "";
53+
totalSpaces > 0 ? blankChar.repeat(Math.floor(totalSpaces)) : "";
5354
return spaces + line;
5455
});
5556
activeElement.value = centeredLines.join("\n");

features/features.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
[
2+
{
3+
"version": 2,
4+
"id": "picture-in-picture",
5+
"versionAdded": "v5.0.0"
6+
},
7+
{
8+
"version": 2,
9+
"id": "mutual-following",
10+
"versionAdded": "v5.0.0"
11+
},
12+
{
13+
"version": 2,
14+
"id": "studio-invite-comments",
15+
"versionAdded": "v4.2.0"
16+
},
217
{
318
"version": 2,
419
"id": "copy-paste-lists",
@@ -578,7 +593,7 @@
578593
},
579594
{
580595
"title": "Frontpage Curator Name as Link",
581-
"description": "Makes the name of the Frontpage Curator to a clickable link to his profile.",
596+
"description": "Turns the Front Page Curator's name into a clickable link to their profile.",
582597
"credits": ["Dr_Lego"],
583598
"urls": ["https://scratch.mit.edu/users/Dr_Lego/"],
584599
"file": "frontpage-curator",

features/follow-on-projects/data.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"title": "Follow on Project Page",
33
"description": "Follow users directly from the project page instead of going to their profile.",
44
"credits": [
5+
{ "username": "MaterArc", "url": "https://scratch.mit.edu/users/MaterArc/" },
56
{ "username": "green_thing_game2", "url": "https://scratch.mit.edu/users/green_thing_game2/" },
67
{ "username": "rgantzos", "url": "https://scratch.mit.edu/users/rgantzos/" }
78
],

features/follow-on-projects/script.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ export default async function ({ feature, console }) {
3030
(following ? "Unfollow" : "Follow") + " " + username;
3131
let data = await (
3232
await fetch(
33-
"https://scratch.mit.edu/site-api/users/followers/rgantzosTEST/remove/?usernames=" +
33+
"https://scratch.mit.edu/site-api/users/followers/" + username + "/remove/?usernames=" +
3434
auth.user.username,
3535
{
3636
headers: {
37-
"x-csrftoken": "VZ0lgYGuLZzG5nD4nNirmbbze7CulCmP",
37+
"x-csrftoken": document.cookie.match(/scratchcsrftoken=([^;]+)/)?.[1],
3838
"x-requested-with": "XMLHttpRequest",
3939
},
4040
referrer: "https://scratch.mit.edu/users/" + username + "/",
@@ -53,15 +53,14 @@ export default async function ({ feature, console }) {
5353
(following ? "Unfollow" : "Follow") + " " + username;
5454
let data = await (
5555
await fetch(
56-
"https://scratch.mit.edu/site-api/users/followers/rgantzosTEST/add/?usernames=" +
56+
"https://scratch.mit.edu/site-api/users/followers/" + username + "/add/?usernames=" +
5757
auth.user.username,
5858
{
5959
headers: {
60-
"x-csrftoken": "VZ0lgYGuLZzG5nD4nNirmbbze7CulCmP",
60+
"x-csrftoken": document.cookie.match(/scratchcsrftoken=([^;]+)/)?.[1],
6161
"x-requested-with": "XMLHttpRequest",
6262
},
6363
referrer: "https://scratch.mit.edu/users/" + username + "/",
64-
body: '{"id":"' + username + '"}',
6564
method: "PUT",
6665
mode: "cors",
6766
credentials: "include",

features/localized-explore/data.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"title": "Projects from Country",
3-
"description": "On the explore page, makes projects from other countries less visible. This is to only show projects in languages that you understand.",
3+
"description": "On the explore page, makes projects from countries that speak other languages less visible.",
44
"credits": [
5+
{ "username": "MaterArc", "url": "https://scratch.mit.edu/users/MaterArc/" },
56
{ "username": "KitsunLilly", "url": "https://scratch.mit.edu/users/KitsunLilly/" },
67
{ "username": "rgantzos", "url": "https://scratch.mit.edu/users/rgantzos/" }
78
],

features/localized-explore/script.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,27 @@ export default async function ({ feature, console }) {
99
).json()
1010
).profile.country;
1111

12-
ScratchTools.waitForElements("div.thumbnail.project", detectCountry);
12+
async function getLanguage(country) {
13+
try {
14+
const res = await fetch(
15+
`https://data.scratchtools.app/language/${encodeURIComponent(country)}?fullText=true`
16+
);
17+
if (!res.ok) return null;
18+
const data = await res.json();
19+
if (data && data[0] && data[0].languages) {
20+
return Object.values(data[0].languages)[0];
21+
}
22+
return null;
23+
} catch {
24+
return null;
25+
}
26+
}
1327

14-
async function detectCountry(element) {
28+
const myLanguage = await getLanguage(myCountry);
29+
30+
ScratchTools.waitForElements("div.thumbnail.project", detectLanguage);
31+
32+
async function detectLanguage(element) {
1533
let author = element.querySelector(".thumbnail-creator a");
1634

1735
let data = await (
@@ -23,7 +41,9 @@ export default async function ({ feature, console }) {
2341
)
2442
).json();
2543

26-
if (data.profile.country !== myCountry) {
44+
const authorLanguage = await getLanguage(data.profile.country);
45+
46+
if (authorLanguage !== myLanguage) {
2747
element.classList.add("ste-outside-country");
2848
if (feature.settings.get("hide-completely")) {
2949
element.classList.add("ste-country-hide");
@@ -35,7 +55,6 @@ export default async function ({ feature, console }) {
3555

3656
feature.settings.addEventListener("changed", function ({ key, value }) {
3757
if (key === "hide-completely") {
38-
console.log(value);
3958
if (value) {
4059
document
4160
.querySelectorAll(".ste-outside-country")
@@ -51,6 +70,6 @@ export default async function ({ feature, console }) {
5170
});
5271

5372
feature.addEventListener("enabled", function() {
54-
ScratchTools.waitForElements("div.thumbnail.project", detectCountry);
73+
ScratchTools.waitForElements("div.thumbnail.project", detectLanguage);
5574
})
5675
}

0 commit comments

Comments
 (0)