// Variável global para o intervalo do contador
let countdownInterval;
// Função para carregar o widget
function loadWidget() {
// Cria um elemento
para o widget
const widgetContainer = document.createElement('div');
widgetContainer.id = 'widget-container';
widgetContainer.innerHTML = `
`;
// Adiciona o widget ao final do
document.body.appendChild(widgetContainer);
// Inicializa o contador
initializeCountdown();
}
// Função para inicializar o contador
function initializeCountdown() {
const countdownDate = new Date(2024, 1, 14, 23, 59, 59).getTime();
function updateCountdown() {
const now = new Date().getTime();
const distance = countdownDate - now;
const days = Math.floor(distance / (1000 * 60 * 60 * 24));
const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((distance % (1000 * 60)) / 1000;
document.getElementById('days').innerText = String(days).padStart(2, '0');
document.getElementById('hours').innerText = String(hours).padStart(2, '0');
document.getElementById('minutes').innerText = String(minutes).padStart(2, '0');
document.getElementById('seconds').innerText = String(seconds).padStart(2, '0');
if (distance < 0) {
clearInterval(countdownInterval);
document.getElementById('countdown-timer').innerHTML = '
A promoção acabou!
';
}
}
// Inicia o contador
countdownInterval = setInterval(updateCountdown, 1000);
updateCountdown(); // Atualiza imediatamente
}
// Função para reiniciar o contador
function resetTimer() {
clearInterval(countdownInterval);
initializeCountdown();
}
// Carrega o widget quando a página é carregada
window.onload = loadWidget;