Skip to content

Commit d1b5ea8

Browse files
authored
Merge pull request #928 from MaterArc/studio-creation-date
Studio Creation Date
2 parents 3e76ef5 + 641cb0a commit d1b5ea8

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-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": "studio-creation-date",
5+
"versionAdded": "v4.0.0"
6+
},
27
{
38
"version": 2,
49
"id": "explore-filter",
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: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
export default function ({ feature }) {
2+
ScratchTools.waitForElements(
3+
".studio-info-footer-stats",
4+
async function (footer) {
5+
if (document.querySelector(".ste-studio-created")) 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+
creationDateDiv.classList.add("ste-studio-created")
35+
36+
const creationDateImg = document.createElement("img");
37+
creationDateImg.src = feature.self.getResource("calendar");
38+
39+
const creationDateSpan = document.createElement("span");
40+
creationDateSpan.textContent = formattedDate;
41+
42+
creationDateDiv.appendChild(creationDateImg);
43+
creationDateDiv.appendChild(creationDateSpan);
44+
45+
footer.insertBefore(creationDateDiv, footer.firstChild);
46+
}
47+
);
48+
}

0 commit comments

Comments
 (0)