Widget:DzScript
Ir para navegação
Ir para pesquisar
<script> document.addEventListener('DOMContentLoaded', function () {
// Function to calculate week number based on a specific start date function getWeekNumberFromStart(date, startDate) { let diffTime = date.getTime() - startDate.getTime(); let diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24)); return Math.ceil(diffDays / 7); }
const url = window.location.origin; const dzCard = document.getElementById('dz-card'); // Check if dzCard exists on the page if (!dzCard) { console.error('Elemento dz-card não encontrado na página.'); return; } const today = new Date();
// Start date for week calculation const startDate = new Date('2024-10-19'); // Start of counting let actualWeekNumber = getWeekNumberFromStart(today, startDate);
// Check if it's Friday after 7 AM const isFridayAfter7AM = today.getDay() === 5 && today.getHours() >= 7;
// Check if it's Saturday const isSaturday = today.getDay() === 6;
// Increment week number if it's Friday after 7 AM or Saturday if (isFridayAfter7AM || isSaturday) { actualWeekNumber++; }
// Week data 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' }, ];
// Ensure the week index is correct let weekIndex = (actualWeekNumber - 1) % dzWeeks.length; if (weekIndex < 0) weekIndex += dzWeeks.length; // Correct negative index
// Update the image corresponding to the week dzCard.src = url + dzWeeks[weekIndex].image; dzCard.alt = dzWeeks[weekIndex].name;
});
</script>