51,573
edits
Marblemadmax (talk | contribs) mNo edit summary |
Marblemadmax (talk | contribs) mNo edit summary |
||
Line 62: | Line 62: | ||
// Function to check if a critter is available | // Function to check if a critter is available | ||
function isAvailable(critter, day, hour) { | function isAvailable(critter, day, hour) { | ||
const times = critters[critter][day]; | |||
if (!times) return false; // 'n/a' or undefined | |||
if (times === 'All day') return true; | |||
const [start, end] = times.split(' to '); | |||
const startHour = parseHour(start); | |||
const endHour = parseHour(end); | |||
return hour >= startHour && hour < endHour; | |||
} | } | ||
// Helper function to parse hour string to 24-hour format number | // Helper function to parse hour string to 24-hour format number | ||
function parseHour(timeStr) { | function parseHour(timeStr) { | ||
const [time, period] = timeStr.split(' '); | |||
let [hours, minutes] = time.split(':'); | |||
hours = parseInt(hours); | |||
if (period === 'PM' && hours !== 12) hours += 12; | |||
if (period === 'AM' && hours === 12) hours = 0; | |||
return hours; | |||
} | } | ||
// Function to update the gallery | // Function to update the gallery | ||
function updateGallery() { | function updateGallery() { | ||
const now = new Date(); | |||
const dayOfWeek = now.toLocaleString('en-US', { weekday: 'long' }); // Get day name | |||
const hour = now.getHours(); // Get current hour in 24-hour format | |||
let galleryContent = ''; | |||
for (const [critter, _] of Object.entries(critters)) { | |||
if (isAvailable(critter, dayOfWeek, hour)) { | |||
galleryContent += `File:${critter.replace(/ /g, '_')}.png|link=${critter}\n`; | |||
} | |||
} | } | ||
// Assuming you have a div with id 'critterGallery' to host the gallery | |||
const galleryContainer = document.getElementById('critterGallery'); | |||
if (galleryContainer) { | |||
galleryContainer.innerHTML = `<gallery widths="50px" heights="50px" class="clothesgallery">${galleryContent}</gallery>`; | |||
} | |||
} | } | ||
// | // Listen for the wikipage.content hook to update the gallery after MediaWiki processes the content | ||
mw.hook('wikipage.content').add(function ($content) { | |||
updateGallery(); | updateGallery(); | ||
}); | |||
// Update the gallery immediately on script load, in case it's not triggered by mw.hook | |||
updateGallery(); | |||
</script> | </script> |