diff options
Diffstat (limited to 'assets/js/index.js')
-rw-r--r-- | assets/js/index.js | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/assets/js/index.js b/assets/js/index.js index d3ff7bf..dc0bc0c 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -110,23 +110,24 @@ function update() { const url = self.location.href.split("#")[0].split("?")[0]; const indicator = document.querySelector("a[data-update]"); - if (indicator.dataset.update === "refresh" || indicator === null) return; + if (indicator === null || indicator.dataset.update === "refresh") return; indicator.cloneNode(); fetch(url, "HEAD", function(request) { const local = document.querySelector('meta[name="last-modified"]').content || document.lastModified; - const remote = request.getResponseHeader("last-modified") || document.lastModified; - const modified = Date.parse(remote) > Date.parse(local); - const drift = Date.parse(remote) - Date.parse(local); + const remote = request.getResponseHeader("last-modified") || ''; + const modified = Date.parse(remote || local) > Date.parse(local); + const drift = Date.parse(remote || local) - Date.parse(local); if (drift < 10000) return; if (remote && modified) { - fetch(url, "GET"); - indicator.href = url; - indicator.removeAttribute("id"); - indicator.dataset.update = "refresh"; - console.log("INFO: R: " + remote); - console.log("INFO: L: " + local); - console.log("INFO: D: " + drift); - console.log("INFO: M: " + modified); + fetch(url, "GET", function() { + indicator.href = url.replace(/^https:/, "http:"); + indicator.removeAttribute("id"); + indicator.dataset.update = "refresh"; + console.log("INFO: R: " + remote); + console.log("INFO: L: " + local); + console.log("INFO: D: " + drift); + console.log("INFO: M: " + modified); + }); } }); } |