Skip to content

Commit 5921319

Browse files
authored
Studio Creation Date
1 parent 3e76ef5 commit 5921319

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"title": "Studio Creation Date",
3+
"description": "Adds the creation date of the studio to the studio footer.",
4+
"credits": [
5+
{
6+
"username": "MaterArc",
7+
"url": "https://scratch.mit.edu/users/MaterArc/"
8+
}
9+
],
10+
"type": ["Website"],
11+
"tags": ["New"],
12+
"dynamic": true,
13+
"scripts": [{ "file": "script.js", "runOn": "/studios/*" }],
14+
"resources": [{ "name": "calendar", "path": "/calendar.svg" }]
15+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
export default function ({ feature }) {
2+
ScratchTools.waitForElements(
3+
".studio-info-footer-stats",
4+
async function (footer) {
5+
if (!footer) return;
6+
7+
const studioId = window.location.href.match(/studios\/(\d+)/)[1];
8+
const apiUrl = `https://api.scratch.mit.edu/studios/${studioId}`;
9+
10+
const response = await fetch(apiUrl);
11+
const data = await response.json();
12+
13+
const createdDate = new Date(data.history.created);
14+
const monthNames = [
15+
"Jan",
16+
"Feb",
17+
"Mar",
18+
"Apr",
19+
"May",
20+
"Jun",
21+
"Jul",
22+
"Aug",
23+
"Sep",
24+
"Oct",
25+
"Nov",
26+
"Dec",
27+
];
28+
const formattedDate = `Created ${
29+
monthNames[createdDate.getUTCMonth()]
30+
} ${createdDate.getUTCDate()}, ${createdDate.getUTCFullYear()}`;
31+
32+
const creationDateDiv = document.createElement("div");
33+
creationDateDiv.classList.add("studio-creation-date");
34+
35+
const creationDateImg = document.createElement("img");
36+
creationDateImg.src = feature.self.getResource("calendar");
37+
38+
const creationDateSpan = document.createElement("span");
39+
creationDateSpan.textContent = formattedDate;
40+
41+
creationDateDiv.appendChild(creationDateImg);
42+
creationDateDiv.appendChild(creationDateSpan);
43+
44+
footer.insertBefore(creationDateDiv, footer.firstChild);
45+
}
46+
);
47+
}

0 commit comments

Comments
 (0)