transbeam/static/js/download.js

20 lines
719 B
JavaScript
Raw Normal View History

let updateInterval;
document.addEventListener("DOMContentLoaded", () => {
const table = document.getElementById("download_contents").getElementsByTagName("tbody")[0];
if (table.children.length === 0) { return; }
updateInterval = setInterval(() => {
fetch(`info?code=${CODE}`)
.then((res) => res.json())
.then((info) => {
for (const [index, offset] of info.offsets.entries()) {
table.children[index].className = (offset > info.available) ? "unavailable" : "";
}
if (info.available === info.file.size) {
clearInterval(updateInterval);
}
});
}, 5000);
});