Skip to content

Commit 1cd7e89

Browse files
authored
Merge pull request #806 from STForScratch/MaterArc-patch-20
Project Version Detector
2 parents da7dcee + 66e1d18 commit 1cd7e89

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

features/features.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
[
2+
{
3+
"version": 2,
4+
"id": "project-version-detector",
5+
"versionAdded": "v3.8.0"
6+
},
27
{
38
"version": 2,
49
"id": "download-project",
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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", "url": "https://scratch.mit.edu/users/MaterArc/" }
6+
],
7+
"type": ["Website"],
8+
"tags": ["New"],
9+
"dynamic": true,
10+
"scripts": [
11+
{
12+
"file": "script.js",
13+
"runOn": "/projects/*"
14+
}
15+
]
16+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
export default async function ({ feature, console }) {
2+
ScratchTools.waitForElements("div.share-date", function (shareDateDiv) {
3+
const shareDateSpan = shareDateDiv.querySelector("span");
4+
5+
if (shareDateSpan) {
6+
const shareDate = shareDateSpan.textContent.trim();
7+
const shareDateObject = new Date(shareDate);
8+
9+
const versionDates = [
10+
{ version: "Scratch 1.0", date: new Date("May 15, 2007") },
11+
{ version: "Scratch 1.1", date: new Date("May 26, 2007") },
12+
{ version: "Scratch 1.2", date: new Date("December 2, 2007") },
13+
{ version: "Scratch 1.3", date: new Date("September 2, 2008") },
14+
{ version: "Scratch 1.3.1", date: new Date("November 24, 2008") },
15+
{ version: "Scratch 1.4", date: new Date("July 2, 2009") },
16+
{ version: "Scratch 2.0", date: new Date("May 9, 2013") },
17+
{ version: "Scratch 3.0", date: new Date("January 2, 2019") },
18+
];
19+
20+
let detectedVersion = null;
21+
22+
for (const versionInfo of versionDates) {
23+
if (shareDateObject >= versionInfo.date) {
24+
detectedVersion = versionInfo.version;
25+
} else {
26+
break;
27+
}
28+
}
29+
30+
const additionalInfoSpan = document.createElement("span");
31+
additionalInfoSpan.textContent = " • Shared in " + detectedVersion;
32+
33+
shareDateSpan.parentNode.insertBefore(
34+
additionalInfoSpan,
35+
shareDateSpan.nextSibling
36+
);
37+
38+
feature.self.hideOnDisable(additionalInfoSpan)
39+
}
40+
});
41+
}

0 commit comments

Comments
 (0)