aboutsummaryrefslogtreecommitdiff
path: root/assets
diff options
context:
space:
mode:
authortdro <tdro@noreply.example.com>2024-01-13 20:33:21 -0500
committertdro <tdro@noreply.example.com>2024-01-13 20:33:21 -0500
commit8b53662def693a97ee5e0b5697841cf7859b6704 (patch)
tree91404ed8b418b5fd7eaf72eebc1e89549faaef9c /assets
parent30d33a9eedca8ae4b2e6082b915579c309f8b52c (diff)
downloadcanory-8b53662def693a97ee5e0b5697841cf7859b6704.tar.gz
canory-8b53662def693a97ee5e0b5697841cf7859b6704.tar.bz2
canory-8b53662def693a97ee5e0b5697841cf7859b6704.zip
static/js/update: Handle no drift
Some browsers can't read headers. Prepare _self and add reset state
Diffstat (limited to 'assets')
-rw-r--r--assets/js/index.js10
1 files changed, 6 insertions, 4 deletions
diff --git a/assets/js/index.js b/assets/js/index.js
index 83d3943..ef35f63 100644
--- a/assets/js/index.js
+++ b/assets/js/index.js
@@ -93,7 +93,7 @@
});
})();
(function() {
- function check(url, method, callback) {
+ function fetch(url, method, callback) {
const http = new XMLHttpRequest();
http.onreadystatechange = function() {
if (http.readyState === 4 && http.status === 200) {
@@ -108,14 +108,16 @@
}
function update() {
const url = self.location.href.split("#")[0].split("?")[0];
- check(url, "HEAD", function(request) {
+ fetch(url, "HEAD", function(request) {
const local = document.querySelector('meta[name="last-modified"]').content;
const remote = request.getResponseHeader("last-modified") || '';
const modified = Date.parse(document.lastModified) !== Date.parse(remote);
const drift = Date.parse(remote || local) - Date.parse(local);
+ let indicator = document.querySelector("a[data-update]");
+ indicator.cloneNode();
+ if (drift === 0) return;
if (remote && modified) {
- const indicator = document.querySelector("a[data-update]");
- check(url, "GET");
+ fetch(url, "GET");
indicator.href = url;
indicator.removeAttribute("id");
indicator.dataset.update = "refresh";