Skip to content

Commit 2fece35

Browse files
committed
Fix a few issues
1 parent eabd7fb commit 2fece35

File tree

2 files changed

+47
-43
lines changed

2 files changed

+47
-43
lines changed
Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
{
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/"
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/*"
714
}
8-
],
9-
"type": ["Website"],
10-
"tags": ["New"],
11-
"dynamic": true,
12-
"styles": [
13-
{
14-
"file": "script.js",
15-
"runOn": "/projects/*"
16-
}
17-
]
18-
}
15+
]
16+
}
Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,42 @@
1-
const shareDateDiv = document.querySelector('.share-date');
2-
3-
if (shareDateDiv) {
4-
const shareDateSpan = shareDateDiv.querySelector('span');
1+
export default async function ({ feature, console }) {
2+
ScratchTools.waitForElements("div.share-date", function (shareDateDiv) {
3+
const shareDateSpan = shareDateDiv.querySelector("span");
4+
console.log(shareDateSpan)
55

66
if (shareDateSpan) {
7-
const shareDate = shareDateSpan.textContent.trim();
8-
const shareDateObject = new Date(shareDate);
7+
const shareDate = shareDateSpan.textContent.trim();
8+
const shareDateObject = new Date(shareDate);
99

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-
];
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+
];
2020

21-
let detectedVersion = null;
21+
let detectedVersion = null;
2222

23-
for (const versionInfo of versionDates) {
24-
if (shareDateObject >= versionInfo.date) {
25-
detectedVersion = versionInfo.version;
26-
} else {
27-
break;
28-
}
23+
for (const versionInfo of versionDates) {
24+
if (shareDateObject >= versionInfo.date) {
25+
detectedVersion = versionInfo.version;
26+
} else {
27+
break;
2928
}
29+
}
30+
31+
const additionalInfoSpan = document.createElement("span");
32+
additionalInfoSpan.textContent = " • Shared in " + detectedVersion;
3033

31-
const additionalInfoSpan = document.createElement('span');
32-
additionalInfoSpan.textContent = ' • Shared in ' + detectedVersion;
34+
shareDateSpan.parentNode.insertBefore(
35+
additionalInfoSpan,
36+
shareDateSpan.nextSibling
37+
);
3338

34-
shareDateSpan.parentNode.insertBefore(additionalInfoSpan, shareDateSpan.nextSibling);
39+
feature.self.hideOnDisable(additionalInfoSpan)
3540
}
36-
}
41+
});
42+
}

0 commit comments

Comments
 (0)