Widget:AvailableCritters: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
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().toString().padStart(2, '0') + ':' + now.getMinutes().toString().padStart(2, '0');
     const currentHour = now.getHours();
     const gallery = document.getElementById('crittergallery');
     const gallery = document.getElementById('crittergallery'); // Ensure this ID matches your gallery's ID
     let galleryContent = '';
     let galleryContent = '<gallery widths=60px heights=60px class="clothesgallery">';


     critters.forEach(critter => {
     crittersAvailability.forEach(critter => {
       const availability = critter.times[dayOfWeek];
       const times = critter.available[dayOfWeek];
       if (availability) {
       if (times) {
         const [startTime, endTime] = availability.map(time => time.replace('AM', ':00').replace('PM', ':00'));
         times.forEach(time => {
        // assuming times don't cross midnight
          const [start, end] = time.split('-').map(t => parseInt(t.split(':')[0], 10)); // assuming times don't cross midnight
        if (currentTime >= startTime && currentTime < endTime) {
          if ((currentHour >= start && currentHour < end) || end === 24 && currentHour === 0) {
          galleryContent += `File:${critter.name.replace(/ /g, '_')}.png|link=${critter.name}\n`;
            galleryContent += `File:${critter.name.replace(/ /g, '_')}.png|link=${critter.name}\n`;
         }
          }
         });
       }
       }
     });
     });


    galleryContent += '</gallery>';
     gallery.innerHTML = galleryContent;
     gallery.innerHTML = galleryContent;
   }
   }


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

Navigation menu