-
Notifications
You must be signed in to change notification settings - Fork 189
/
Copy pathspace_nextpage.uc.js
77 lines (68 loc) · 2.3 KB
/
space_nextpage.uc.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
75
76
77
// ==UserScript==
// @name 空格键页面底部翻页(依次调用 uAutoPagerize、uSuper_preloader、nextPage.uc.xul)
// @description 默认设置小说阅读脚本启用后禁用
// @author [email protected]
// @include main
// ==/UserScript==
if(window.Space_nextpage){
window.Space_nextpage.uninit();
window.Space_nextpage = null;
}
window.Space_nextpage = {
init: function(){
gBrowser.mPanelContainer.addEventListener('keypress', this, false);
},
uninit: function(){
gBrowser.mPanelContainer.removeEventListener('keypress', this, false);
},
handleEvent: function(event){
switch(event.type){
case "keypress":
this.keypress(event);
break;
}
},
goToNextPage: function(win){
if (win.ap) {
let nextURL = win.ap.nextLink && win.ap.nextLink.href;
if (nextURL)
win.location = nextURL;
} else if (win.uSuper_preloader) {
win.uSuper_preloader.go();
} else if (window.nextPage) {
nextPage.next(true);
}
},
space: " ".charCodeAt(0),
keypress: function(event){
if (event.charCode != this.space)
return;
if (event.target.nodeName.match(/input|textarea|select/i))
return;
var
doc = event.target.ownerDocument,
win = doc.defaultView,
isFrame = (win.top != win)
;
if(!doc.body)
return;
// 鲜果阅读器防止出错
if(win.location.href.match(/xianguo\.com\/reader/i))
return;
// 有小说阅读脚本的逃过
if(doc.body.getAttribute("name") == "MyNovelReader")
return;
if(isFrame){
var clientHeight = doc.body.clientHeight;
var scrollTop = doc.body.scrollTop | doc.documentElement.scrollTop;
var windowHeight = doc.all ? doc.getElementsByTagName("html")[0].offsetHeight : win.innerHeight;
// 为什么 Firefox 下要加1?
if ((scrollTop + windowHeight + 1) >= clientHeight)
this.goToNextPage(win);
}else{
if(content.scrollMaxY <= content.scrollY)
this.goToNextPage(win);
}
}
};
window.Space_nextpage.init();