|
| 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