Widget:CountdownStarPath

From Dreamlight Valley Wiki
Revision as of 02:36, 31 January 2024 by Marblemadmax (talk | contribs) (Created page with "<!-- Countdown Widget --> <div id="countdown-widget"></div> <script> (function() { // Function to update the countdown widget function updateCountdownWidget() { var currentDate = new Date(); var targetDate = new Date("2024-02-29T12:00:00-05:00"); // Replace with your target date and time var timeDifference = targetDate - currentDate; if (timeDifference <= 0) { // Countdown has elapsed, do not reset document.getElementById('countdown-wid...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

<script> (function() {

 // Function to update the countdown widget
 function updateCountdownWidget() {
   var currentDate = new Date();
   var targetDate = new Date("2024-02-29T12:00:00-05:00"); // Replace with your target date and time
   var timeDifference = targetDate - currentDate;
   if (timeDifference <= 0) {
     // Countdown has elapsed, do not reset
     document.getElementById('countdown-widget').innerHTML = "Countdown Ended";
     return;
   }
   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 >= 1) {
     countdownText = days + 'd ' + hours + 'h ' + minutes + 'm';
   } else if (hours >= 1) {
     countdownText = hours + 'h ' + minutes + 'm';
   } else if (minutes >= 1) {
     countdownText = minutes + 'm';
   } else {
     countdownText = (seconds < 10 ? '0' : ) + seconds + 's';
   }
   document.getElementById('countdown-widget').innerHTML = countdownText;
   // Update the countdown display every second
   setTimeout(updateCountdownWidget, 1000);
 }
 // Initial call to start the countdown widget
 window.onload = function() {
   updateCountdownWidget();
 };

})(); </script>