Widget:AvailableCritters: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 1: Line 1:
<script>
<script>
document.addEventListener('DOMContentLoaded', function() {
document.addEventListener('DOMContentLoaded', function() {
   // Example structure for critter availability
   // Critter availability
   const critters = [
   const critters = [
     [
     [
Line 66: Line 66:
     const now = new Date();
     const now = new Date();
     const dayOfWeek = now.toLocaleString('en-US', { weekday: 'long' });
     const dayOfWeek = now.toLocaleString('en-US', { weekday: 'long' });
     const currentTime = now.getHours() + ':' + now.getMinutes();
     const currentTime = now.getHours().toString().padStart(2, '0') + ':' + now.getMinutes().toString().padStart(2, '0');
     const gallery = document.getElementById('crittergallery');
     const gallery = document.getElementById('crittergallery');
     let galleryContent = '';
     let galleryContent = '';
Line 73: Line 73:
       const availability = critter.times[dayOfWeek];
       const availability = critter.times[dayOfWeek];
       if (availability) {
       if (availability) {
         const startTime = availability[0];
         const [startTime, endTime] = availability.map(time => time.replace('AM', ':00').replace('PM', ':00'));
         const endTime = availability[1];
         // assuming times don't cross midnight
         if (currentTime >= startTime && currentTime < endTime) {
         if (currentTime >= startTime && currentTime < endTime) {
          // Assuming critter names match file names exactly
           galleryContent += `File:${critter.name.replace(/ /g, '_')}.png|link=${critter.name}\n`;
           galleryContent += `File:{critter.name.replace(/ /g, '_')}.png|link=${critter.name}`;
         }
         }
       }
       }