From 5921319a758ad06fac7936a090a6614de218e579 Mon Sep 17 00:00:00 2001 From: MaterArc <105017592+MaterArc@users.noreply.github.com> Date: Fri, 12 Jul 2024 14:43:21 -0400 Subject: [PATCH 1/3] Studio Creation Date --- features/studio-creation-date/calendar.svg | 3 ++ features/studio-creation-date/data.json | 15 +++++++ features/studio-creation-date/script.js | 47 ++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 features/studio-creation-date/calendar.svg create mode 100644 features/studio-creation-date/data.json create mode 100644 features/studio-creation-date/script.js diff --git a/features/studio-creation-date/calendar.svg b/features/studio-creation-date/calendar.svg new file mode 100644 index 00000000..320d0de6 --- /dev/null +++ b/features/studio-creation-date/calendar.svg @@ -0,0 +1,3 @@ + + + diff --git a/features/studio-creation-date/data.json b/features/studio-creation-date/data.json new file mode 100644 index 00000000..ddbc2fac --- /dev/null +++ b/features/studio-creation-date/data.json @@ -0,0 +1,15 @@ +{ + "title": "Studio Creation Date", + "description": "Adds the creation date of the studio to the studio footer.", + "credits": [ + { + "username": "MaterArc", + "url": "https://scratch.mit.edu/users/MaterArc/" + } + ], + "type": ["Website"], + "tags": ["New"], + "dynamic": true, + "scripts": [{ "file": "script.js", "runOn": "/studios/*" }], + "resources": [{ "name": "calendar", "path": "/calendar.svg" }] +} diff --git a/features/studio-creation-date/script.js b/features/studio-creation-date/script.js new file mode 100644 index 00000000..3f72f0d2 --- /dev/null +++ b/features/studio-creation-date/script.js @@ -0,0 +1,47 @@ +export default function ({ feature }) { + ScratchTools.waitForElements( + ".studio-info-footer-stats", + async function (footer) { + if (!footer) return; + + const studioId = window.location.href.match(/studios\/(\d+)/)[1]; + const apiUrl = `https://api.scratch.mit.edu/studios/${studioId}`; + + const response = await fetch(apiUrl); + const data = await response.json(); + + const createdDate = new Date(data.history.created); + const monthNames = [ + "Jan", + "Feb", + "Mar", + "Apr", + "May", + "Jun", + "Jul", + "Aug", + "Sep", + "Oct", + "Nov", + "Dec", + ]; + const formattedDate = `Created ${ + monthNames[createdDate.getUTCMonth()] + } ${createdDate.getUTCDate()}, ${createdDate.getUTCFullYear()}`; + + const creationDateDiv = document.createElement("div"); + creationDateDiv.classList.add("studio-creation-date"); + + const creationDateImg = document.createElement("img"); + creationDateImg.src = feature.self.getResource("calendar"); + + const creationDateSpan = document.createElement("span"); + creationDateSpan.textContent = formattedDate; + + creationDateDiv.appendChild(creationDateImg); + creationDateDiv.appendChild(creationDateSpan); + + footer.insertBefore(creationDateDiv, footer.firstChild); + } + ); +} From 89b34a73656c3048147dd6f720e6eeb159ee2f17 Mon Sep 17 00:00:00 2001 From: MaterArc <105017592+MaterArc@users.noreply.github.com> Date: Fri, 12 Jul 2024 14:44:08 -0400 Subject: [PATCH 2/3] Update features.json --- features/features.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/features/features.json b/features/features.json index fa38492f..77393409 100644 --- a/features/features.json +++ b/features/features.json @@ -1,4 +1,9 @@ [ + { + "version": 2, + "id": "studio-creation-date", + "versionAdded": "v4.0.0" + }, { "version": 2, "id": "explore-filter", From 641cb0a445fc2cb3e1b199ebeb252f2831d4fe52 Mon Sep 17 00:00:00 2001 From: rgantzos <86856959+rgantzos@users.noreply.github.com> Date: Fri, 12 Jul 2024 12:10:56 -0700 Subject: [PATCH 3/3] Update script.js --- features/studio-creation-date/script.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/features/studio-creation-date/script.js b/features/studio-creation-date/script.js index 3f72f0d2..527839ed 100644 --- a/features/studio-creation-date/script.js +++ b/features/studio-creation-date/script.js @@ -2,7 +2,7 @@ export default function ({ feature }) { ScratchTools.waitForElements( ".studio-info-footer-stats", async function (footer) { - if (!footer) return; + if (document.querySelector(".ste-studio-created")) return; const studioId = window.location.href.match(/studios\/(\d+)/)[1]; const apiUrl = `https://api.scratch.mit.edu/studios/${studioId}`; @@ -31,6 +31,7 @@ export default function ({ feature }) { const creationDateDiv = document.createElement("div"); creationDateDiv.classList.add("studio-creation-date"); + creationDateDiv.classList.add("ste-studio-created") const creationDateImg = document.createElement("img"); creationDateImg.src = feature.self.getResource("calendar");