aboutsummaryrefslogtreecommitdiff
path: root/assets/js/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'assets/js/index.js')
-rw-r--r--assets/js/index.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/assets/js/index.js b/assets/js/index.js
index cc61f84..67331da 100644
--- a/assets/js/index.js
+++ b/assets/js/index.js
@@ -64,6 +64,49 @@
});
})();
(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(id) {
+ const url = self.location.href;
+ 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";
+ clearInterval(id);
+ }
+ 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);
+ });
+})();
+(function() {
const options = "targetWindow,width=700,height=500,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes";
self.addEventListener("keydown", function(event) {
if (event.repeat && event.key === "d") {