48 lines
1.1 KiB
JavaScript
48 lines
1.1 KiB
JavaScript
let build_id = "";
|
|
|
|
async function fetch_build_id()
|
|
{
|
|
const response = await fetch("/build-id");
|
|
const json = await response.json();
|
|
return json.build_id;
|
|
}
|
|
|
|
(async function() {
|
|
build_id = await fetch_build_id();
|
|
})();
|
|
|
|
|
|
const asyncIntervals = [];
|
|
|
|
const runAsyncInterval = async (cb, interval, intervalIndex) => {
|
|
await cb();
|
|
if (asyncIntervals[intervalIndex]) {
|
|
setTimeout(() => runAsyncInterval(cb, interval, intervalIndex), interval);
|
|
}
|
|
};
|
|
|
|
const setAsyncInterval = (cb, interval) => {
|
|
if (cb && typeof cb === "function") {
|
|
const intervalIndex = asyncIntervals.length;
|
|
asyncIntervals.push(true);
|
|
runAsyncInterval(cb, interval, intervalIndex);
|
|
return intervalIndex;
|
|
} else {
|
|
throw new Error('Callback must be a function');
|
|
}
|
|
};
|
|
|
|
const clearAsyncInterval = (intervalIndex) => {
|
|
if (asyncIntervals[intervalIndex]) {
|
|
asyncIntervals[intervalIndex] = false;
|
|
}
|
|
};
|
|
|
|
setAsyncInterval(async function () {
|
|
let new_build_id = await fetch_build_id();
|
|
if (build_id !== new_build_id) {
|
|
location.reload(true);
|
|
}
|
|
}, 1000);
|
|
|