(function () { function check(url, method, callback) { const http = new XMLHttpRequest(); http.onreadystatechange = function () { if (http.readyState === 4 && http.status === 200) { if (callback) callback(http); } }; http.open(method, url); http.setRequestHeader("Pragma", "no-cache"); http.setRequestHeader("Cache-Control", "no-cache"); http.send(); } function update() { const url = self.location.href.split("#")[0].split("?")[0]; check(url, "HEAD", function (request) { const local = document.querySelector('meta[name="last-modified"]').content; const remote = request.getResponseHeader("last-modified") || local; const localHour = local.substring(0, local.length - 9); const remoteHour = remote.substring(0, remote.length - 9); const modified = localHour !== remoteHour; if (modified) { const indicator = document.querySelector("a[data-update]"); check(url, "GET"); indicator.href = url; indicator.removeAttribute("id"); indicator.dataset.update = "refresh"; self.removeEventListener("blur", update); console.log("R: " + remote); console.log("L: " + local); console.log("M: " + modified); } }); } self.addEventListener("blur", update); })();