async function setIntervals() {
try {
const birth_intervals = await getIntervalJson();
for (const country in birth_intervals) {
setInterval(() => {
const countryElement = document.getElementById(country);
if (countryElement) {
countryElement.style.animation = 'none';
setTimeout(() => {
countryElement.style.animation = `flashColor 1s`;
}, 0);
} else {
console.log("setInterval failed: " + country);
}
}, birth_intervals[country]);
}
} catch (error) {
console.error("Failed to set intervals:", error);
}
}
function getIntervalJson() {
console.log("Fetching birth_intervals.json");
return fetch('birth-map/birth_intervals.json')
.then(response => {
if (!response.ok) {
throw new Error("Bad network response.");
}
return response.json();
})
.catch(error => {
console.error("Failed to load birth rates:", error);
throw error;
});
}
setIntervals();