forge
Explore
Log in

Don't you dare go Hollow

forge

Clone
★ 0

0 watching0 forksRustAGPL-3.07.1 MiB490f099Tahinli7 hours ago322 commits

offline.js28 lines, 1.1 KiBHistoryRawDownload
1// Offline page (served by the service worker when a page load finds the server down). Shows the
2// line in the browser's language, then reloads once the server answers again. Nothing else runs here.
3(function () {
4 'use strict';
5 var want = /^tr\b/i.test(navigator.language || '') ? 'tr' : 'en';
6 document.querySelectorAll('.link-offline [lang]').forEach(function (el) {
7 if (el.getAttribute('lang') !== want) { el.hidden = true; }
8 });
9
10 if (!window.EventSource) { return; }
11 // Opens the stream again after a drop. The browser retries by itself, except when a proxy answers
12 // with an error (EventSource then closes for good): that case is retried here, 1, 2, then 3 s.
13 function keepOpen(url, onOpen) {
14 var delay = 1000;
15 function connect() {
16 var es = new EventSource(url);
17 es.onopen = function () { delay = 1000; onOpen(); };
18 es.onerror = function () {
19 if (es.readyState !== EventSource.CLOSED) { return; }
20 es.close();
21 setTimeout(connect, delay);
22 delay = Math.min(delay + 1000, 3000);
23 };
24 }
25 connect();
26 }
27 keepOpen('/-/alive', function () { location.reload(); });
28})();