diff options
author | Daniel Friesel <derf@finalrewind.org> | 2021-08-22 13:04:58 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2021-08-22 13:04:58 +0200 |
commit | 7fb32adf98e180c59ad9863cf1afd1af0b12125b (patch) | |
tree | a2c5cd802942858b7e10b7703261867958df92ae /static/js/reload.js | |
parent | 0a72758216e7486d89393eff5174f54b74f950b3 (diff) |
regularly update relative departure timestamps even when offline
Diffstat (limited to 'static/js/reload.js')
-rw-r--r-- | static/js/reload.js | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/static/js/reload.js b/static/js/reload.js index 2a3fbf3..0f167f1 100644 --- a/static/js/reload.js +++ b/static/js/reload.js @@ -6,6 +6,31 @@ document.addEventListener("DOMContentLoaded", function() { departureList.innerHTML = departureText; }; + const updateOfflineDepartures = () => { + const listEntries = departureList.children; + const now = Math.floor(Date.now() / 1000); + + for (const listEntry of listEntries) { + const departureTimestamp = listEntry.dataset.timestamp; + if (departureTimestamp < now) { + departureList.removeChild(listEntry); + } else { + countdownNodes = listEntry.querySelectorAll(".time"); + for (i = 0; i < countdownNodes.length; i++) { + for (const countdown of countdownNodes[i].childNodes) { + if ((countdown.nodeType == document.TEXT_NODE) && (countdown.textContent.includes("min"))) { + if (departureTimestamp - 60 < now) { + countdown.textContent = "sofort"; + } else { + countdown.textContent = Math.floor((departureTimestamp - now) / 60) + " min"; + } + } + } + } + } + } + }; + const fetchDepartures = () => { var fetchUrl = window.location.href; if (fetchUrl.includes("?")) { @@ -26,6 +51,7 @@ document.addEventListener("DOMContentLoaded", function() { }) .catch(err => { syncFailedMarker.style.display = "inline-block"; + updateOfflineDepartures(); }); }; |