Skip to content

Commit 80d2a80

Browse files
authored
Merge branch 'main' into recent-followers-and-following
2 parents 906cc44 + c441798 commit 80d2a80

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1957
-267
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
4+
const rootDir = path.resolve(__dirname, "../../features");
5+
const outputFile = path.resolve(__dirname, "../../class-names.json");
6+
7+
let collected = new Set();
8+
9+
function traverseDir(dir) {
10+
const files = fs.readdirSync(dir);
11+
for (const file of files) {
12+
const fullPath = path.join(dir, file);
13+
const stat = fs.statSync(fullPath);
14+
15+
if (stat.isDirectory()) {
16+
traverseDir(fullPath);
17+
} else if (stat.isFile() && file.endsWith(".js")) {
18+
const content = fs.readFileSync(fullPath, "utf-8");
19+
const regex = /className\(["'`](.*?)["'`]\)/g;
20+
let match;
21+
while ((match = regex.exec(content)) !== null) {
22+
collected.add({
23+
className: "ste-" + match[1].replaceAll(" ", "-"),
24+
features: [
25+
dir.split("/features/")[1].split("/")[0].replaceAll(".js", ""),
26+
],
27+
});
28+
}
29+
}
30+
}
31+
}
32+
33+
traverseDir(rootDir);
34+
35+
const mergedFeatures = Object.values(
36+
[...collected].reduce((acc, item) => {
37+
if (!acc[item.className]) {
38+
acc[item.className] = { className: item.className, features: new Set() };
39+
}
40+
item.features.forEach(f => acc[item.className].features.add(f));
41+
return acc;
42+
}, {})
43+
).map(obj => ({ className: obj.className, features: [...obj.features] }));
44+
45+
fs.writeFileSync(outputFile, JSON.stringify(mergedFeatures, null, 2));
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Extract Class Names
2+
3+
on:
4+
push:
5+
paths:
6+
- "features/**.js"
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
13+
jobs:
14+
extract:
15+
if: github.repository == 'STForScratch/ScratchTools'
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: Set up Node.js
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: 20
25+
26+
- name: Run extraction script
27+
run: node .github/scripts/extract-classnames.js
28+
29+
- name: Check for changes
30+
id: git-diff
31+
run: |
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

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ There are multiple ways of installing.
4040
- Chrome: You can download from Chrome's Extension Webstore [here](https://chrome.google.com/webstore/detail/scratchtools/jjnpbalpllpfdpgplpbcbadkgdmleopm). Then just press the Add to Chrome button, and you've downloaded ScratchTools!
4141

4242
> [!NOTE]
43-
> If you are using a browser based on Chromium (eg. Brave), then this is your way of installing unless your browser has it's own extension store.
43+
> If you are using a browser based on Chromium (eg. Brave), then this is your way of installing unless your browser has its own extension store.
4444
4545
- Firefox/Mozilla: You can download from Firefox Addons (Works on Firefox forks) [here](https://addons.mozilla.org/en-US/firefox/addon/scratchtools/). You can then just add it to Firefox, and then you have ScratchTools!
4646

4747
> [!NOTE]
48-
> The Firefox version of Scratchtools is behind compared to the chrome version of Scratchtools due to technical difficulties. Until a solution is found, the Firefox version will remain behind.
48+
> The Firefox version of ScratchTools is behind compared to the Chrome version of ScratchTools due to technical difficulties. Until a solution is found, the Firefox version will remain behind.
4949
5050
- Microsoft Edge: You can download from Edge's addon webstore [here](https://microsoftedge.microsoft.com/addons/detail/scratchtools/aaidjeidbnhpjhblbianjeghjopbimmk). You can then just add it to Edge, and then you have ScratchTools!
5151
- Safari (macOS, iPadOS and iOS): You can build the extension by typing `make` for macOS, and `make ios` for the iOS app (you will have to sign it on Xcode), make sure you have enabled Developer mode and allowed unsigned extensions.
@@ -55,7 +55,7 @@ There are multiple ways of installing.
5555
- GitHub (For Firefox & Firefox Forks): Download from the GitHub repository [here](https://github.com/STForScratch/ScratchTools/zipball/master). After the `.zip` file is downloaded, unpack it. Then, with the folder, go to `about:debugging`, click "This Firefox" and click "Load temporary extension", go into the extension folder and select the `manifest.json`.
5656

5757
> [!WARNING]
58-
> Extensions loaded this way onto Safari indeed temporary. Once you close the window, it will be gone. In addition, ScratchTools is still outdated on Firefox at the time of writing this.
58+
> Extensions loaded this way onto Safari are temporary. Once you close the window, it will be gone.
5959
6060
- Installing with Git: Open the code dropdown on the extension's repository, copy the HTTPS url and then execute `git clone https://github.com/STForScratch/ScratchTools.git -b main` in Git, and you have installed ScratchTools! To pull changes instead of cloning the repository, enter the folder and execute `git remote add upstream https://github.com/STForScratch/ScratchTools.git`. When a commit is made to the repository, you can just run `git pull upstream main` to pull the changes, note that sometimes you may need to refresh ScratchTools.
6161

@@ -77,7 +77,7 @@ Using `ScratchTools.Auth`, you can access the authentication info for the signed
7777
Using `ScratchTools.Scratch.blockly` and `ScratchTools.Scratch.vm`, you can access the Blockly and Virtual Machine from inside the editor (or on the project page with vm). Blockly must wait for the editor to load, but the virtual machine is ready instantly.
7878
##### Blockly Context Menus
7979
If you want to control what appears in a context menu, you easily can with the `ScratchTools.Scratch.waitForContextMenu()` API. The only input you need is JSON, which must include the block ID for the context menu, the ID you want to set for the context menu option (lets you change the context menu option, so don't use the same ID as another feature), and the callback for when the context menu is opened. The callback function will also have an input, which is the context menu itself. That way, you can add the context menu option when the context menu is opened.
80-
##### Sound , GUI and Paint-Mode
80+
##### Sound, GUI and Paint-Mode
8181
Using `ScratchTools.Scratch.scratchSound`and `ScratchTools.Scratch.scratchGui`, you can return sound from the editor as well as access Graphical User Interface inside the editor. `ScratchTools.Scratch.scratchPaint` can be used in selecting the paint editor mode.
8282

8383
#### Logging

_locales/en/messages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"message": "ScratchTools is fully customizable with tons of features, all for making the Scratch website better and easier to use!"
77
},
88
"supportButton": {
9-
"message": "Get support"
9+
"message": "Get live support"
1010
},
1111
"feedbackButton": {
1212
"message": "Give feedback"

api/feature.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ class Feature {
66
finalFeature = el;
77
}
88
});
9+
this.requestPermissions = async function(...permissions) {
10+
return await ScratchTools.sendMessage("request-perms", permissions)
11+
}
912
this.data = finalFeature;
1013
this.msg = function (string) {
1114
return this.data.localesData[`${this.data.id}/`+string] || `ScratchTools.${this.data.id}.${string}`;
@@ -87,6 +90,9 @@ class Feature {
8790

8891
return element[reactKey]
8992
}
93+
this.getInternalKey = function(element) {
94+
return Object.keys(element).find((key) => key.startsWith("__reactInternalInstance")) || null
95+
}
9096
this.redux = document.querySelector("#app")?.[
9197
Object.keys(app).find((key) => key.startsWith("__reactContainer"))
9298
].child.stateNode.store

api/main.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,23 @@ if (
101101
ScratchTools.type = "Website";
102102
}
103103

104+
ScratchTools.MESSAGES = []
105+
ScratchTools.sendMessage = function(id, content) {
106+
let uuid = UUID()
107+
chrome.runtime.sendMessage(ScratchTools.id, { message: id, content, source: "message-api", uuid });
108+
return new Promise((resolve, reject) => {
109+
ScratchTools.MESSAGES.push({ message: id, source: "message-api", uuid, resolve });
110+
});
111+
}
112+
113+
function UUID() {
114+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (char) {
115+
const random = Math.random() * 16 | 0;
116+
const value = char === 'x' ? random : (random & 0x3 | 0x8);
117+
return value.toString(16);
118+
});
119+
}
120+
104121
var storagePromises = [];
105122
ScratchTools.storage = {
106123
get: async function (key) {
@@ -409,7 +426,7 @@ ScratchTools.waitForElements(
409426
scratchClass("menu_hoverable_");
410427

411428
var div = document.createElement("div");
412-
div.className = "settings-menu_option_3rMur";
429+
div.className = "settings-menu_option_GGukG";
413430

414431
var icon = document.createElement("img");
415432
icon.src = ScratchTools.icons.main;

api/module.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ function scratchClass(name) {
2121
}
2222
}
2323

24+
function className(name) {
25+
return "ste-" + name.toLowerCase().replaceAll(" ", "-")
26+
}
27+
2428
ScratchTools.modules.forEach(async function (script) {
2529
var feature = await import(ScratchTools.dir + "/api/feature/index.js");
2630
var shouldBeRun = true;
@@ -41,6 +45,7 @@ ScratchTools.modules.forEach(async function (script) {
4145
fun.default({
4246
feature: featureGenerated,
4347
scratchClass,
48+
className,
4449
console: {
4550
log: function (content) {
4651
ste.console.log(content, script.feature.id);
@@ -78,6 +83,7 @@ ScratchTools.injectModule = async function (script) {
7883
fun.default({
7984
feature: featureGenerated,
8085
scratchClass,
86+
className,
8187
console: {
8288
log: function (content) {
8389
ste.console.log(content, script.feature.id);

api/update/changelogs/forum.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"active": false,
3+
"title": "Forum Changes for {{ version }}",
4+
"description": "",
5+
"changes": []
6+
}
7+

api/update/changelogs/project.json

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"active": true,
3+
"title": "Project Page Changes for {{ version }}",
4+
"description": "ScratchTools is introducing many new project page and editor features that will revolutionize the way that you use Scratch. You can enable them on the settings page.",
5+
"changes": [
6+
{
7+
"icon": "gradient.svg",
8+
"slogan": "Rotate gradient colors in the paint editor"
9+
},
10+
{
11+
"icon": "align.svg",
12+
"slogan": "Align shapes and objects in the paint editor"
13+
},
14+
{
15+
"icon": "align.svg",
16+
"slogan": "Quickly center text in your project instructions"
17+
},
18+
{
19+
"icon": "extend.svg",
20+
"slogan": "Extend C-blocks around code when dragging them"
21+
},
22+
{
23+
"icon": "filesize.svg",
24+
"slogan": "View file sizes for any asset"
25+
},
26+
{
27+
"icon": "font.svg",
28+
"slogan": "Use dozens of extra fonts in the paint editor"
29+
},
30+
{
31+
"icon": "nocloud.svg",
32+
"slogan": "Temporarily disable cloud variables in projects"
33+
},
34+
{
35+
"icon": "opacity.svg",
36+
"slogan": "Customize the opacity of stage variable monitors"
37+
},
38+
{
39+
"icon": "outline.svg",
40+
"slogan": "Customize and round lines and shape outlines"
41+
},
42+
{
43+
"icon": "reaction.svg",
44+
"slogan": "Add and view emoji reactions on any project"
45+
},
46+
{
47+
"icon": "record.svg",
48+
"slogan": "Record and save videos of your project stage"
49+
},
50+
{
51+
"icon": "shapes.svg",
52+
"slogan": "Unite, subtract, intersect, and exclude shapes"
53+
},
54+
{
55+
"icon": "thumbnail.svg",
56+
"slogan": "Upload custom project thumbnails"
57+
},
58+
{
59+
"icon": "upload.svg",
60+
"slogan": "Upload WEBP images as costumes and sprites"
61+
}
62+
]
63+
}

api/update/changelogs/website.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"active": true,
3+
"title": "Website Changes for {{ version }}",
4+
"description": "ScratchTools is introducing many new features for the Scratch website. You can enable them on the settings page.",
5+
"changes": [
6+
{
7+
"icon": "change.svg",
8+
"slogan": "Customize what tag is used by default on the explore page"
9+
},
10+
{
11+
"icon": "gift.svg",
12+
"slogan": "A ScratchTools selection of featured projects"
13+
},
14+
{
15+
"icon": "filter.svg",
16+
"slogan": "Filter through studio, explore, and searched projects"
17+
},
18+
{
19+
"icon": "date.svg",
20+
"slogan": "See when a studio was created"
21+
},
22+
{
23+
"icon": "countdown.svg",
24+
"slogan": "View how many replies are left in a thread"
25+
}
26+
]
27+
}
28+

0 commit comments

Comments
 (0)