Publish eventLabs 0.5.0
This commit is contained in:
18
assets/events.js
Normal file
18
assets/events.js
Normal file
@@ -0,0 +1,18 @@
|
||||
function updateCountdowns() {
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
for (const clock of document.querySelectorAll('[data-be-countdown]')) {
|
||||
const remaining = Number(clock.dataset.beCountdown) - now;
|
||||
if (remaining <= 0) {
|
||||
clock.textContent = clock.dataset.beStarted;
|
||||
continue;
|
||||
}
|
||||
const days = Math.floor(remaining / 86400);
|
||||
const hours = Math.floor(remaining / 3600) % 24;
|
||||
const minutes = Math.floor(remaining / 60) % 60;
|
||||
const seconds = remaining % 60;
|
||||
const time = [hours, minutes, seconds].map((part) => String(part).padStart(2, '0')).join(':');
|
||||
clock.textContent = days ? `${days}d ${time}` : time;
|
||||
}
|
||||
}
|
||||
updateCountdowns();
|
||||
window.setInterval(updateCountdowns, 1000);
|
||||
Reference in New Issue
Block a user