Widget:AvailableCritters: Difference between revisions

From Dreamlight Valley Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 63: Line 63:
   ];
   ];


  function updateGallery() {
    // Function to check if a critter is available based on the current day and time
    const now = new Date();
    function isCritterAvailable(critter) {
    const dayOfWeek = now.toLocaleString('en-US', { weekday: 'long' });
        const now = new Date();
    const currentHour = now.getHours();
        const dayOfWeek = now.toLocaleString('en-us', { weekday: 'long' });
    const gallery = document.getElementById('crittergallery'); // Ensure this ID matches your gallery's ID
        const currentTime = now.getHours() * 100 + now.getMinutes();
    let galleryContent = '<gallery widths=60px heights=60px id="crittergallery" class="clothesgallery">';
        const times = critter.times[dayOfWeek];


    crittersAvailability.forEach(critter => {
        if (!times) return false; // Not available today
      const times = critter.available[dayOfWeek];
 
      if (times) {
         return times.some(timeRange => {
         times.forEach(time => {
            const [start, end] = timeRange.split('-').map(time => {
          const [start, end] = time.split('-').map(t => parseInt(t.split(':')[0], 10)); // assuming times don't cross midnight
                const [hours, minutes] = time.split(':');
          if ((currentHour >= start && currentHour < end) || end === 24 && currentHour === 0) {
                return parseInt(hours, 10) * 100 + parseInt(minutes, 10);
            galleryContent += `File:${critter.name.replace(/ /g, '_')}.png|link=${critter.name}\n`;
            });
          }
            return currentTime >= start && currentTime <= end;
         });
         });
      }
    }
     });
 
    // Function to generate gallery content string based on availability
     function generateGalleryContent(critters) {
        return critters.filter(isCritterAvailable).map(critter =>
            `File:${critter.name.replace(/ /g, '_')}.png|link=${critter.name}`
        ).join('\n');
    }


     galleryContent += '</gallery>';
     // Function to update the gallery
    gallery.innerHTML = galleryContent;
    function updateGallery() {
  }
        const galleryElement = document.getElementById('crittergallery');
        if (galleryElement) {
            const newGalleryContent = generateGalleryContent(critters);
            galleryElement.innerHTML = `<gallery widths=60px heights=60px class="clothesgallery">\n${newGalleryContent}\n</gallery>`;
        }
    }


  updateGallery();
    // Update the gallery
  // Optionally, set an interval to update the gallery periodically
    updateGallery();
  // setInterval(updateGallery, 60000); // every minute
});
});
</script>
</script>

Revision as of 22:14, 26 February 2024

