Widget:DzScript2: mudanças entre as edições

De PokeXGames
Ir para navegação Ir para pesquisar
Sem resumo de edição
Etiqueta: Revertido
Sem resumo de edição
Etiqueta: Reversão manual
Linha 42: Linha 42:


       // Offset to start at "Sexta semana"
       // Offset to start at "Sexta semana"
       let offset = 6;
       let offset = 5;
       let weekIndex = ((actualWeekNumber - 1) + offset) % dzWeeks.length;
       let weekIndex = ((actualWeekNumber - 1) + offset) % dzWeeks.length;



Edição das 21h00min de 19 de outubro de 2024

<script> document.addEventListener('DOMContentLoaded', function () {

 function getWeekNumber(date) {
   let d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
   let dayNum = d.getUTCDay() || 7; // Ensures Sunday (0) is the last day of the week
   let yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
   return Math.ceil((((d - yearStart) / 86400000) + dayNum) / 7); // Calculate the week number
 }
 const url = window.location.origin;
 const dzCard = document.getElementById('dz-card'); 
 fetch('https://worldtimeapi.org/api/timezone/America/Sao_Paulo')
   .then(response => response.json())
   .then(data => {
     const currentDate = new Date(data.datetime);
     let actualWeekNumber = getWeekNumber(currentDate);
     // Check if it's Friday and after 7 AM in local time
     const isFridayAfter7AM = currentDate.getDay() === 5 && currentDate.getHours() >= 7;
     // Increment the week number only if it's Friday after 7 AM
     if (isFridayAfter7AM) {
       actualWeekNumber++;
     }
     // Define the weeks starting with "Sexta semana"
     const dzWeeks = [
       { name: 'Sexta semana', image: '/images/2/23/Card_DZ_Sexta-Semana.png' },
       { name: 'Sétima semana', image: '/images/f/f2/Card_DZ_S%C3%A9tima-Semana.png' },
       { name: 'Oitava semana', image: '/images/9/97/Card_DZ_Oitava-Semana.png' },
       { name: 'Nona semana', image: '/images/b/b3/Card_DZ_Nona-Semana.png' },
       { name: 'Décima semana', image: '/images/3/30/Card_DZ_D%C3%A9cima-Semana.png' },
       { name: 'Décima primeira semana', image: '/images/4/49/Card_DZ_D%C3%A9cima-Primeira-Semana.png' },
       { name: 'Décima segunda semana', image: '/images/1/11/Card_DZ_D%C3%A9cima-Segunda-Semana.png' },
       { name: 'Primeira semana', image: '/images/b/b2/Card_DZ_Primeira-Semana.png' },
       { name: 'Segunda semana', image: '/images/9/97/Card_DZ_Segunda-Semana.png' },
       { name: 'Terceira semana', image: '/images/f/fd/Card_DZ_Terceira-Semana.png' },
       { name: 'Quarta semana', image: '/images/1/17/Card_DZ_Quarta-Semana.png' },
       { name: 'Quinta semana', image: '/images/4/40/Card_DZ_Quinta-Semana.png' },
     ];
     // Offset to start at "Sexta semana"
     let offset = 5;
     let weekIndex = ((actualWeekNumber - 1) + offset) % dzWeeks.length;
     // Update the image only if dzCard is found
     if (dzCard) {
       dzCard.src = url + dzWeeks[weekIndex].image;
       dzCard.alt = dzWeeks[weekIndex].name;
     }
   })
   .catch(error => {
     console.error('Error fetching date and time:', error);
   });

}); </script>