From 6839831af54cd9302119bcc3bffafe10475958d4 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Mon, 3 Aug 2026 14:31:25 +0200 Subject: refactor project structure * merge sites into single project root * fix name of mass-graduation site * enable typescript support --- src/utils-common.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/utils-common.ts (limited to 'src/utils-common.ts') diff --git a/src/utils-common.ts b/src/utils-common.ts new file mode 100644 index 0000000..89a8ddd --- /dev/null +++ b/src/utils-common.ts @@ -0,0 +1,25 @@ +"use strict"; + +export const DATE_FMT = new Intl.DateTimeFormat("de-DE", { month: "numeric", day: "numeric", year: "numeric"}); + +export const DATETIME_FMT = new Intl.DateTimeFormat("de-DE", { month: "numeric", day: "numeric", year: "numeric", hour: "numeric", minute: "numeric" }); + +export function dateStringNow() { + return DATE_FMT.format(new Date()); +} + +export function datetimeStringNow() { + return DATETIME_FMT.format(new Date()); +} + +// TODO(muhq): Cache the retrieved URL +export async function getUserIconUrl(userId: number) { + const userRes = await fetch(`https://lernplattform.bycs.de/user/profile.php?id=${userId}`) + const userDoc = new DOMParser().parseFromString(await userRes.text(), 'text/html') + const userpicture = userDoc.querySelector(".userpicture"); + if (userpicture === null) { + return ""; + } + + return (userpicture as HTMLImageElement).src; +} -- cgit v1.2.3