diff options
| author | Emma Terzioglu <emreterzioglu49@gmail.com> | 2026-03-13 13:49:15 -0700 |
|---|---|---|
| committer | Emma Terzioglu <emreterzioglu49@gmail.com> | 2026-03-13 13:49:15 -0700 |
| commit | 7a33856a527aebbd8d2a624c6d5937c25c9a1d90 (patch) | |
| tree | 855c642394e7ba1de40b8bb8737be12bec0aedaf /src/static/js/clocks.js | |
initial commit
new website repo yay!!!
Diffstat (limited to 'src/static/js/clocks.js')
| -rw-r--r-- | src/static/js/clocks.js | 45 |
1 files changed, 45 insertions, 0 deletions
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); +} |
