-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
50 lines (48 loc) · 1.67 KB
/
index.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
function GET(url, callback) {
var req = new XMLHttpRequest();
req.onreadystatechange = function() {
if(req.readyState === 4 && req.status === 200) {
callback(req.responseText);
}
};
req.open('GET', url);
req.send(null);
}
// Language strings
GET('lang.json', function(response) {
var strings = JSON.parse(response);
document.title = strings.sitename;
});
// Page content
var iframe = document.createElement('iframe');
var interval;
function updateVisibility() {
iframe.contentDocument.body.classList.toggle('inactive', document.hidden);
}
if('sandbox' in iframe) {
iframe.sandbox = 'allow-top-navigation allow-same-origin';
iframe.src = 'content' + (document.referrer && window.URL && new URL(document.referrer).origin === location.origin ? '#noanim' : '');
iframe.id = 'content';
iframe.addEventListener('load', function() {
Array.prototype.forEach.call(iframe.contentDocument.getElementsByClassName('needsfocus'), function(elm) {
elm.addEventListener('click', function() {});
});
updateVisibility();
document.addEventListener('visibilitychange', updateVisibility);
var wrap = iframe.contentDocument.getElementById('wrap');
interval = setInterval(function() {
if(iframe.contentWindow.pageYOffset || wrap.scrollTop) {
iframe.contentDocument.body.classList.add('scrolled');
clearInterval(interval);
if(iframe.contentDocument.querySelector(':target:not(a)')) {
wrap.style.webkitOverflowScrolling = 'auto';
wrap.addEventListener('animationend', function onanimationend() {
wrap.removeEventListener('animationend', onanimationend);
wrap.style.webkitOverflowScrolling = '';
});
}
}
}, 100);
});
document.body.appendChild(iframe);
}