forked from vector-of-bool/vector-of-bool.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare.js
68 lines (63 loc) · 1.8 KB
/
prepare.js
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
Polymer = {
lazyRegister: true
};
function revealComments() {
var el = document.getElementById('comments-container');
const but = el.querySelector('.comments-reveal-button');
if (but) {
el.removeChild(but);
}
const tmpl = document.getElementById('disqus-tmpl');
if (tmpl) {
const clone = document.importNode(tmpl.content, true);
el.appendChild(clone);
}
}
(function() {
const haveWebComponents =
('registerElement' in document &&
'import' in document.createElement('link') &&
'content' in document.createElement('template'));
if (!haveWebComponents) {
const script = document.createElement('script');
script.defer = true;
script.async = true;
script.src = '/bower_components/webcomponentsjs/webcomponents-lite.min.js';
document.head.appendChild(script);
}
const link = document.createElement('link');
link.rel = 'import';
link.href = '/bower_components/polymer/polymer.html';
link.onload = function() {
const link = document.createElement('link');
link.rel = 'import';
link.href = 'elements.html';
link.async = true;
document.head.appendChild(link);
};
document.head.appendChild(link);
})();
setTimeout(() => {
const req = fetch('network-test.html');
const timer =
new Promise(resolve => { setInterval(() => resolve('timeout'), 3000); });
function showOffline() {
document.getElementById('toast').show({
text: 'Unable to connect. Browsing offline.',
duration: 5000,
});
document.body.classList.remove('online');
};
Promise.race([req, timer])
.then(res => {
if (res === 'timeout') {
showOffline();
} else {
console.log(res);
}
})
.catch(exc => {
console.error('Request failed', exc);
showOffline();
});
}, 3000);