This commit is contained in:
parent
2d526f189b
commit
f91d315440
|
@ -1,59 +1,11 @@
|
||||||
__TEMPLATE_HEAD__
|
__TEMPLATE_HEAD__
|
||||||
|
|
||||||
<script type="module" src="scripts/blog.js"></script>
|
<script type="module" src="scripts/blog.js"></script>
|
||||||
<script type="module">
|
<script type="module" src="scripts/status_cafe.js"></script>
|
||||||
function timeAgo(input) {
|
|
||||||
const date = (input instanceof Date) ? input : new Date(input);
|
|
||||||
const formatter = new Intl.RelativeTimeFormat('en');
|
|
||||||
const ranges = [
|
|
||||||
['years', 3600 * 24 * 365],
|
|
||||||
['months', 3600 * 24 * 30],
|
|
||||||
['weeks', 3600 * 24 * 7],
|
|
||||||
['days', 3600 * 24],
|
|
||||||
['hours', 3600],
|
|
||||||
['minutes', 60],
|
|
||||||
['seconds', 1],
|
|
||||||
];
|
|
||||||
const secondsElapsed = (date.getTime() - Date.now()) / 1000;
|
|
||||||
|
|
||||||
for (const [rangeType, rangeVal] of ranges) {
|
|
||||||
if (rangeVal < Math.abs(secondsElapsed)) {
|
|
||||||
const delta = secondsElapsed / rangeVal;
|
|
||||||
return formatter.format(Math.round(delta), rangeType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const req = await fetch("https://status.cafe/users/sophie.atom");
|
|
||||||
const parser = new DOMParser();
|
|
||||||
const doc = parser.parseFromString(await req.text(), "text/xml");
|
|
||||||
const latestEntryRaw = doc.querySelector("feed > entry");
|
|
||||||
const latestEntry = {
|
|
||||||
username: doc.querySelector("feed > author > name").textContent,
|
|
||||||
status: latestEntryRaw.querySelector("content").textContent,
|
|
||||||
title: latestEntryRaw.querySelector("title").textContent,
|
|
||||||
updated: new Date(latestEntryRaw.querySelector("updated").textContent)
|
|
||||||
}
|
|
||||||
latestEntry.emoji = latestEntry.title.slice(latestEntry.username.length).slice(0, -Math.min(latestEntry.status.length, 53)).trim()
|
|
||||||
const statusElement = document.getElementById("status");
|
|
||||||
const h2 = document.createElement("h2");
|
|
||||||
const a = document.createElement("a");
|
|
||||||
const p = document.createElement("p");
|
|
||||||
|
|
||||||
a.href = "https://status.cafe/users/" + latestEntry.username;
|
|
||||||
a.innerText = latestEntry.emoji + " " + latestEntry.username;
|
|
||||||
h2.appendChild(a);
|
|
||||||
h2.innerHTML += " - " + timeAgo(latestEntry.updated);
|
|
||||||
|
|
||||||
p.style.textAlign = "end";
|
|
||||||
p.innerText = latestEntry.status;
|
|
||||||
|
|
||||||
statusElement.appendChild(h2);
|
|
||||||
statusElement.appendChild(p);
|
|
||||||
</script>
|
|
||||||
<script>
|
<script>
|
||||||
window.addEventListener("load", () => {
|
window.addEventListener("load", () => {
|
||||||
const stickers = document.getElementById("stickers");
|
const stickers = document.getElementById("stickers");
|
||||||
|
const binkies = document.getElementById("binkies");
|
||||||
if (!stickers) return;
|
if (!stickers) return;
|
||||||
|
|
||||||
for (const sticker of __STICKERS__) {
|
for (const sticker of __STICKERS__) {
|
||||||
|
@ -76,7 +28,7 @@ __TEMPLATE_HEAD__
|
||||||
<p>I love to play games with peeps! My favorite games recently have been Minecraft and Stardew Valley! DM me
|
<p>I love to play games with peeps! My favorite games recently have been Minecraft and Stardew Valley! DM me
|
||||||
if you wanna play with me ^w^
|
if you wanna play with me ^w^
|
||||||
</p>
|
</p>
|
||||||
|
<p><a href="https://files.sad.ovh/public/midis">Did you know that I have a 6 gigabyte big MiDi collection? (empty password/username)</a></p>
|
||||||
<p>
|
<p>
|
||||||
DNI:
|
DNI:
|
||||||
<br>
|
<br>
|
||||||
|
|
64
website/scripts/status_cafe.ts
Normal file
64
website/scripts/status_cafe.ts
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
interface LatestStatus {
|
||||||
|
username: string;
|
||||||
|
status: string;
|
||||||
|
title: string;
|
||||||
|
emoji?: string;
|
||||||
|
updated: Date;
|
||||||
|
}
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
function timeAgo(input: number | Date) {
|
||||||
|
const date = input instanceof Date ? input : new Date(input);
|
||||||
|
const formatter = new Intl.RelativeTimeFormat("en");
|
||||||
|
const ranges = [
|
||||||
|
["years", 3600 * 24 * 365],
|
||||||
|
["months", 3600 * 24 * 30],
|
||||||
|
["weeks", 3600 * 24 * 7],
|
||||||
|
["days", 3600 * 24],
|
||||||
|
["hours", 3600],
|
||||||
|
["minutes", 60],
|
||||||
|
["seconds", 1],
|
||||||
|
] as const;
|
||||||
|
const secondsElapsed = (date.getTime() - Date.now()) / 1000;
|
||||||
|
|
||||||
|
for (const [rangeType, rangeVal] of ranges) {
|
||||||
|
if (rangeVal < Math.abs(secondsElapsed)) {
|
||||||
|
const delta = secondsElapsed / rangeVal;
|
||||||
|
return formatter.format(Math.round(delta), rangeType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const req = await fetch("https://status.cafe/users/sophie.atom");
|
||||||
|
const parser = new DOMParser();
|
||||||
|
const doc = parser.parseFromString(await req.text(), "text/xml");
|
||||||
|
const latestEntryRaw = doc.querySelector("feed > entry");
|
||||||
|
if (!latestEntryRaw) throw new Error("Missing latest entry!");;
|
||||||
|
|
||||||
|
const latestEntry: LatestStatus = {
|
||||||
|
username: doc.querySelector("feed > author > name")?.textContent!,
|
||||||
|
status: latestEntryRaw.querySelector("content")?.textContent!,
|
||||||
|
title: latestEntryRaw.querySelector("title")?.textContent!,
|
||||||
|
updated: new Date(latestEntryRaw.querySelector("updated")?.textContent!),
|
||||||
|
};
|
||||||
|
latestEntry.emoji = latestEntry.title
|
||||||
|
.slice(latestEntry.username.length)
|
||||||
|
.slice(0, -Math.min(latestEntry.status.length, 53))
|
||||||
|
.trim();
|
||||||
|
const statusElement = document.getElementById("status");
|
||||||
|
if(!statusElement) throw new Error("Missing status element!");
|
||||||
|
const h2 = document.createElement("h2");
|
||||||
|
const a = document.createElement("a");
|
||||||
|
const p = document.createElement("p");
|
||||||
|
|
||||||
|
a.href = "https://status.cafe/users/" + latestEntry.username;
|
||||||
|
a.innerText = latestEntry.emoji + " " + latestEntry.username;
|
||||||
|
h2.appendChild(a);
|
||||||
|
h2.innerHTML += " - " + timeAgo(latestEntry.updated);
|
||||||
|
|
||||||
|
p.style.textAlign = "end";
|
||||||
|
p.innerText = latestEntry.status;
|
||||||
|
|
||||||
|
statusElement.appendChild(h2);
|
||||||
|
statusElement.appendChild(p);
|
||||||
|
})();
|
Loading…
Reference in a new issue