-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoffline.html
More file actions
87 lines (84 loc) · 3.14 KB
/
offline.html
File metadata and controls
87 lines (84 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="robots" content="noindex" />
<title>Offline — Archive Film Club</title>
<style>
html, body { margin: 0; padding: 0; background: #0a0a0b; color: #eee;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
min-height: 100vh; }
main { min-height: 100vh; display: flex; align-items: center; justify-content: center;
padding: 2rem 1rem; text-align: center; }
.card { max-width: 32rem; }
h1 { font-size: 1.6rem; margin: 0 0 .5rem; }
p { color: #8a8a92; margin: 0 0 1.25rem; line-height: 1.55; }
button { padding: .7em 1.3em; border-radius: 6px; border: 0;
background: #ff0000; color: #fff; font-weight: 500; cursor: pointer;
font: inherit; }
button:hover { background: #cc0000; }
button[disabled] { opacity: .6; cursor: progress; }
.icon { font-size: 3rem; margin-bottom: 1rem; opacity: .8; }
.status { margin-top: 1.25rem; font-size: .85rem; color: #5a5a64; }
</style>
</head>
<body>
<main>
<div class="card">
<div class="icon" aria-hidden="true">📡</div>
<h1>You’re offline.</h1>
<p>It looks like your device isn’t connected to the internet right now. Pages you’ve already visited may still work — try going back to a previous page.</p>
<button id="retry" type="button">Try again</button>
<p class="status" id="status" hidden>Checking for connection…</p>
</div>
</main>
<script>
// Auto-recover. The SW serves this page when a fetch fails, but the
// actual cause is often transient (sleep/wake, captive portal, VPN
// reconnect). Probe every 5 seconds — and on the browser's `online`
// event — and reload as soon as we can reach the API.
(function () {
var retryBtn = document.getElementById('retry');
var status = document.getElementById('status');
var inflight = false;
function setBusy(busy, msg) {
inflight = busy;
retryBtn.disabled = busy;
if (msg) {
status.hidden = false;
status.textContent = msg;
} else {
status.hidden = true;
}
}
function probe() {
if (inflight) return;
setBusy(true, 'Checking for connection…');
var ctl = new AbortController();
var t = setTimeout(function () { ctl.abort(); }, 4000);
fetch('api/index.php', {
method: 'HEAD',
cache: 'no-store',
signal: ctl.signal,
}).then(function (res) {
clearTimeout(t);
if (res && (res.ok || res.status < 500)) {
setBusy(false, 'Back online — reloading…');
window.location.reload();
return;
}
setBusy(false);
}).catch(function () {
clearTimeout(t);
setBusy(false);
});
}
retryBtn.addEventListener('click', probe);
window.addEventListener('online', probe);
window.addEventListener('focus', probe);
setInterval(probe, 5000);
})();
</script>
</body>
</html>