51,573
edits
Marblemadmax (talk | contribs) mNo edit summary |
Marblemadmax (talk | contribs) mNo edit summary |
||
Line 60: | Line 60: | ||
}; | }; | ||
function updateCritterList() { | function updateCritterList() { | ||
const now = new Date(); | const now = new Date(); | ||
const dayOfWeek = now.toLocaleString('en-US', { weekday: 'long' }); | const dayOfWeek = now.toLocaleString('en-US', { weekday: 'long' }); | ||
const hour = now.getHours(); | const hour = now.getHours(); | ||
let listContent = ''; | |||
Object.entries(critters).forEach(([critterName, _]) => { | |||
if (isAvailable(critterName, dayOfWeek, hour)) { | if (isAvailable(critterName, dayOfWeek, hour)) { | ||
listContent += ` | listContent += `{{name|${critterName}}}<br>`; | ||
} | } | ||
} | }); | ||
parseContent(listContent); | |||
} | |||
function parseContent(wikitext) { | |||
const apiEndpoint = "/w/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() { | window.addEventListener('load', function() { | ||
updateCritterList(); // | updateCritterList(); // Initial update | ||
setInterval(updateCritterList, 60000); // | setInterval(updateCritterList, 60000); // Refresh every minute | ||
}); | }); | ||
</script> | </script> |