52,215
edits
Marblemadmax (talk | contribs) mNo edit summary |
Marblemadmax (talk | contribs) mNo edit summary |
||
Line 60: | Line 60: | ||
}; | }; | ||
// 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 | // Function to update the critter list based on the current time | ||
function | function updateCritterList() { | ||
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 listContent = ''; | |||
for (const [critterName, _] of Object.entries(critters)) { | |||
if (isAvailable(critterName, dayOfWeek, hour)) { | |||
listContent += `<p>{{name|${critterName}}}</p>`; | |||
} | |||
} | } | ||
const listContainer = document.getElementById('critterList'); | |||
if (listContainer) { | |||
listContainer.innerHTML = listContent; | |||
} else { | |||
console.log('List container not found'); | |||
} | |||
} | |||
} | } | ||
// | // Ensure the script runs after the page has loaded | ||
window.addEventListener('load', function() { | |||
updateCritterList(); // Update the list immediately upon loading | |||
setInterval(updateCritterList, 60000); // Update the list every minute | |||
}); | |||
</script> | </script> |