Widget:AvailableCritters: Difference between revisions
Jump to navigation
Jump to search
Marblemadmax (talk | contribs) No edit summary |
Marblemadmax (talk | contribs) No edit summary |
||
Line 63: | Line 63: | ||
]; | ]; | ||
// 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 => { | |||
times. | 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 = `<gallery widths=60px heights=60px class="clothesgallery">\n${newGalleryContent}\n</gallery>`; | |||
} | |||
} | |||
// Update the gallery | |||
updateGallery(); | |||
}); | }); | ||
</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>