| 1 | |
| 2 | |
| 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 | |
| 12 | |
| 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 | })(); |