diff --git a/features/features.json b/features/features.json index ec2b4a66..37c3e7fa 100644 --- a/features/features.json +++ b/features/features.json @@ -1,4 +1,9 @@ [ + { + "version": 2, + "id": "real-date", + "versionAdded": "v5.0.0" + }, { "version": 2, "id": "comment-newlines", diff --git a/features/real-date/data.json b/features/real-date/data.json new file mode 100644 index 00000000..9ca76807 --- /dev/null +++ b/features/real-date/data.json @@ -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"] +} diff --git a/features/real-date/script.js b/features/real-date/script.js new file mode 100644 index 00000000..cbffe62e --- /dev/null +++ b/features/real-date/script.js @@ -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() + }) +} \ No newline at end of file diff --git a/features/real-date/style.css b/features/real-date/style.css new file mode 100644 index 00000000..6b53141b --- /dev/null +++ b/features/real-date/style.css @@ -0,0 +1,3 @@ +.ste-hide-ago-real-date { + display: none; +} \ No newline at end of file