Skip to content

Commit ebdee7d

Browse files
authored
Merge branch 'main' into main
2 parents 73a8d3a + fe1fb4f commit ebdee7d

8 files changed

Lines changed: 117 additions & 49 deletions

File tree

extras/feature-locales/en.json

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

features/admin-notifications.js

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"title": "Red Admin Message Indicator",
3+
"description": "If you have an admin notification from the Scratch Team, the message indicator in the navigation bar will display red instead of orange.",
4+
"credits": [
5+
{
6+
"username": "rgantzos",
7+
"url": "https://scratch.mit.edu/users/rgantzos"
8+
}
9+
],
10+
"scripts": [
11+
{
12+
"file": "script.js",
13+
"runOn": "/*"
14+
}
15+
],
16+
"styles": [
17+
{
18+
"file": "style.css",
19+
"runOn": "/*"
20+
}
21+
],
22+
"tags": [],
23+
"type": ["Website"],
24+
"dynamic": "true"
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export default async function ({ feature, console }) {
2+
const session = await ScratchTools.Session();
3+
if (!session.user) return;
4+
5+
const username = session.user.username;
6+
const response = await fetch(
7+
`https://api.scratch.mit.edu/users/${username}/messages/admin`,
8+
{
9+
headers: {
10+
"x-token": session.user.token,
11+
},
12+
}
13+
);
14+
const data = await response.json();
15+
16+
if (data.length > 0) {
17+
if (feature.tab.scratch === 2) {
18+
document
19+
.querySelector(".notificationsCount")
20+
.classList.add("ste-red-alert");
21+
} else {
22+
document.querySelector(".message-count").classList.add("ste-red-alert");
23+
}
24+
}
25+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.ste-red-alert {
2+
background-color: #ff1a1a !important;
3+
}

features/features.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
"id": "wrap-lists",
55
"versionAdded": "v3.3.0"
66
},
7+
{
8+
"version": 2,
9+
"id": "live-stats",
10+
"versionAdded": "v3.3.0"
11+
},
712
{
813
"version": 2,
914
"id": "hide-scratch-news",
@@ -237,6 +242,10 @@
237242
"version": 2,
238243
"id": "box-shadows"
239244
},
245+
{
246+
"version": 2,
247+
"id": "admin-notifications"
248+
},
240249
{
241250
"title": "Nicknames",
242251
"description": "Set nicknames for other Scratchers. Only you can see the nicknames, and their username will be replaced with the nickname when you see their name.",
@@ -677,15 +686,6 @@
677686
"type": ["Website", "Editor"],
678687
"dynamic": true
679688
},
680-
{
681-
"title": "Message Indicator Red for Admin Messages",
682-
"description": "If you have an admin notification from the Scratch Team, the message indicator in the navigation bar will display red instead of orange.",
683-
"credits": ["rgantzos"],
684-
"urls": ["https://scratch.mit.edu/users/rgantzos/"],
685-
"file": "admin-notifications",
686-
"tags": [],
687-
"type": ["Website"]
688-
},
689689
{
690690
"title": "Custom Website Font",
691691
"description": "On the Scratch website, you can set the font to whatever font you want, as long as it is on the Google Fonts website. This is case-sensitive.",

features/live-stats/data.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"title": "Live Stats",
3+
"description": "Updates the loves, favorites, remixes, and views on a project live, without having to reload to view the new counts.",
4+
"credits": [
5+
{
6+
"username": "RowanMoonBoy",
7+
"url": "https://scratch.mit.edu/users/RowanMoonBoy/"
8+
},
9+
{ "username": "rgantzos", "url": "https://scratch.mit.edu/users/rgantzos/" }
10+
],
11+
"scripts": [
12+
{
13+
"file": "script.js",
14+
"runOn": "/projects/*"
15+
}
16+
],
17+
"dynamic": true,
18+
"type": ["Website"],
19+
"tags": ["New", "Featured"]
20+
}

features/live-stats/script.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
export default function ({ feature, console }) {
2+
ScratchTools.waitForElements(
3+
"div.flex-row.stats.noselect",
4+
async function (row) {
5+
let love = row.querySelector(".project-loves");
6+
let favorite = row.querySelector(".project-favorites");
7+
let remix = row.querySelector(".project-remixes");
8+
let view = row.querySelector(".project-views");
9+
10+
let interval = setInterval(async function () {
11+
if (!row) clearInterval(interval);
12+
if (!row) return;
13+
if (!feature.self.enabled) return;
14+
15+
let data = await (
16+
await fetch(
17+
`https://api.scratch.mit.edu/projects/${
18+
window.location.pathname.split("/")[2]
19+
}/?nocache=${Date.now().toString()}`
20+
)
21+
).json();
22+
23+
if (data.error) return;
24+
25+
love.textContent = data.stats.loves.toString()
26+
favorite.textContent = data.stats.favorites.toString()
27+
remix.textContent = data.stats.remixes.toString()
28+
view.textContent = data.stats.views.toString()
29+
30+
feature.redux.getState().preview.projectInfo.stats = data.stats
31+
}, 5000);
32+
}
33+
);
34+
}

0 commit comments

Comments
 (0)