-
Notifications
You must be signed in to change notification settings - Fork 0
/
next_page.js
74 lines (66 loc) · 1.67 KB
/
next_page.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
69
70
71
72
73
74
function append( content ) {
var add = document.getElementById( 'content' );
add.innerHTML= add.innerHTML + content;
}
var ask_for = 'p=';
function next_page_scroll_hdl( event ) {
if( free_ajax && update && (window.scrollY + window.innerHeight >= 0.90 * document.body.offsetHeight) ) {
/* glue is defined in static.rb */
var url = next_page_url_base + glue + ask_for + next_page;
ajax_get( url );
};
}
function processData(data) {
json = JSON.parse( data );
append( json["content_as_html"] );
if( json["fin"] ) finished();
if( json["pairs"] ) do_pairs();
next_page = json["last_row"];
free_ajax = true;
next_page_scroll_hdl( null );
}
function handler() {
if(this.status == 200) {
processData(this.responseText);
} else {
alert("failed ajax");
}
}
var free_ajax = true;
function ajax_get( url ) {
if( free_ajax ) {
free_ajax = false;
window.setTimeout(function(){free_ajax = true;}, 1500);
var client = new XMLHttpRequest();
client.onload = handler;
client.open("GET", url);
client.send();
};
}
function finished() {
update = false;
append( " --- end of content --- " );
}
function do_pairs() {
update = true;
ask_for = 'pairs=';
next_page = 0;
append( " --- pairs --- <br/>" );
next_page_scroll_hdl( null );
}
function do_alt() {
update = true;
ask_for = 'alt&pairs=';
next_page = 0;
append( " --- alt pairs --- <br/>" );
next_page_scroll_hdl( null );
}
function do_fuzz() {
update = true;
ask_for = 'fuzz&p=';
next_page = 0;
append( " --- fuzz --- <br/>" );
next_page_scroll_hdl( null );
}
document.addEventListener( "scroll", next_page_scroll_hdl, false );
next_page_scroll_hdl( null );