2022-05-24 22:47:58 -04:00
|
|
|
let updateInterval;
|
|
|
|
|
2022-05-24 16:49:48 -04:00
|
|
|
document.addEventListener("DOMContentLoaded", () => {
|
2023-11-16 21:37:15 -05:00
|
|
|
const downloadContents = document.getElementById("download_contents");
|
|
|
|
if (!downloadContents) { return; }
|
|
|
|
const table = downloadContents.getElementsByTagName("tbody")[0];
|
2022-05-24 16:49:48 -04:00
|
|
|
if (table.children.length === 0) { return; }
|
|
|
|
|
2022-05-24 22:47:58 -04:00
|
|
|
updateInterval = setInterval(() => {
|
2022-05-24 16:49:48 -04:00
|
|
|
fetch(`info?code=${CODE}`)
|
2022-05-25 08:56:55 -04:00
|
|
|
.then((res) => {
|
|
|
|
if (res.status === 404) {
|
|
|
|
clearInterval(updateInterval);
|
|
|
|
return Promise.reject("Download not found");
|
|
|
|
} else {
|
|
|
|
return res.json();
|
|
|
|
}
|
|
|
|
})
|
2022-05-24 16:49:48 -04:00
|
|
|
.then((info) => {
|
|
|
|
for (const [index, offset] of info.offsets.entries()) {
|
|
|
|
table.children[index].className = (offset > info.available) ? "unavailable" : "";
|
|
|
|
}
|
2022-05-25 09:05:35 -04:00
|
|
|
if (info.offsets.length === 0 || info.available >= info.offsets.at(-1)) {
|
2022-05-24 22:47:58 -04:00
|
|
|
clearInterval(updateInterval);
|
|
|
|
}
|
2022-05-25 08:56:55 -04:00
|
|
|
})
|
|
|
|
.catch(console.error);
|
2022-05-24 16:49:48 -04:00
|
|
|
}, 5000);
|
|
|
|
});
|