Skip to content

Commit 5d02630

Browse files
authored
Custom Explore Redirect
1 parent 2a88756 commit 5d02630

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

features/custom-explore/data.json

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"title": "Custom Explore Redirect",
3+
"description": "Automatically redirect to a specific tab on the Explore page.",
4+
"credits": [
5+
{
6+
"username": "ItsThatKittyDragon",
7+
"url": "https://scratch.mit.edu/users/ItsThatKittyDragon/"
8+
},
9+
{
10+
"username": "MaterArc",
11+
"url": "https://scratch.mit.edu/users/MaterArc/"
12+
}
13+
],
14+
"type": [
15+
"Website"
16+
],
17+
"tags": [
18+
"New",
19+
"Featured"
20+
],
21+
"scripts": [
22+
{
23+
"file": "script.js",
24+
"runOn": "/explore/projects/*||/"
25+
}
26+
],
27+
"dynamic": true,
28+
"options": [
29+
{
30+
"id": "custom-tab",
31+
"name": "",
32+
"type": 4,
33+
"options": [
34+
{
35+
"name": "Animations",
36+
"value": "animations"
37+
},
38+
{
39+
"name": "Art",
40+
"value": "art"
41+
},
42+
{
43+
"name": "Games",
44+
"value": "games"
45+
},
46+
{
47+
"name": "Music",
48+
"value": "music"
49+
},
50+
{
51+
"name": "Stories",
52+
"value": "stories"
53+
},
54+
{
55+
"name": "Tutorials",
56+
"value": "tutorials"
57+
}
58+
]
59+
}
60+
]
61+
}

features/custom-explore/script.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export default async function({ feature, console }) {
2+
let tabName = ScratchTools.Storage["customtab"];
3+
4+
function updateRedirect() {
5+
const exploreLink = document.querySelector('li.link.explore > a');
6+
if (exploreLink && window.location.href === 'https://scratch.mit.edu/explore/projects/all') {
7+
exploreLink.href = `https://scratch.mit.edu/explore/projects/${tabName}`;
8+
window.location.href = exploreLink.href;
9+
}
10+
}
11+
12+
await ScratchTools.waitForElement('li.link.explore > a');
13+
updateRedirect();
14+
15+
feature.options.addEventListener('changed', async ({ key, value }) => {
16+
if (key === 'customtab') {
17+
tabName = value;
18+
updateRedirect();
19+
}
20+
});
21+
}

0 commit comments

Comments
 (0)