From 7a33856a527aebbd8d2a624c6d5937c25c9a1d90 Mon Sep 17 00:00:00 2001 From: Emma Terzioglu Date: Fri, 13 Mar 2026 13:49:15 -0700 Subject: initial commit new website repo yay!!! --- src/static/js/clocks.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/static/js/clocks.js (limited to 'src/static/js/clocks.js') diff --git a/src/static/js/clocks.js b/src/static/js/clocks.js new file mode 100644 index 0000000..da617b6 --- /dev/null +++ b/src/static/js/clocks.js @@ -0,0 +1,45 @@ +const updateClock = (start, e) => { + let timeSince = new Date().getTime() - start; + + let days = Math.floor(timeSince / (1000 * 60 * 60 * 24)); + let hours = Math.floor( + (timeSince % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60), + ); + let minutes = Math.floor((timeSince % (1000 * 60 * 60)) / (1000 * 60)); + let seconds = Math.floor((timeSince % (1000 * 60)) / 1000); + + const elems = e.getElementsByTagName("p"); + + for (const e of elems) { + switch (e.id) { + case "d": + e.innerHTML = days + "d"; + break; + case "h": + e.innerHTML = hours + "h"; + break; + case "m": + e.innerHTML = minutes + "m"; + break; + case "s": + e.innerHTML = seconds + "s"; + break; + default: + break; + } + } +}; + +const applyClock = (e) => { + const startattr = e.getAttributeNode("x-start-time"); + if (startattr === null) return; + + const start = Number.parseInt(startattr.value); + + setInterval(() => updateClock(start, e), 1000); +}; + +const clocks = document.getElementsByClassName("clock"); +for (const e of clocks) { + applyClock(e); +} -- cgit v1.2.3