Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions features/features.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
[
{
"version": 2,
"id": "real-date",
"versionAdded": "v5.0.0"
},
{
"version": 2,
"id": "comment-newlines",
Expand Down
15 changes: 15 additions & 0 deletions features/real-date/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"title": "Real Profile Join Dates",
"description": "Displays the real join date on profiles instead of the relative times.",
"credits": [
{
"username": "rgantzos",
"url": "https://scratch.mit.edu/users/rgantzos/"
}
],
"dynamic": true,
"scripts": [{ "file": "script.js", "runOn": "/users/*" }],
"styles": [{ "file": "style.css", "runOn": "/users/*" }],
"tags": ["New"],
"type": ["Website"]
}
37 changes: 37 additions & 0 deletions features/real-date/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
export default async function ({ feature, console, className }) {
if (document.querySelector("." + className("real profile date"))) return;

const PROFILE = Scratch.INIT_DATA.PROFILE.model.username

const data = await (await fetch(`https://api.scratch.mit.edu/users/${PROFILE}/`)).json()
const joined = data.history.joined

const profileDetails = document.querySelector(".profile-details")
profileDetails.classList.add(className("real profile date"))
const profileDetailsChildNodes = profileDetails.childNodes
const profileLocation = profileDetails.querySelector(".location")

const locationIndex = [...profileDetailsChildNodes].indexOf(profileLocation)
const agoIndex = locationIndex - 1
const dateIndex = locationIndex - 2

const oldJoined = profileDetailsChildNodes[dateIndex].textContent

const newAgo = Object.assign(document.createElement("span"), {
textContent: profileDetailsChildNodes[agoIndex].textContent,
className: className("hide ago real date")
})

profileDetails.insertBefore(newAgo, profileDetails.querySelector(".location"))
profileDetailsChildNodes[agoIndex].remove()

profileDetailsChildNodes[dateIndex].textContent = new Date(joined).toLocaleString()

feature.addEventListener("disabled", function() {
profileDetailsChildNodes[dateIndex].textContent = oldJoined
})

feature.addEventListener("enabled", function() {
profileDetailsChildNodes[dateIndex].textContent = new Date(joined).toLocaleString()
})
}
3 changes: 3 additions & 0 deletions features/real-date/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.ste-hide-ago-real-date {
display: none;
}