Widget:DzScript

Revisão de 15h08min de 26 de agosto de 2024 por Renee (discussão | contribs)

document.addEventListener('DOMContentLoaded', function () {

 const dzWeeks = [
   { name: 'Décima semana', image: '/images/3/30/Card_DZ_D%C3%A9cima-Semana.png' }, // 1ª semana
   { name: 'Décima primeira semana', image: '/images/4/49/Card_DZ_D%C3%A9cima-Primeira-Semana.png' }, // 2ª semana
   // ... restante das semanas
 ];
 const url = window.location.origin;
 const dzCard = document.getElementById('dz-card');
 
 let currentWeekNumber = parseInt(localStorage.getItem('currentWeekNumber')) || 0;
 
 const today = new Date();
 const lastUpdate = localStorage.getItem('lastUpdate');
 const lastUpdateDate = lastUpdate ? new Date(lastUpdate) : null;
 const targetHour = 7;
 const targetMinute = 40;
 if (today.getDay() === 5 && 
     (today.getHours() > targetHour || (today.getHours() === targetHour && today.getMinutes() >= targetMinute))) {
   
   if (!lastUpdateDate || lastUpdateDate < today.setHours(targetHour, targetMinute, 0, 0)) {
     currentWeekNumber = (currentWeekNumber + 1) % dzWeeks.length;
     localStorage.setItem('currentWeekNumber', currentWeekNumber);
     localStorage.setItem('lastUpdate', new Date().toISOString());
   }
 }
 dzCard.src = url + dzWeeks[currentWeekNumber].image;
 dzCard.alt = dzWeeks[currentWeekNumber].name;

});