// ==========================================
// CUENTA REGRESIVA DE 21 HORAS
// ==========================================
const DURACION = 21 * 60 * 60 * 1000;
// Si ya existe un inicio guardado, continúa desde allí.
// Así, recargar la página NO reinicia las 21 horas.
let inicio = localStorage.getItem("countdownInicio");
if (!inicio) {
inicio = Date.now();
localStorage.setItem("countdownInicio", inicio);
} else {
inicio = parseInt(inicio);
}
const fechaFinal = inicio + DURACION;
function actualizarCuenta() {
const ahora = Date.now();
let restante = fechaFinal - ahora;
if (restante <= 0) {
restante = 0;
}
const dias = Math.floor(restante / (1000 * 60 * 60 * 24));
const horas = Math.floor(
(restante % (1000 * 60 * 60 * 24)) /
(1000 * 60 * 60)
);
const minutos = Math.floor(
(restante % (1000 * 60 * 60)) /
(1000 * 60)
);
const segundos = Math.floor(
(restante % (1000 * 60)) /
1000
);
document.getElementById("days").textContent =
String(dias).padStart(2, "0");
document.getElementById("hours").textContent =
String(horas).padStart(2, "0");
document.getElementById("minutes").textContent =
String(minutos).padStart(2, "0");
document.getElementById("seconds").textContent =
String(segundos).padStart(2, "0");
// Cuando termina
if (restante === 0) {
clearInterval(intervalo);
document.querySelector(".countdown-title").textContent =
"¡YA ESTÁ DISPONIBLE!";
}
}
actualizarCuenta();
const intervalo = setInterval(actualizarCuenta, 1000);