From 242e7870c809e1a89cc00aa4caa8f6e0ca8f065f Mon Sep 17 00:00:00 2001 From: tdro Date: Sat, 8 Apr 2023 22:26:43 -0400 Subject: static/js/refresh: Hook into blur Keep it simple --- assets/css/default.css | 2 +- assets/js/index.js | 19 ++++++------------- 2 files changed, 7 insertions(+), 14 deletions(-) (limited to 'assets') diff --git a/assets/css/default.css b/assets/css/default.css index e5eaa16..2cd30b3 100644 --- a/assets/css/default.css +++ b/assets/css/default.css @@ -1386,7 +1386,7 @@ icon-button a[data-update="refresh"] small:nth-of-type(1) { icon-button a[data-update="refresh"] svg:nth-of-type(2), icon-button a[data-update="refresh"] small:nth-of-type(2) { - display: initial; + display: block; } icon-button a:hover { diff --git a/assets/js/index.js b/assets/js/index.js index 22c6cb7..87cb4b1 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -76,7 +76,7 @@ http.setRequestHeader("Cache-Control", "no-cache"); http.send(); } - function update(id) { + function update() { const url = self.location.href; check(url, "HEAD", function(request) { const local = document.querySelector('meta[name="last-modified"]').content; @@ -90,21 +90,14 @@ indicator.href = url; indicator.removeAttribute("id"); indicator.dataset.update = "refresh"; - clearInterval(id); + self.removeEventListener("blur", update); + console.log("R: " + remote); + console.log("L: " + local); + console.log("M: " + modified); } - console.log("R: " + remote); - console.log("L: " + local); - console.log("M: " + modified); }); } - self.addEventListener("load", function() { - let meta = document.querySelector('meta[name="refresh"]'); - if (meta) meta = document.querySelector('meta[name="refresh"]').content; - const interval = meta || 3600000; - const monitor = setInterval(function() { - if (navigator.onLine) update(monitor); - }, interval); - }); + self.addEventListener("blur", update); })(); (function() { const options = "targetWindow,width=700,height=500,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes"; -- cgit v1.2.3