Widget:AvailableCritters: Difference between revisions

Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 87: Line 87:
     const hour = now.getHours(); // Get current hour in 24-hour format
     const hour = now.getHours(); // Get current hour in 24-hour format


     let galleryContent = '';
     let galleryContent = '<gallery>';
     for (const [critter, _] of Object.entries(critters)) {
     for (const [critter, _] of Object.entries(critters)) {
         if (isAvailable(critter, dayOfWeek, hour)) {
         if (isAvailable(critter, dayOfWeek, hour)) {
             galleryContent += `File:${critter.replace(/ /g, '_')}.png|link=${critter}\n`;
             galleryContent += `File:${critter.replace(/ /g, '_')}.png|${critter}\n`;
         }
         }
     }
     }
    galleryContent += '</gallery>';


    // Assuming you have a div with id 'critterGallery' to host the gallery
     const galleryContainer = document.getElementById('critterGallery');
     const galleryContainer = document.getElementById('critterGallery');
     if (galleryContainer) {
     if (galleryContainer) {
         galleryContainer.innerHTML = `<gallery widths="50px" heights="50px" class="clothesgallery">${galleryContent}</gallery>`;
         galleryContainer.innerHTML = galleryContent;
    } else {
        console.log('Gallery container not found');
     }
     }
}
}


// Listen for the wikipage.content hook to update the gallery after MediaWiki processes the content
// Ensure script runs after MediaWiki and its modules are available
window.addEventListener('load', function() {
window.addEventListener('load', function() {
     if (typeof mw === 'object' && typeof mw.hook === 'function') {
     if (typeof mw === 'object' && typeof mw.hook === 'function') {
Line 112: Line 114:
});
});


// Update the gallery immediately on script load, in case it's not triggered by mw.hook
// Attempt to update gallery immediately on script load
updateGallery();
updateGallery();
</script>
</script>