Skip to content

Commit 72dfa01

Browse files
authored
Merge pull request #1028 from rgantzos/main
New feature: `real-date`
2 parents 6ba0e25 + dfa54ae commit 72dfa01

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-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": "real-date",
5+
"versionAdded": "v5.0.0"
6+
},
27
{
38
"version": 2,
49
"id": "comment-newlines",

features/real-date/data.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"title": "Real Profile Join Dates",
3+
"description": "Displays the real join date on profiles instead of the relative times.",
4+
"credits": [
5+
{
6+
"username": "rgantzos",
7+
"url": "https://scratch.mit.edu/users/rgantzos/"
8+
}
9+
],
10+
"dynamic": true,
11+
"scripts": [{ "file": "script.js", "runOn": "/users/*" }],
12+
"styles": [{ "file": "style.css", "runOn": "/users/*" }],
13+
"tags": ["New"],
14+
"type": ["Website"]
15+
}

features/real-date/script.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
export default async function ({ feature, console, className }) {
2+
if (document.querySelector("." + className("real profile date"))) return;
3+
4+
const PROFILE = Scratch.INIT_DATA.PROFILE.model.username
5+
6+
const data = await (await fetch(`https://api.scratch.mit.edu/users/${PROFILE}/`)).json()
7+
const joined = data.history.joined
8+
9+
const profileDetails = document.querySelector(".profile-details")
10+
profileDetails.classList.add(className("real profile date"))
11+
const profileDetailsChildNodes = profileDetails.childNodes
12+
const profileLocation = profileDetails.querySelector(".location")
13+
14+
const locationIndex = [...profileDetailsChildNodes].indexOf(profileLocation)
15+
const agoIndex = locationIndex - 1
16+
const dateIndex = locationIndex - 2
17+
18+
const oldJoined = profileDetailsChildNodes[dateIndex].textContent
19+
20+
const newAgo = Object.assign(document.createElement("span"), {
21+
textContent: profileDetailsChildNodes[agoIndex].textContent,
22+
className: className("hide ago real date")
23+
})
24+
25+
profileDetails.insertBefore(newAgo, profileDetails.querySelector(".location"))
26+
profileDetailsChildNodes[agoIndex].remove()
27+
28+
profileDetailsChildNodes[dateIndex].textContent = new Date(joined).toLocaleString()
29+
30+
feature.addEventListener("disabled", function() {
31+
profileDetailsChildNodes[dateIndex].textContent = oldJoined
32+
})
33+
34+
feature.addEventListener("enabled", function() {
35+
profileDetailsChildNodes[dateIndex].textContent = new Date(joined).toLocaleString()
36+
})
37+
}

features/real-date/style.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.ste-hide-ago-real-date {
2+
display: none;
3+
}

0 commit comments

Comments
 (0)