44 lines
1.6 KiB
TypeScript
44 lines
1.6 KiB
TypeScript
import { timeAgo } from "./util";
|
|
|
|
interface LatestStatus {
|
|
username: string;
|
|
status: string;
|
|
title: string;
|
|
emoji?: string;
|
|
updated: Date;
|
|
}
|
|
|
|
(async () => {
|
|
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.innerHTML = decodeURIComponent(latestEntry.status); // I trust status.cafe, and myself with the contents of this string.
|
|
|
|
statusElement.appendChild(h2);
|
|
statusElement.appendChild(p);
|
|
})();
|