52,234
edits
Marblemadmax (talk | contribs) mNo edit summary |
Marblemadmax (talk | contribs) mNo edit summary |
||
(5 intermediate revisions by the same user not shown) | |||
Line 60: | Line 60: | ||
}; | }; | ||
function isAvailable(critter, day, hour) { | |||
function isAvailable(critter, day, hour) { | const availability = critters[critter][day]; | ||
if (!availability) return false; // 'n/a' or undefined | |||
if (availability === 'All day') return true; | |||
const [start, end] = availability.split(' to '); | |||
const startHour = parseHour(start); | |||
const endHour = parseHour(end); | |||
return hour >= startHour && hour < endHour; | |||
} | |||
} | |||
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 updateCritterList() { | |||
function | const now = new Date(); | ||
const dayOfWeek = now.toLocaleString('en-US', { weekday: 'long' }); | |||
const hour = now.getHours(); | |||
let listContent = ''; | |||
Object.entries(critters).forEach(([critterName, _]) => { | |||
if (isAvailable(critterName, dayOfWeek, hour)) { | |||
listContent += `{{name|${critterName}}}<br>`; | |||
} | |||
} | }); | ||
parseContent(listContent); | |||
} | } | ||
/ | function parseContent(wikitext) { | ||
const apiEndpoint = "/api.php"; | |||
const params = new URLSearchParams({ | |||
action: 'parse', | |||
format: 'json', | |||
contentmodel: 'wikitext', | |||
text: wikitext, | |||
prop: 'text' | |||
}); | |||
fetch(apiEndpoint + "?" + params.toString(), { | |||
method: 'POST', | |||
credentials: 'same-origin' | |||
}) | |||
.then(response => response.json()) | |||
.then(data => { | |||
const parsedHtml = data.parse.text['*']; | |||
document.getElementById('critterList').innerHTML = parsedHtml; | |||
}) | |||
.catch(error => console.error('Error parsing content:', error)); | |||
} | } | ||
// | window.addEventListener('load', function() { | ||
updateCritterList(); // Initial update | |||
setInterval(updateCritterList, 60000); // Refresh every minute | |||
}); | |||
</script> | </script> |