Widget:AvailableCritters

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

<script> // gallerySwitcher.js

// Function to switch images based on the day and time function switchGalleryImage() {

 // Get the current day and time
 var now = new Date();
 var dayOfWeek = now.getDay(); // Sunday is 0, Monday is 1, ..., Saturday is 6
 var currentTime = now.getHours();
 // Define the gallery element ID
 var galleryId = 'crittergallery';
 // Define the image sources for each day and time range
 var imageSources = {
   0: { start: 0, end: 24, source: 'Classic_Squirrel.png' },
   1: { start: 0, end: 24, source: 'Red_Squirrel.png' },
   2: { start: 0, end: 24, source: 'Black_Squirrel.png' },
   // Add entries for other days and times as needed
 };
 // Get the gallery element
 var gallery = document.getElementById(galleryId);
 // Check if the gallery element exists
 if (gallery) {
   // Get the image source based on the current day and time
   var imageSource = imageSources[dayOfWeek];
   if (imageSource && currentTime >= imageSource.start && currentTime < imageSource.end) {
     // Change the source of the first image in the gallery
     gallery.getElementsByTagName('img')[0].src = imageSource.source;
   }
 }

}

// Call the switchGalleryImage function when the page is loaded window.onload = switchGalleryImage; </script>