forked from ywzhaiqi/userChromeJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uSuper_preloader.uc.js
3080 lines (2841 loc) · 120 KB
/
uSuper_preloader.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ==UserScript==
// @name uSuper_preloader.uc.js
// @author ywzhaiqi
// @namespace https://github.com/ywzhaiqi
// @include main
// @charset UTF-8
// @description 基于 NLF 的 Super_preloader 2.0.22,增加对 noscript 的支持,精简代码等。
// ==/UserScript==
(function (){
// super_preloader.db 存放的位置,相对路径,Chrome 目录下
var DB_FILE_NAME = "Local\\uSuper_preloader.db.js";
// 1 按钮, 2 菜单, 0 无
// 按钮ID: uSuper_preloader-icon
// 菜单ID: uSuper_preloader-menuitem, 可用 rebulid_userChrome 移动统一管理
var append_type = 1;
var APPEND_BUTTON = 1;
var APPEND_MENU_ITEM = 2;
var APPEND_NONE = 0;
var AUTO_START = true;
var DEBUG = false;
var BUTTON_IMG_ENABLE = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABVklEQVQ4jZWTzUoCURTHz6t0UkcyiUgdcvyYmgEDadGihRsXLSSjDypyHiFkWsxAQoJtkgpauDEybDFQUcH4AC2jlT2CFJ0WNXHndoX8w29x7vndAwfuBfiJbvTyeqV3rRluXzd6JEIz3L5WcTtze64CbNTth/353ScaBXXn0QAAgPTGbV7duqeR2bz7UNedGGTKzlVmzSEePiInXXbOQSl131KlG2IZFt5TSt1XmF3pEI8XRPzFq3kX5GKbeNgB7Dlfy8U2QbzQIh5RRF680CKYWb4gEaKIPJheOqNhsPt7K/EOTC2eEA8R/am9AbwLk7lGP7pwTCzDgog+L5prPENEr19G9DrxiC4jos+Z0I6aEM7YSSlb+wyrNeJh3wEi+vvZw4GkWBIAAASTdiWUst5DKZv+hWINgoq96vuRmKjGAgnzdFw2XwLyAYn47pnNsVhV8u59Afs2ShHG9IUdAAAAAElFTkSuQmCC";
var BUTTON_IMG_DISABLE = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABT0lEQVQ4jZWTz0sCURDH5295Fy/rzYO226EfoCAodczO1tVLHaJrKbjgJoWIddBCkkgIdVuQtgw7mFiB7UpepJP9CVI0Xdx4Tk/IL3wO8+bzBgbeAxjHst6Ctt2/tuz+0O71UcS4p3e7PRn4tDuv++2OhbPR3QYAgJvGU/D2/gVnxWw8f5lmxwNVo1WrGo9IoRE5FaNVhNJl86NUfkCeaaHeebn5Diend0hxwhj7xampC+lsHSn8AP6c1ulsHSGe0pEiisiLp3SE3b0rFCGKyIPYzgVOg9/fWYk6EI0VkYKIf2pnAHVhLZofRjbyyDMtjDEkbg9CkVwlvH6MFNFlxtiEE4rkCrAYPpxbWsl8L69mkMK/A8YY7Y8WQkcuAADw+rUtn1/79AUO8D94A9rI69c2J36kJCc8bkU9k5TkwD2voghJSQ4kWS245ITLufcDB6uwLE1qxtEAAAAASUVORK5CYII=";
if(window.uSuper_preloader){
window.uSuper_preloader.uninit();
window.uSuper_preloader = null;
}
let { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
if (!window.Services) Cu.import("resource://gre/modules/Services.jsm");
var ns = window.uSuper_preloader = {
icon: null,
db: null,
get prefs() {
delete this.prefs;
return this.prefs = Services.prefs.getBranch("uSuper_preloader.");
},
get DB_File() {
var aFile = Services.dirsvc.get('UChrm', Ci.nsILocalFile);
aFile.appendRelativePath(DB_FILE_NAME);
return aFile;
},
get AUTO_START() AUTO_START,
set AUTO_START(bool) {
let m = $("uSuper_preloader-AUTOSTART");
if (m) m.setAttribute("checked", AUTO_START = !!bool);
updateIcon();
return bool;
},
get DEBUG() DEBUG,
set DEBUG(bool) {
let m = $("uSuper_preloader-DEBUG");
if (m) m.setAttribute("checked", DEBUG = !!bool);
return bool;
},
init: function(){
this.load_DB();
if(!this.db)
return alerts("uSuper_preloader.db.js", "数据文件有错误");
// 设置初始时间
this.isModified();
gBrowser.mPanelContainer.addEventListener('DOMContentLoaded', this, true);
if(append_type != APPEND_NONE){
// addon-bar, nav-bar, urlbar-icons
this.addIconOrMenuitem('addon-bar');
window.addEventListener('unload', this, false);
["AUTO_START", "DEBUG"].forEach(function(name) {
try {
ns[name] = ns.prefs.getBoolPref(name);
} catch (e) {}
}, ns);
}
},
uninit: function(){
gBrowser.mPanelContainer.removeEventListener('DOMContentLoaded', this, true);
if(append_type != APPEND_NONE){
window.removeEventListener('unload', this, false);
["AUTO_START", "DEBUG"].forEach(function(name) {
try {
ns.prefs.setBoolPref(name, ns[name]);
} catch (e) {}
}, ns);
}
var ids = ["uSuper_preloader-icon", "uSuper_preloader-popup", "uSuper_preloader-menuitem"];
for (let [, id] in Iterator(ids)) {
let e = document.getElementById(id);
if (e) e.parentNode.removeChild(e);
}
},
handleEvent: function(event){
switch(event.type){
case "DOMContentLoaded":
if (this.AUTO_START){
var win = event.target.defaultView;
win.setTimeout(function(){
ns.launch(win);
}, 500)
}
break;
case "unload":
this.uninit(event);
break;
}
},
addIconOrMenuitem: function(appendBarId){
if(append_type == APPEND_NONE){
return;
}else if(append_type == APPEND_BUTTON){
ns.icon = $(appendBarId).appendChild($C("toolbarbutton", {
id: "uSuper_preloader-icon",
class: "toolbarbutton-1",
type: "context",
onclick: "if (event.button != 2) uSuper_preloader.iconClick(event);",
context: "uSuper_preloader-popup",
image: BUTTON_IMG_ENABLE
}));
}else if(append_type == APPEND_MENU_ITEM){
let ins = $("webDeveloperMenu");
let menuitem = $C("menuitem", {
id: "uSuper_preloader-menuitem",
label: "uSuper_preloader 开关",
class: "menuitem-iconic",
image: BUTTON_IMG_ENABLE
});
menuitem.addEventListener("click", function(event){
if(event.button == 0){
uSuper_preloader.iconClick(event);
}else if(event.button == 2){
event.preventDefault();
$("uSuper_preloader-popup").openPopup(
menuitem, "after_start", -1, -1, false, false);
}
}, false);
ns.icon = ins.parentNode.insertBefore(menuitem, ins);
}
var xml = '\
<menupopup id="uSuper_preloader-popup"\
position="after_start"\
onpopupshowing="if (this.triggerNode) this.triggerNode.setAttribute(\'open\', \'true\');"\
onpopuphiding="if (this.triggerNode) this.triggerNode.removeAttribute(\'open\');">\
<menuitem label="启用自动翻页"\
id="uSuper_preloader-AUTOSTART"\
type="checkbox"\
autoCheck="true"\
checked="'+ AUTO_START +'"\
oncommand="uSuper_preloader.toggle(event);"/>\
<menuitem label="调试模式"\
id="uSuper_preloader-DEBUG"\
type="checkbox"\
autoCheck="false"\
checked="'+ DEBUG +'"\
oncommand="uSuper_preloader.DEBUG = !uSuper_preloader.DEBUG;"/>\
<menuseparator/>\
<menuitem label="在线搜索翻页规则"\
id="uSuper_preloader-search"\
oncommand="uSuper_preloader.search()"/>\
</menupopup>\
';
var range = document.createRange();
range.selectNodeContents($('mainPopupSet'));
range.collapse(false);
range.insertNode(range.createContextualFragment(xml.replace(/\n|\t/g, '')));
range.detach();
},
iconClick: function(event){
if (!event || !event.button) {
ns.toggle();
}
},
toggle: function() {
if (ns.AUTO_START) {
ns.AUTO_START = false;
} else {
ns.AUTO_START = true;
if(!content.uSuper_preloader){
ns.launch(content);
}else{
if(content.uSuper_preloader.scroll)
content.uSuper_preloader.scroll();
}
}
updateIcon();
},
load_DB: function(isAlert){
var data = loadText(this.DB_File);
if (!data) return false;
var sandbox = new Cu.Sandbox( new XPCNativeWrapper(window) );
// 如果是原版,去除部分内容
data = data.replace("(function(){", "")
.replace(/浏览器检测\.开始\.[\s\S]+\.浏览器检测\.结束/, "")
.replace(/function xToString\(x\)\{\/\/任何转字符串[\s\S]+/, "");
try {
Cu.evalInSandbox(data, sandbox, '1.8');
} catch (e) {
alerts('uSuper_preloader.db 有错误', e);
return log('load error.', e);
}
this.db = sandbox.superPreloader;
//转成正则.
this.db.prePageKey = this.pageKeyToRE('previous', this.db.prePageKey, this.db);
this.db.nextPageKey = this.pageKeyToRE('next', this.db.nextPageKey, this.db);
if (isAlert)
alerts('uSuper_preloader.db', '载入成功');
return true;
},
_isModified_lastcheck: 0,
_modified: 0,
isModified: function() {
let aFile = this.DB_File;
if(!aFile.exists() || !aFile.isFile()){
return false;
}
let now = Date.now();
if (now - this._isModified_lastcheck < 1000) {
return false;
}
this._isModified_lastcheck = now;
let lmt = aFile.lastModifiedTime;
if (this._modified != lmt) {
this._modified = lmt;
return true;
}
return false;
},
launch: function(win){
if(!win) return;
var doc = win.document;
var locationHref = win.location.href;
if (locationHref.indexOf('http') !== 0)
return;
if (!/html|xml/i.test(doc.contentType) ||
doc.body instanceof HTMLFrameSetElement ||
doc.querySelector('meta[http-equiv="refresh"]'))
return;
if(win.name == "MyNovelReader" || doc.body.getAttribute("name") == 'MyNovelReader')
return;
// 监测文件是否更新
if(this.isModified()){
this.load_DB(true);
}
var timer = 0;
if(/\bgoogle\.com(\.hk)?$/.test(win.location.host)){
timer = 1000;
// TODO: 运行2次,有错误
// win.addEventListener("hashchange", function(event) {
// win.setTimeout(function(){
// win.console.log("Hashchanged", win.location.href);
// new Super_preloader(win, win.document, ns.db);
// }, timer);
// }, false);
}
win.setTimeout(function(){
new Super_preloader(win, win.document, ns.db);
}, timer);
},
search: function(){
// 如果焦点在 开发工具,则得到的地址错误
// var focusedWindow = ns.getFocusedWindow();
var focusedWindow = content;
var keyword = encodeURIComponent(focusedWindow.location.href);
// openLinkIn('http://ap.teesoft.info/?exp=0&url=' + keyword, 'tab', {});
gBrowser.selectedTab = gBrowser.addTab('http://ap.teesoft.info/?exp=0&url=' + keyword);
},
pageKeyToRE: function(name, pageKey, db) {
var pageKeyLength = pageKey.length;
function strMTE(str) {
return (str.replace(/\\/g, '\\\\')
.replace(/\+/g, '\\+')
.replace(/\./g, '\\.')
.replace(/\?/g, '\\?')
.replace(/\{/g, '\\{')
.replace(/\}/g, '\\}')
.replace(/\[/g, '\\[')
.replace(/\]/g, '\\]')
.replace(/\^/g, '\\^')
.replace(/\$/g, '\\$')
.replace(/\*/g, '\\*')
.replace(/\(/g, '\\(')
.replace(/\)/g, '\\)')
.replace(/\|/g, '\\|')
.replace(/\//g, '\\/'));
}
var pfwordl = db.autoMatch.pfwordl,
sfwordl = db.autoMatch.sfwordl;
var RE_enable_a = pfwordl[name].enable,
RE_maxPrefix = pfwordl[name].maxPrefix,
RE_character_a = pfwordl[name].character,
RE_enable_b = sfwordl[name].enable,
RE_maxSubfix = sfwordl[name].maxSubfix,
RE_character_b = sfwordl[name].character;
var plwords,
slwords,
rep;
plwords = RE_maxPrefix > 0 ? ('[' + (RE_enable_a ? strMTE(RE_character_a.join('')) : '.') + ']{0,' + RE_maxPrefix + '}') : '';
plwords = '^\\s*' + plwords;
//alert(plwords);
slwords = RE_maxSubfix > 0 ? ('[' + (RE_enable_b ? strMTE(RE_character_b.join('')) : '.') + ']{0,' + RE_maxSubfix + '}') : '';
slwords = slwords + '\\s*$';
//alert(slwords);
rep = db.prefs.cases ? '' : 'i';
for (var i = 0; i < pageKeyLength; i++) {
pageKey[i] = new RegExp(plwords + strMTE(pageKey[i]) + slwords, rep);
//alert(pageKey[i]);
};
return pageKey;
},
getFocusedWindow: function() {
var win = document.commandDispatcher.focusedWindow;
return (!win || win == window) ? content : win;
},
};
function Super_preloader(window, document, db){
this.init.apply(this, arguments);
}
Super_preloader.prototype = {
init: function(window, document, db){
this.win = window;
this.doc = document;
this.db = db;
this.run(window, document, db);
//修正一些网站的自动翻页..
this.siteFixd();
},
run: function(window, document, db){
var self = this;
//引用console对象的部分函数.
var C = {};
if(DEBUG){
C.log = window.console.log;
C.err = window.console.error;
}else{
C.log = function(){};
C.err = function(){};
}
//如果是取出下一页使用的iframe window
if (window.name == 'superpreloader-iframe') {
window.scroll(window.scrollX, 99999); //滚动到底部,针对,某些使用滚动事件加载图片的网站.
window.parent.postMessage('superpreloader-iframe:DOMLoaded', '*');
C.log("iframe 加载下一页", window.location.href);
return;
}
var startTime = new Date();
//从db取出数据.
var prefs = db.prefs,
sep_icons = db.sep_icons,
FWKG_color = db.FWKG_color,
blackList = db.blackList,
DIExclude = db.DIExclude,
SITEINFO_D = db.SITEINFO_D,
SITEINFO = db.SITEINFO,
SITEINFO_TP = db.SITEINFO_TP,
SITEINFO_comp = db.SITEINFO_comp,
autoMatch = db.autoMatch,
prePageKey = db.prePageKey,
nextPageKey = db.nextPageKey;
///////////
// db = null;
var nullFn = function() {}; //空函数.
var url = document.location.href.replace(/#.*$/, ''); //url 去掉hash
var cplink = url; //翻上来的最近的页面的url;
var domain = document.domain; //取得域名.
var domain_port = url.match(/https?:\/\/([^\/]+)/)[1]; //端口和域名,用来验证是否跨域.
//重要的变量两枚.
var nextlink;
var prelink;
//===============
//初始化..
C.log('----------------------------------------------------');
//悬浮窗
var floatWO = {
updateColor: nullFn,
loadedIcon: nullFn,
CmodeIcon: nullFn,
style: null,
div: null
};
function floatWindow() {
floatWO.style = self.addStyle(self.floatWindowStyle);
var div = document.createElement('div');
div.id = 'sp-fw-container';
div.innerHTML = self.floatWindowInnerHTML;
document.body.appendChild(div);
floatWO = div;
//id获取元素
function $(id) {
return document.getElementById(id);
}
var rect = $('sp-fw-rect'); //悬浮窗的小正方形,用颜色描述当前的状态.
var spanel = $('sp-fw-content'); //设置面板.
var spanelc = {
show: function() {
spanel.style.display = 'block';
},
hide: function() {
spanel.style.display = 'none';
},
};
var rectt1, rectt2;
//设置面板显隐
rect.addEventListener('mouseover', function(e) {
rectt1 = window.setTimeout(spanelc.show, 100);
}, false);
rect.addEventListener('mouseout', function(e) {
window.clearTimeout(rectt1);
}, false);
div.addEventListener('mouseover', function(e) {
// C.log('over:',e.target);
window.clearTimeout(rectt2);
}, false);
div.addEventListener('mouseout', function(e) {
//C.log('out:',e.target);
if (e.relatedTarget && e.relatedTarget.disabled) return; //for firefox and chrome
rectt2 = window.setTimeout(spanelc.hide, 288);
}, false);
var dot = $('sp-fw-dot'); //载入完成后,显示的小点
dot.style.backgroundColor = FWKG_color.dot;
var cur_mode = $('sp-fw-cur-mode'); //当载入状态时,用来描述当前是翻页模式,还是预读模式.
cur_mode.style.backgroundColor = SSS.a_enable ? FWKG_color.autopager : FWKG_color.prefetcher
var a_enable = $('sp-fw-a_enable'); //启用翻页模式
var autopager_field = $('sp-fw-autopager-field'); //翻页设置区域
//预读设置
var useiframe = $('sp-fw-useiframe');
var viewcontent = $('sp-fw-viewcontent');
//翻页设置
var a_useiframe = $('sp-fw-a_useiframe');
var a_iloaded = $('sp-fw-a_iloaded');
var a_itimeout = $('sp-fw-a_itimeout');
var a_manualA = $('sp-fw-a_manualA');
var a_remain = $('sp-fw-a_remain');
var a_maxpage = $('sp-fw-a_maxpage');
var a_separator = $('sp-fw-a_separator');
var a_ipages_0 = $('sp-fw-a_ipages_0');
var a_ipages_1 = $('sp-fw-a_ipages_1');
var a_force = $('sp-fw-a_force');
var a_starti = $('sp-fw-a_starti'); //开始立即翻页
a_starti.addEventListener('click', function() {
if (this.disabled) return;
var value = Number(a_ipages_1.value);
if (isNaN(value) || value <= 0) {
value = SSS.a_ipages[1];
a_ipages_1.value = value;
}
autoPO.startipages(value);
}, false);
//总开关
var enable = $('sp-fw-enable');
//保存设置按钮.
var savebutton = $('sp-fw-savebutton');
var saveButtonClicked = function(e) {
var value = {
Rurl: SSS.Rurl,
useiframe: gl(useiframe),
viewcontent: gl(viewcontent),
enable: gl(enable)
};
function gl(obj) {
return (obj.type == 'checkbox' ? obj.checked : obj.value);
}
if (SSS.a_enable !== undefined) {
value.a_enable = gl(a_enable);
value.a_useiframe = gl(a_useiframe);
value.a_iloaded = gl(a_iloaded);
value.a_manualA = gl(a_manualA);
value.a_force = gl(a_force);
var t_a_itimeout = Number(gl(a_itimeout));
value.a_itimeout = isNaN(t_a_itimeout) ? SSS.a_itimeout : (t_a_itimeout >= 0 ? t_a_itimeout : 0);
var t_a_remain = Number(gl(a_remain));
value.a_remain = isNaN(t_a_remain) ? SSS.a_remain : Number(t_a_remain.toFixed(2));
var t_a_maxpage = Number(gl(a_maxpage));
value.a_maxpage = isNaN(t_a_maxpage) ? SSS.a_maxpage : (t_a_maxpage >= 1 ? t_a_maxpage : 1);
var t_a_ipages_1 = Number(gl(a_ipages_1));
value.a_ipages = [gl(a_ipages_0), (isNaN(t_a_ipages_1) ? SSS.a_ipages[1] : (t_a_ipages_1 >= 1 ? t_a_ipages_1 : 1))];
value.a_separator = gl(a_separator);
}
// alert(xToString(value));
SSS.savedValue[SSS.sedValueIndex] = value;
saveValue('spfwset', xToString(SSS.savedValue));
if ((e.shiftKey ? !prefs.FW_RAS : prefs.FW_RAS)) { //按住shift键,执行反向操作.
window.setTimeout(function(){
window.location.reload();
// loadValueAndRun();
}, 1);
}
};
savebutton.addEventListener('click', saveButtonClicked, false);
function ll(obj, value) {
if (obj.type == 'checkbox') {
obj.checked = value;
} else {
obj.value = value;
}
}
//载入翻页设置.
if (SSS.a_enable === undefined) { //未定义翻页功能.
a_enable.disabled = true;
autopager_field.style.display = 'none';
} else {
ll(a_enable, SSS.a_enable);
ll(a_useiframe, SSS.a_useiframe);
ll(a_iloaded, SSS.a_iloaded);
ll(a_itimeout, SSS.a_itimeout);
ll(a_manualA, SSS.a_manualA);
ll(a_force, SSS.a_force);
ll(a_remain, SSS.a_remain);
ll(a_maxpage, SSS.a_maxpage);
ll(a_separator, SSS.a_separator);
ll(a_ipages_0, SSS.a_ipages[0]);
ll(a_ipages_1, SSS.a_ipages[1]);
}
if (!SSS.a_enable) { //当前不是翻页模式,禁用立即翻页按钮.
a_starti.disabled = true;
}
if (!SSS.hasRule) { //如果没有高级规则,那么此项不允许操作.
a_force.disabled = true;
}
//载入预读设置.
ll(useiframe, SSS.useiframe);
ll(viewcontent, SSS.viewcontent);
//总开关
ll(enable, SSS.enable);
floatWO = {
updateColor: function(state) {
rect.style.backgroundColor = FWKG_color[state];
},
loadedIcon: function(command) {
dot.style.display = command == 'show' ? 'block' : 'none'
},
CmodeIcon: function(command) {
cur_mode.style.display = command == 'show' ? 'block' : 'none'
},
};
var vertical = parseInt(prefs.FW_offset[0], 10);
var horiz = parseInt(prefs.FW_offset[1], 10);
var FW_position = prefs.FW_position;
function gss() {
var scrolly = window.scrollY;
var scrollx = window.scrollX;
switch (FW_position) {
case 1:
div.style.top = vertical + scrolly + 'px';
div.style.left = horiz + scrollx + 'px';
break;
case 2:
div.style.top = vertical + scrolly + 'px';
div.style.right = horiz - scrollx + 'px';
break;
case 3:
div.style.bottom = vertical - scrolly + 'px';
div.style.right = horiz - scrollx + 'px';
break;
case 4:
div.style.bottom = vertical - scrolly + 'px';
div.style.left = horiz + scrollx + 'px';
break;
default:
break;
}
}
//非opera用fixed定位.
div.style.position = 'fixed';
switch (FW_position) {
case 1:
div.style.top = vertical + 'px';
div.style.left = horiz + 'px';
break;
case 2:
div.style.top = vertical + 'px';
div.style.right = horiz + 'px';
break;
case 3:
div.style.bottom = vertical + 'px';
div.style.right = horiz + 'px';
break;
case 4:
div.style.bottom = vertical + 'px';
div.style.left = horiz + 'px';
break;
default:
break;
}
}
var Tween = self.Tween,
TweenM = self.TweenM,
TweenEase = self.TweenEase;
function sp_transition(start, end) {
var TweenF = sp_transition.TweenF;
if (!TweenF) {
TweenF = Tween[TweenM[prefs.s_method]];
TweenF = TweenF[TweenEase[prefs.s_ease]] || TweenF;
sp_transition.TweenF = TweenF;
}
var frameSpeed = 1000 / prefs.s_FPS;
var t = 0; //次数,开始
var b = start; //开始
var c = end - start; //结束
var d = Math.ceil(prefs.s_duration / frameSpeed); //次数,结束
//alert(d);
//alert(c);
var x = window.scrollX;
function transition() {
var y = Math.ceil(TweenF(t, b, c, d));
//alert(y);
window.scroll(x, y);
if (t < d) {
t++;
window.setTimeout(transition, frameSpeed);
}
}
transition();
}
function scrollIt(a, b) {
//a=a!==undefined? a : window.scrollY;
prefs.sepT ? sp_transition(a, b) : window.scroll(window.scrollX, b);
}
function sepHandler(e) {
e.stopPropagation();
var div = this;
var target = e.target;
//alert(div);
function getRelativeDiv(which) {
var id = div.id;
id = id.replace(/(sp-separator-)(.+)/, function(a, b, c) {
return b + String((Number(c) + (which == 'pre' ? -1 : 1)));
});
//alert(id);
return (id ? document.getElementById(id) : null);
}
var o_scrollY, divS;
switch (target.className) {
case 'sp-sp-gotop':
scrollIt(window.scrollY, 0);
break;
case 'sp-sp-gopre':
var prediv = getRelativeDiv('pre');
if (!prediv) return;
o_scrollY = window.scrollY;
var preDS = prediv.getBoundingClientRect().top;
if (prefs.sepP) {
divS = div.getBoundingClientRect().top;
preDS = o_scrollY - (divS - preDS);
} else {
preDS += o_scrollY - 6;
}
scrollIt(o_scrollY, preDS);
break;
case 'sp-sp-gonext':
var nextdiv = getRelativeDiv('next');
if (!nextdiv) return;
o_scrollY = window.scrollY;
var nextDS = nextdiv.getBoundingClientRect().top;
if (prefs.sepP) {
divS = div.getBoundingClientRect().top;
nextDS = o_scrollY + (-divS + nextDS);
} else {
nextDS += o_scrollY - 6;
}
scrollIt(o_scrollY, nextDS);
break;
case 'sp-sp-gobottom':
scrollIt(window.scrollY, Math.max(document.documentElement.scrollHeight, document.body.scrollHeight));
break;
default:
break;
}
}
//autopager
var autoPO = {
startipages: nullFn
};
function autopager(SSS, floatWO) {
//return;
//更新悬浮窗的颜色.
floatWO.updateColor('autopager');
//获取插入位置节点.
var insertPoint;
var pageElement;
var insertMode;
if (SSS.a_HT_insert) {
insertPoint = getElement(SSS.a_HT_insert[0]);
insertMode = SSS.a_HT_insert[1];
} else {
pageElement = getAllElements(SSS.a_pageElement);
if (pageElement.length > 0) {
var pELast = pageElement[pageElement.length - 1];
insertPoint = pELast.nextSibling ? pELast.nextSibling : pELast.parentNode.appendChild(document.createTextNode(' '));
}
}
if (insertPoint) {
C.log('验证是否能找到插入位置节点:成功,', insertPoint);
} else {
C.err('验证是否能找到插入位置节点:失败', (SSS.a_HT_insert ? SSS.a_HT_insert[0] : ''), 'JS执行终止');
floatWO.updateColor('Astop');
return;
}
if (pageElement === undefined) {
pageElement = getAllElements(SSS.a_pageElement);
}
if (pageElement.length > 0) {
C.log('验证是否能找到主要元素:成功,', pageElement);
} else {
C.err('验证是否能找到主要元素:失败,', SSS.a_pageElement, 'JS执行终止');
floatWO.updateColor('Astop');
return;
}
var insertPointP;
if (insertMode != 2) {
insertPointP = insertPoint.parentNode;
}
var addIntoDoc;
if (insertMode == 2) {
addIntoDoc = function(obj) {
insertPoint.appendChild(obj);
};
} else {
addIntoDoc = function(obj) {
insertPointP.insertBefore(obj, insertPoint);
};
}
var doc, win;
function XHRLoaded(req) {
var str = req.responseText;
doc = win = createDocumentByString(str);
if (!doc) {
C.err('文档对象创建失败');
removeL();
return;
}
floatWO.updateColor('autopager');
floatWO.CmodeIcon('hide');
floatWO.loadedIcon('show');
working = false;
scroll();
}
var remove = [];
function removeL() {
C.log('移除各种事件监听');
floatWO.updateColor('Astop');
var _remove = remove;
for (var i = 0, ii = _remove.length; i < ii; i++) {
_remove[i]();
}
}
var iframe;
var messageR;
var cdomloadedc = nullFn;
function iframeLoaded() {
var iframe = this;
//alert(this.contentDocument.body)
//alert(iframe.contentDocument.body.innerHTML);
var body = iframe.contentDocument.body;
if (body && body.firstChild) {
window.setTimeout(function() {
doc = iframe.contentDocument;
win = iframe.contentWindow || doc;
floatWO.updateColor('autopager');
floatWO.CmodeIcon('hide');
floatWO.loadedIcon('show');
working = false;
scroll();
}, SSS.a_itimeout);
}
}
function iframeRquest(link) {
if (!iframe) {
var i = document.createElement('iframe');
iframe = i;
i.name = 'superpreloader-iframe';
i.width = '100%';
i.height = '0';
i.frameBorder = "0";
i.style.cssText = '\
margin:0!important;\
padding:0!important;\
visibility:hidden!important;\
';
i.src = link;
if (SSS.a_iloaded) {
i.addEventListener('load', iframeLoaded, false);
remove.push(function() {
i.removeEventListener('load', iframeLoaded, false)
});
} else {
function messagehandler(e) {
if (!messageR && e.data == 'superpreloader-iframe:DOMLoaded') {
//alert(e.source);
messageR = true;
iframeLoaded.call(i);
}
}
window.addEventListener('message', messagehandler, false);
remove.push(function() {
window.removeEventListener('message', messagehandler, false);
});
};
document.body.appendChild(i);
C.log("创建 iframe 成功");
cdomloadedc();
} else {
messageR = false;
iframe.contentDocument.location.replace(link);
cdomloadedc();
};
}
var working;
function doRequest() {
working = true;
floatWO.updateColor('loading');
floatWO.CmodeIcon('show');
SSS.a_useiframe ? iframeRquest(nextlink) : self.xmlhttpRequest(nextlink, XHRLoaded);
}
var ipagesmode = SSS.a_ipages[0];
var ipagesnumber = SSS.a_ipages[1];
var scrollDo = nullFn;
var afterInsertDo = nullFn;
if (prefs.Aplus) {
afterInsertDo = doRequest;
doRequest();
} else {
scrollDo = doRequest;
if (ipagesmode) doRequest();
}
var manualDiv;
function manualAdiv() {
if (!manualDiv) {
self.addStyle(self.manualAdiv_style);
var div = document.createElement('div');
div.id = 'sp-sp-manualdiv';
manualDiv = div;
var span = document.createElement('span');
span.textContent = '下';
span.className = 'sp-sp-md-span'
div.appendChild(span);
var input = document.createElement('input');
input.type = 'number';
input.value = 1;
input.min = 1;
input.title = "输入你想要拼接的页数(必须>=1),然后按回车."
input.id = 'sp-sp-md-number';
function getInputValue() {
var value = Number(input.value);
if (isNaN(value) || value < 1) {
value = 1;
input.value = 1;
};
return value;
};
function spage() {
if (doc) {
var value = getInputValue();
//alert(value);
ipagesmode = true;
ipagesnumber = value + paged;
insertedIntoDoc();
};
};
input.addEventListener('keyup', function(e) {
//alert(e.keyCode);
if (e.keyCode == 13) { //回车
spage();
};
}, false);
div.appendChild(input);
var span2 = document.createElement('span');
span2.textContent = '页';
span2.className = 'sp-sp-md-span'
div.appendChild(span2);
var img = document.createElement('img');
img.id = 'sp-sp-md-imgnext';
img.src = _sep_icons.next;
div.appendChild(img);
var span_info = document.createElement('span');
span_info.id = 'sp-sp-md-someinfo';
span_info.textContent = prefs.someValue;
div.appendChild(span_info);
document.body.appendChild(div);
div.addEventListener('click', function(e) {
if (e.target.id == 'sp-sp-md-number') return;
spage();
}, false);
};
addIntoDoc(manualDiv);
manualDiv.style.display = 'block';