mirror of
https://github.com/LucasKalil-Programador/world-2026-hub.git
synced 2026-07-04 17:41:28 -03:00
perf(app): optimize countdown rendering and hero clock polling
This commit is contained in:
parent
715ecedbcb
commit
1f23daf120
1 changed files with 9 additions and 1 deletions
|
|
@ -357,12 +357,20 @@ function setupCountdown(target) {
|
||||||
countdownEls = Object.fromEntries(
|
countdownEls = Object.fromEntries(
|
||||||
units.map((unit) => [unit, root.querySelector(`[data-unit="${unit}"]`)]),
|
units.map((unit) => [unit, root.querySelector(`[data-unit="${unit}"]`)]),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
lastSeconds = null;
|
||||||
updateCountdown();
|
updateCountdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let lastSeconds = null
|
||||||
|
|
||||||
function updateCountdown() {
|
function updateCountdown() {
|
||||||
if (!countdownEls) return;
|
if (!countdownEls) return;
|
||||||
const seconds = Math.floor(Math.max(0, countdownTarget - Date.now()) / 1000);
|
const seconds = Math.floor(Math.max(0, countdownTarget - Date.now()) / 1000);
|
||||||
|
|
||||||
|
if (seconds === lastSeconds) return;
|
||||||
|
lastSeconds = seconds;
|
||||||
|
|
||||||
countdownEls.days.textContent = Math.floor(seconds / 86400);
|
countdownEls.days.textContent = Math.floor(seconds / 86400);
|
||||||
countdownEls.hours.textContent = String(Math.floor((seconds % 86400) / 3600)).padStart(2, '0');
|
countdownEls.hours.textContent = String(Math.floor((seconds % 86400) / 3600)).padStart(2, '0');
|
||||||
countdownEls.minutes.textContent = String(Math.floor((seconds % 3600) / 60)).padStart(2, '0');
|
countdownEls.minutes.textContent = String(Math.floor((seconds % 3600) / 60)).padStart(2, '0');
|
||||||
|
|
@ -374,7 +382,7 @@ function updateCountdown() {
|
||||||
// match), the signature flips and we rebuild the hero — no reload, no JSON edit.
|
// match), the signature flips and we rebuild the hero — no reload, no JSON edit.
|
||||||
function startHeroClock() {
|
function startHeroClock() {
|
||||||
if (heroTimer) return;
|
if (heroTimer) return;
|
||||||
heroTimer = setInterval(heroTick, 1000);
|
heroTimer = setInterval(heroTick, 250);
|
||||||
}
|
}
|
||||||
|
|
||||||
function heroTick() {
|
function heroTick() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue