goveal/assets/web/js/reload.js

24 lines
613 B
JavaScript
Raw Normal View History

let knownHashes = {}
function getLatestHash(path) {
let request = new XMLHttpRequest()
request.open("GET", `/hash/md5${path}`)
request.onload = () => {
if(request.status === 200) {
let hashResp = JSON.parse(request.responseText)
if(path in knownHashes && knownHashes[path] !== hashResp["Hash"]) {
window.location.reload()
} else {
knownHashes[path] = hashResp["Hash"]
}
}
}
request.send()
}
function subscribeForUpdates(path) {
setInterval(() => {
getLatestHash(path)
}, 1000)
}