Widget:AvailableCritters: Difference between revisions
Jump to navigation
Jump to search
Marblemadmax (talk | contribs) No edit summary |
Marblemadmax (talk | contribs) No edit summary |
||
Line 3: | Line 3: | ||
// Critter availability | // Critter availability | ||
const critters = [ | const critters = [ | ||
{ "name": "Emerald Sunbird", "times": { "Monday": ["12:00", "24:00"] } }, | { "name": "Emerald Sunbird", "times": { "Monday": ["12:00", "24:00"] } }, | ||
{ "name": "Golden Sunbird", "times": { "Monday": ["00:00", "12:00"] } } | { "name": "Golden Sunbird", "times": { "Monday": ["00:00", "12:00"] } } | ||
]; | |||
// Function to check if a critter is available based on the current day and time | // Function to check if a critter is available based on the current day and time |
Revision as of 22:22, 26 February 2024
<script> document.addEventListener('DOMContentLoaded', function() {
// Critter availability const critters = [ { "name": "Emerald Sunbird", "times": { "Monday": ["12:00", "24:00"] } }, { "name": "Golden Sunbird", "times": { "Monday": ["00:00", "12: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>