Widget:CountdownStarPath: Difference between revisions

From Dreamlight Valley Wiki
Jump to navigation Jump to search
(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...")
 
No edit summary
Line 1: Line 1:
<!-- Countdown Widget -->
<div id="countdown-starpath"></div>
<div id="countdown-widget"></div>


<script>
<script>
Line 34: Line 33:
     }
     }


     document.getElementById('countdown-widget').innerHTML = countdownText;
     document.getElementById('countdown-starpath').innerHTML = countdownText;


     // Update the countdown display every second
     // Update the countdown display every second
Line 40: Line 39:
   }
   }


   // Initial call to start the countdown widget
   // Initial call to start the widget countdown
   window.onload = function() {
   window.onload = function() {
     updateCountdownWidget();
     updateCountdownWidget();

Revision as of 02:40, 31 January 2024

<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-starpath').innerHTML = countdownText;
   // Update the countdown display every second
   setTimeout(updateCountdownWidget, 1000);
 }
 // Initial call to start the widget countdown
 window.onload = function() {
   updateCountdownWidget();
 };

})(); </script>