blob: aacfe8378b9d386e0ee8ca88dcbda6dad346bd8a (
plain)
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
|
/* Continuously scrolls the page
*/
(function(){
class Scroll {
constructor () {
this.scrolled = new Map ();
this.interval = window.setInterval (this.scroll.bind (this), 200);
}
stop() {
window.clearInterval (this.interval);
window.scrollTo (0, 0);
this.scrolled.forEach (function (value, key, map) {
key.scrollTop = value;
});
}
/* save initial scroll state */
save(obj) {
if (!this.scrolled.has (obj)) {
this.scrolled.set (obj, obj.scrollTop);
}
}
/* perform a single scroll step */
scroll (event) {
window.scrollBy (0, window.innerHeight/2);
document.querySelectorAll ('html body *').forEach (
function (d) {
if (d.scrollHeight-d.scrollTop > d.clientHeight) {
this.save (d);
d.scrollBy (0, d.clientHeight/2);
}
}.bind (this));
return true;
}
}
return new Scroll();
}())
|