Widget:CountdownPremium

From Dreamlight Valley Wiki
Revision as of 02:43, 6 February 2024 by Marblemadmax (talk | contribs)
Jump to navigation Jump to search

<script> (function() {

 // Function to update the premium countdown
 function updatePremiumCountdown() {
   var currentDate = new Date();
   var targetDay = 3;
   var targetHour = 14; // Adjusted to 1pm UTC
   var nextWednesday = new Date(currentDate);
   nextWednesday.setUTCHours(targetHour, 0, 0, 0);
   // If today is Wednesday and the target hour has passed, move to the next Wednesday
   if (currentDate.getUTCDay() === targetDay && currentDate.getUTCHours() >= targetHour) {
     nextWednesday.setDate(nextWednesday.getDate() + 7);
   }
   while (nextWednesday.getUTCDay() !== targetDay) {
     nextWednesday.setDate(nextWednesday.getDate() + 1);
   }
   var timeDifference = nextWednesday - currentDate;
   if (timeDifference < 0) {
     nextWednesday.setDate(nextWednesday.getDate() + 7);
     timeDifference = nextWednesday - currentDate;
   }
   var days = Math.floor(timeDifference / (24 * 60 * 60 * 1000));
   var hours = Math.floor((timeDifference % (24 * 60 * 60 * 1000)) / (60 * 60 * 1000));
   var minutes = Math.floor((timeDifference % (60 * 60 * 1000)) / (60 * 1000));
   var seconds = Math.floor((timeDifference % (60 * 1000)) / 1000);
   var countdownText = ;
   if (days > 0) {
     countdownText += days + 'd ';
   }
   countdownText += ('0' + hours).slice(-2) + 'h ' +
                    ('0' + minutes).slice(-2) + 'm';
   document.getElementById('countdown-premium').innerHTML = countdownText;
   // Use a separate setTimeout for premium countdown
   setTimeout(updatePremiumCountdown, 1000);
 }
 window.onload = function() {
   updatePremiumCountdown();
 };

})(); </script>