diff options
author | tdro <tdro@noreply.example.com> | 2024-03-25 17:45:14 -0400 |
---|---|---|
committer | tdro <tdro@noreply.example.com> | 2024-03-25 17:45:14 -0400 |
commit | 54024746a810e1ab5b9e4c385d4b5a107e723585 (patch) | |
tree | dcf9d94992f4c0638ed89a1c0f3eac130f7abe87 | |
parent | f93da143714bb30385b92201ca47878c5eb3abdf (diff) | |
download | canory-54024746a810e1ab5b9e4c385d4b5a107e723585.tar.gz canory-54024746a810e1ab5b9e4c385d4b5a107e723585.tar.bz2 canory-54024746a810e1ab5b9e4c385d4b5a107e723585.zip |
static/js/update: Cover looping condition
-rw-r--r-- | assets/js/index.js | 13 | ||||
-rw-r--r-- | static/js/update.ts | 18 |
2 files changed, 31 insertions, 0 deletions
diff --git a/assets/js/index.js b/assets/js/index.js index dc0bc0c..aac9a66 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -94,6 +94,12 @@ }); })(); (function() { + const cookiesDisabled = !navigator.cookieEnabled; + if (cookiesDisabled) { + document.cookie = "disabled"; + document.cookie.indexOf("disabled"); + return console.warn("WARNING: Update check disabled due to cookie restrictions"); + } function fetch(url, method, callback) { const http = new XMLHttpRequest(); http.onreadystatechange = function() { @@ -107,6 +113,9 @@ http.send(); return http; } + const key = "config.update"; + let stamps = {}; + if (!sessionStorage[key + ".urls"]) sessionStorage[key + ".urls"] = JSON.stringify(stamps); function update() { const url = self.location.href.split("#")[0].split("?")[0]; const indicator = document.querySelector("a[data-update]"); @@ -118,6 +127,10 @@ const modified = Date.parse(remote || local) > Date.parse(local); const drift = Date.parse(remote || local) - Date.parse(local); if (drift < 10000) return; + stamps = JSON.parse(sessionStorage[key + ".urls"]); + if (stamps[url] === remote) return; + stamps[url] = remote; + sessionStorage[key + ".urls"] = JSON.stringify(stamps); if (remote && modified) { fetch(url, "GET", function() { indicator.href = url.replace(/^https:/, "http:"); diff --git a/static/js/update.ts b/static/js/update.ts index aa4ba77..df29f49 100644 --- a/static/js/update.ts +++ b/static/js/update.ts @@ -1,4 +1,13 @@ (function () { + + const cookiesDisabled = !navigator.cookieEnabled; + + if (cookiesDisabled) { + document.cookie = "disabled"; + document.cookie.indexOf("disabled"); + return console.warn("WARNING: Update check disabled due to cookie restrictions"); + } + function fetch(url, method, callback) { const http = new XMLHttpRequest(); http.onreadystatechange = function () { @@ -16,6 +25,10 @@ const state = "on"; const key = "config.update"; + let stamps = {}; + + if (!sessionStorage[key + ".urls"]) sessionStorage[key + ".urls"] = JSON.stringify(stamps); + function update() { const url = self.location.href.split("#")[0].split("?")[0]; @@ -37,6 +50,11 @@ indicator.dataset.update = anchor.dataset.update; } + stamps = JSON.parse(sessionStorage[key + ".urls"]); + if (stamps[url] === remote) return; + stamps[url] = remote; + sessionStorage[key + ".urls"] = JSON.stringify(stamps); + if (remote && modified) { fetch(url, "GET", function () { indicator.href = url.replace(/^https:/, "http:"); |