From 54024746a810e1ab5b9e4c385d4b5a107e723585 Mon Sep 17 00:00:00 2001 From: tdro Date: Mon, 25 Mar 2024 17:45:14 -0400 Subject: static/js/update: Cover looping condition --- static/js/update.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'static/js') 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:"); -- cgit v1.2.3