<script> document.addEventListener('DOMContentLoaded', function() {

 // Critter availability
 const critters = [
   [
   { "name": "Emerald Sunbird", "times": { "Sunday": ["12:00", "24:00"], "Tuesday": ["00:00", "24:00"], "Wednesday": ["00:00", "24:00"], "Saturday": ["00:00", "24:00"] } },
   { "name": "Golden Sunbird", "times": { "Sunday": ["00:00", "12:00"], "Tuesday": ["00:00", "24:00"], "Thursday": ["00:00", "24:00"], "Friday": ["00:00", "24:00"] } },
   { "name": "Orchid Sunbird", "times": { "Friday": ["09:00", "15:00"] } },
   { "name": "Red Sunbird", "times": { "Sunday": ["12:00", "24:00"], "Monday": ["00:00", "24:00"], "Thursday": ["00:00", "24:00"], "Saturday": ["00:00", "24:00"] } },
   { "name": "Turquoise Sunbird", "times": { "Sunday": ["00:00", "12:00"], "Monday": ["00:00", "24:00"], "Wednesday": ["00:00", "24:00"], "Friday": ["00:00", "24:00"] } },
   { "name": "Black Squirrel", "times": { "Sunday": ["00:00", "12:00"], "Tuesday": ["00:00", "24:00"], "Thursday": ["00:00", "24:00"], "Friday": ["00:00", "24:00"] } },
   { "name": "Classic Squirrel", "times": { "Sunday": ["12:00", "24:00"], "Monday": ["00:00", "24:00"], "Thursday": ["00:00", "24:00"], "Saturday": ["00:00", "24:00"] } },
   { "name": "Gray Squirrel", "times": { "Sunday": ["12:00", "24:00"], "Tuesday": ["00:00", "24:00"], "Wednesday": ["00:00", "24:00"], "Saturday": ["00:00", "24:00"] } },
   { "name": "Red Squirrel", "times": { "Sunday": ["00:00", "12:00"], "Monday": ["00:00", "24:00"], "Wednesday": ["00:00", "24:00"], "Friday": ["00:00", "24:00"] } },
   { "name": "White Squirrel", "times": { "Sunday": ["00:00", "06:00"] } },
   { "name": "Blue Crocodile", "times": { "Sunday": ["00:00", "12:00"], "Monday": ["00:00", "24:00"], "Wednesday": ["00:00", "24:00"], "Friday": ["00:00", "24:00"] } },
   { "name": "Classic Crocodile", "times": { "Sunday": ["12:00", "24:00"], "Monday": ["00:00", "24:00"], "Thursday": ["00:00", "24:00"], "Saturday": ["00:00", "24:00"] } },
   { "name": "Golden Crocodile", "times": { "Sunday": ["00:00", "12:00"], "Tuesday": ["00:00", "24:00"], "Thursday": ["00:00", "24:00"], "Friday": ["00:00", "24:00"] } },
   { "name": "Pink Crocodile", "times": { "Saturday": ["06:00", "12:00"] } },
   { "name": "Red Crocodile", "times": { "Sunday": ["12:00", "24:00"], "Tuesday": ["00:00", "24:00"], "Wednesday": ["00:00", "24:00"], "Saturday": ["00:00", "24:00"] } },
   { "name": "White Crocodile", "times": { "Sunday": ["18:00", "24:00"] } },
   { "name": "Black Rabbit", "times": { "Sunday": ["00:00", "12:00"], "Monday": ["00:00", "24:00"], "Wednesday": ["00:00", "24:00"], "Friday": ["00:00", "24:00"] } },
   { "name": "Brown Rabbit", "times": { "Sunday": ["12:00", "24:00"], "Tuesday": ["00:00", "24:00"], "Wednesday": ["00:00", "24:00"], "Saturday": ["00:00", "24:00"] } },
   { "name": "Calico Rabbit", "times": { "Thursday": ["08:00", "14:00"] } },
   { "name": "Classic Rabbit", "times": { "Sunday": ["12:00", "24:00"], "Monday": ["00:00", "24:00"], "Thursday": ["00:00", "24:00"], "Saturday": ["00:00", "24:00"] } },
   { "name": "White Rabbit", "times": { "Sunday": ["00:00", "12:00"], "Tuesday": ["00:00", "24:00"], "Thursday": ["00:00", "24:00"], "Friday": ["00:00", "24:00"] } },
   { "name": "Blue Raven", "times": { "Sunday": ["00:00", "12:00"], "Tuesday": ["00:00", "24:00"], "Thursday": ["00:00", "24:00"], "Friday": ["00:00", "24:00"] } },
   { "name": "Brown Raven", "times": { "Tuesday": ["18:00", "24:00"] } },
   { "name": "Classic Raven", "times": { "Sunday": ["12:00", "24:00"], "Monday": ["00:00", "24:00"], "Thursday": ["00:00", "24:00"], "Saturday": ["00:00", "24:00"] } },
   { "name": "Red Raven", "times": { "Sunday": ["00:00", "12:00"], "Monday": ["00:00", "24:00"], "Wednesday": ["00:00", "24:00"], "Friday": ["00:00", "24:00"] } },
   { "name": "White Raven", "times": { "Sunday": ["12:00", "24:00"], "Tuesday": ["00:00", "24:00"], "Wednesday": ["00:00", "24:00"], "Saturday": ["00:00", "24:00"] } },
   { "name": "Black Sea Turtle", "times": { "Monday": ["10:00", "16:00"] } },
   { "name": "Brown Sea Turtle", "times": { "Sunday": ["00:00", "12:00"], "Monday": ["00:00", "24:00"], "Wednesday": ["00:00", "24:00"], "Friday": ["00:00", "24:00"] } },
   { "name": "Classic Sea Turtle", "times": { "Sunday": ["12:00", "24:00"], "Monday": ["00:00", "24:00"], "Thursday": ["00:00", "24:00"], "Saturday": ["00:00", "24:00"] } },
   { "name": "Purple Sea Turtle", "times": { "Sunday": ["00:00", "12:00"], "Tuesday": ["00:00", "24:00"], "Thursday": ["00:00", "24:00"], "Friday": ["00:00", "24:00"] } },
   { "name": "White Sea Turtle", "times": { "Sunday": ["12:00", "24:00"], "Tuesday": ["00:00", "24:00"], "Wednesday": ["00:00", "24:00"], "Saturday": ["00:00", "24:00"] } },
   { "name": "Black Fox", "times": { "Sunday": ["12:00", "24:00"], "Tuesday": ["00:00", "24:00"], "Wednesday": ["00:00", "24:00"], "Saturday": ["00:00", "24:00"] } },
   { "name": "Blue Fox", "times": { "Sunday": ["00:00", "12:00"], "Tuesday": ["00:00", "24:00"], "Thursday": ["00:00", "24:00"], "Friday": ["00:00", "24:00"] } },
   { "name": "Classic Fox", "times": { "Sunday": ["00:00", "12:00"], "Monday": ["00:00", "24:00"], "Wednesday": ["00:00", "24:00"], "Friday": ["00:00", "24:00"] } },
   { "name": "Red Fox", "times": { "Saturday": ["02:00", "08:00"] } },
   { "name": "White Fox", "times": { "Sunday": ["12:00", "24:00"], "Monday": ["00:00", "24:00"], "Thursday": ["00:00", "24:00"], "Saturday": ["00:00", "24:00"] } },
   { "name": "Black Raccoon", "times": { "Sunday": ["12:00", "24:00"], "Tuesday": ["00:00", "24:00"], "Wednesday": ["00:00", "24:00"], "Saturday": ["00:00", "24:00"] } },
   { "name": "Blue Raccoon", "times": { "Wednesday": ["16:00", "22:00"] } },
   { "name": "Classic Raccoon", "times": { "Sunday": ["12:00", "24:00"], "Monday": ["00:00", "24:00"], "Thursday": ["00:00", "24:00"], "Saturday": ["00:00", "24:00"] } },
   { "name": "Red Raccoon", "times": { "Sunday": ["00:00", "12:00"], "Monday": ["00:00", "24:00"], "Wednesday": ["00:00", "24:00"], "Friday": ["00:00", "24:00"] } },
   { "name": "White Raccoon", "times": { "Sunday": ["00:00", "12:00"], "Tuesday": ["00:00", "24:00"], "Thursday": ["00:00", "24:00"], "Friday": ["00:00", "24:00"] } },
   { "name": "Black and White Capybara", "times": { "Sunday": ["12:00", "24:00"], "Tuesday": ["00:00", "24:00"], "Friday": ["12:00", "24:00"], "Saturday": ["12:00", "24:00"] } },
   { "name": "Blue Striped Capybara", "times": { "Monday": ["00:00", "12:00"], "Tuesday": ["00:00", "12:00"], "Wednesday": ["00:00", "12:00"], "Thursday": ["00:00", "24:00"], "Saturday": ["00:00", "24:00"] } },
   { "name": "Classic Capybara", "times": { "Sunday": ["00:00", "24:00"], "Monday": ["00:00", "24:00"], "Tuesday": ["00:00", "24:00"], "Wednesday": ["00:00", "24:00"], "Thursday": ["00:00", "24:00"], "Friday": ["00:00", "24:00"], "Saturday": ["00:00", "24:00"] } },
   { "name": "Gray Spotted Capybara", "times": { "Sunday": ["00:00", "24:00"], "Monday": ["12:00", "24:00"], "Tuesday": ["12:00", "24:00"], "Wednesday": ["12:00", "24:00"], "Friday": ["00:00", "24:00"] } },
   { "name": "Red and White Striped Capybara", "times": { "Saturday": ["12:00", "18:00"] } },
   { "name": "Blue and Red Striped Cobra", "times": { "Sunday": ["00:00", "24:00"], "Monday": ["12:00", "24:00"], "Tuesday": ["12:00", "24:00"], "Thursday": ["00:00", "24:00"], "Saturday": ["12:00", "24:00"] } },
   { "name": "Classic Cobra", "times": { "Sunday": ["00:00", "24:00"], "Monday": ["00:00", "24:00"], "Tuesday": ["00:00", "24:00"], "Wednesday": ["00:00", "24:00"], "Thursday": ["00:00", "24:00"], "Friday": ["00:00", "24:00"], "Saturday": ["00:00", "24:00"] } },
   { "name": "Green and White Striped Cobra", "times": { "Thursday": ["06:00", "12:00"] } },
   { "name": "Pink Spotted Cobra", "times": { "Sunday": ["00:00", "12:00"], "Monday": ["00:00", "24:00"], "Wednesday": ["00:00", "12:00"], "Thursday": ["00:00", "12:00"], "Friday": ["00:00", "24:00"] } },
   { "name": "Yellow and Purple Striped Cobra", "times": { "Sunday": ["12:00", "24:00"], "Tuesday": ["00:00", "24:00"], "Wednesday": ["12:00", "24:00"], "Thursday": ["12:00", "24:00"], "Saturday": ["00:00", "24:00"] } },
   { "name": "Beige Monkey", "times": { "Sunday": ["00:00", "24:00"], "Monday": ["12:00", "24:00"], "Wednesday": ["12:00", "24:00"], "Thursday": ["00:00", "24:00"], "Friday": ["12:00", "24:00"] } },
   { "name": "Black and Brown Monkey", "times": { "Sunday": ["12:00", "24:00"], "Tuesday": ["12:00", "24:00"], "Wednesday": ["00:00", "24:00"], "Thursday": ["12:00", "24:00"], "Saturday": ["00:00", "24:00"] } },
   { "name": "Black and Gray Monkey", "times": { "Tuesday": ["18:00", "24:00"] } },
   { "name": "Classic Monkey", "times": { "Sunday": ["00:00", "24:00"], "Monday": ["00:00", "24:00"], "Tuesday": ["00:00", "24:00"], "Wednesday": ["00:00", "24:00"], "Thursday": ["00:00", "24:00"], "Friday": ["00:00", "24:00"], "Saturday": ["00:00", "24:00"] } },
   { "name": "Red and Beige Monkey", "times": { "Monday": ["00:00", "12:00"], "Tuesday": ["00:00", "24:00"], "Wednesday": ["00:00", "12:00"], "Friday": ["00:00", "12:00"], "Saturday": ["00:00", "24:00"] } }

]

 ];
   // Function to check if a critter is available based on the current day and time
   function isCritterAvailable(critter) {
       const now = new Date();
       const dayOfWeek = now.toLocaleString('en-us', { weekday: 'long' });
       const currentTime = now.getHours() * 100 + now.getMinutes();
       const times = critter.times[dayOfWeek];
       if (!times) return false; // Not available today
       return times.some(timeRange => {
           const [start, end] = timeRange.split('-').map(time => {
               const [hours, minutes] = time.split(':');
               return parseInt(hours, 10) * 100 + parseInt(minutes, 10);
           });
           return currentTime >= start && currentTime <= end;
       });
   }
   // Function to generate gallery content string based on availability
   function generateGalleryContent(critters) {
       return critters.filter(isCritterAvailable).map(critter => 
           `File:${critter.name.replace(/ /g, '_')}.png|link=${critter.name}`
       ).join('\n');
   }
   // Function to update the gallery
   function updateGallery() {
       const galleryElement = document.getElementById('crittergallery');
       if (galleryElement) {
           const newGalleryContent = generateGalleryContent(critters);

galleryElement.innerHTML = `

`;

       }
   }
   // Update the gallery
   updateGallery();

}); </script>