Skip to content

Commit b0d8d73

Browse files
authored
Project Version Detector
New Feature: Checks when a project was shared and adds a label next to the share date to indicate which version of Scratch was in use at that time.
1 parent da7dcee commit b0d8d73

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"title": "Project Version Detector",
3+
"description": "Checks when a project was shared and adds a label next to the share date to indicate which version of Scratch was in use at that time.",
4+
"credits": [
5+
{ "username": "MaterArc"
6+
, "url": "https://scratch.mit.edu/users/MaterArc/"
7+
}
8+
],
9+
"type": ["Website"],
10+
"tags": ["New"],
11+
"dynamic": true,
12+
"styles": [
13+
{
14+
"file": "script.js",
15+
"runOn": "/projects/*"
16+
}
17+
]
18+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const shareDateDiv = document.querySelector('.share-date');
2+
3+
if (shareDateDiv) {
4+
const shareDateSpan = shareDateDiv.querySelector('span');
5+
6+
if (shareDateSpan) {
7+
const shareDate = shareDateSpan.textContent.trim();
8+
const shareDateObject = new Date(shareDate);
9+
10+
const versionDates = [
11+
{ version: "Scratch 1.0", date: new Date("May 15, 2007") },
12+
{ version: "Scratch 1.1", date: new Date("May 26, 2007") },
13+
{ version: "Scratch 1.2", date: new Date("December 2, 2007") },
14+
{ version: "Scratch 1.3", date: new Date("September 2, 2008") },
15+
{ version: "Scratch 1.3.1", date: new Date("November 24, 2008") },
16+
{ version: "Scratch 1.4", date: new Date("July 2, 2009") },
17+
{ version: "Scratch 2.0", date: new Date("May 9, 2013") },
18+
{ version: "Scratch 3.0", date: new Date("January 2, 2019") },
19+
];
20+
21+
let detectedVersion = null;
22+
23+
for (const versionInfo of versionDates) {
24+
if (shareDateObject >= versionInfo.date) {
25+
detectedVersion = versionInfo.version;
26+
} else {
27+
break;
28+
}
29+
}
30+
31+
const additionalInfoSpan = document.createElement('span');
32+
additionalInfoSpan.textContent = ' • Shared in ' + detectedVersion;
33+
34+
shareDateSpan.parentNode.insertBefore(additionalInfoSpan, shareDateSpan.nextSibling);
35+
}
36+
}

0 commit comments

Comments
 (0)