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

De PokeXGames
Ir para navegação Ir para pesquisar
(Criou página com '<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.ori...')
 
Sem resumo de edição
Linha 11: Linha 11:
   const dzCard = document.getElementById('dz-card');  
   const dzCard = document.getElementById('dz-card');  


   fetch('http://worldtimeapi.org/api/timezone/America/Sao_Paulo')
   fetch('https://worldtimeapi.org/api/timezone/America/Sao_Paulo')
     .then(response => response.json())
     .then(response => response.json())
     .then(data => {
     .then(data => {

Edição das 21h13min de 18 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);

     const isFridayAfter7AM = currentDate.getDay() === 5 && currentDate.getHours() >= 7;

     if (isFridayAfter7AM) {
       actualWeekNumber++;
     }
     // Define the weeks starting with "First week"
     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' },
     ];

     let weekIndex = (actualWeekNumber - 1) % dzWeeks.length;

     if (dzCard) {
       dzCard.src = url + dzWeeks[weekIndex].image;
       dzCard.alt = dzWeeks[weekIndex].name;
     }
   })
   .catch(error => {
     console.error('Error fetching date and time:', error);
   });

}); </script>