forked from hoothin/UserScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DownloadAllContent.user.js
2112 lines (2051 loc) · 95.4 KB
/
DownloadAllContent.user.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 DownloadAllContent
// @name:zh-CN 怠惰小说下载器
// @name:zh-TW 怠惰小説下載器
// @name:ja 怠惰者小説ダウンロードツール
// @namespace hoothin
// @version 2.8.3.6
// @description Lightweight web scraping script. Fetch and download main textual content from the current page, provide special support for novels
// @description:zh-CN 通用网站内容爬虫抓取工具,可批量抓取任意站点的小说、论坛内容等并保存为TXT文档
// @description:zh-TW 通用網站內容爬蟲抓取工具,可批量抓取任意站點的小說、論壇內容等並保存為TXT文檔
// @description:ja 軽量なWebスクレイピングスクリプト。ユニバーサルサイトコンテンツクロールツール、クロール、フォーラム内容など
// @author hoothin
// @match http://*/*
// @match https://*/*
// @match ftp://*/*
// @grant GM_xmlhttpRequest
// @grant GM_registerMenuCommand
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_openInTab
// @grant GM_setClipboard
// @grant GM_addStyle
// @grant unsafeWindow
// @license MIT License
// @compatible chrome
// @compatible firefox
// @compatible opera 未测试
// @compatible safari 未测试
// @contributionURL https://ko-fi.com/hoothin
// @contributionAmount 1
// ==/UserScript==
if (window.top != window.self) {
try {
if (window.self.innerWidth < 250 || window.self.innerHeight < 250) {
return;
}
} catch(e) {
return;
}
}
(function (global, factory) {
if (typeof define === "function" && define.amd) {
define([], factory);
} else if (typeof exports !== "undefined") {
factory();
} else {
var mod = {
exports: {}
};
factory();
global.FileSaver = mod.exports;
}
})(this, function () {
"use strict";
/*
* FileSaver.js
* A saveAs() FileSaver implementation.
*
* By Eli Grey, http://eligrey.com
*
* License : https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md (MIT)
* source : http://purl.eligrey.com/github/FileSaver.js
*/
var _global = typeof window === 'object' && window.window === window ? window : typeof self === 'object' && self.self === self ? self : typeof global === 'object' && global.global === global ? global : void 0;
function bom(blob, opts) {
if (typeof opts === 'undefined') opts = {
autoBom: false
};else if (typeof opts !== 'object') {
console.warn('Deprecated: Expected third argument to be a object');
opts = {
autoBom: !opts
};
}
if (opts.autoBom && /^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) {
return new Blob([String.fromCharCode(0xFEFF), blob], {
type: blob.type
});
}
return blob;
}
function download(url, name, opts) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.responseType = 'blob';
xhr.onload = function () {
saveAs(xhr.response, name, opts);
};
xhr.onerror = function () {
console.error('could not download file');
};
xhr.send();
}
function corsEnabled(url) {
var xhr = new XMLHttpRequest();
xhr.open('HEAD', url, false);
try {
xhr.send();
} catch (e) {}
return xhr.status >= 200 && xhr.status <= 299;
}
function click(node) {
try {
node.dispatchEvent(new MouseEvent('click'));
} catch (e) {
var evt = document.createEvent('MouseEvents');
evt.initMouseEvent('click', true, true, window, 0, 0, 0, 80, 20, false, false, false, false, 0, null);
node.dispatchEvent(evt);
}
}
var isMacOSWebView = _global.navigator && /Macintosh/.test(navigator.userAgent) && /AppleWebKit/.test(navigator.userAgent) && !/Safari/.test(navigator.userAgent);
var saveAs = _global.saveAs || (
typeof window !== 'object' || window !== _global ? function saveAs() {}
: 'download' in HTMLAnchorElement.prototype && !isMacOSWebView ? function saveAs(blob, name, opts) {
var URL = _global.URL || _global.webkitURL;
var a = document.createElement('a');
name = name || blob.name || 'download';
a.download = name;
a.rel = 'noopener';
if (typeof blob === 'string') {
a.href = blob;
if (a.origin !== location.origin) {
corsEnabled(a.href) ? download(blob, name, opts) : click(a, a.target = '_blank');
} else {
click(a);
}
} else {
a.href = URL.createObjectURL(blob);
setTimeout(function () {
URL.revokeObjectURL(a.href);
}, 4E4);
setTimeout(function () {
click(a);
}, 0);
}
}
: 'msSaveOrOpenBlob' in navigator ? function saveAs(blob, name, opts) {
name = name || blob.name || 'download';
if (typeof blob === 'string') {
if (corsEnabled(blob)) {
download(blob, name, opts);
} else {
var a = document.createElement('a');
a.href = blob;
a.target = '_blank';
setTimeout(function () {
click(a);
});
}
} else {
navigator.msSaveOrOpenBlob(bom(blob, opts), name);
}
}
: function saveAs(blob, name, opts, popup) {
popup = popup || open('', '_blank');
if (popup) {
popup.document.title = popup.document.body.innerText = 'downloading...';
}
if (typeof blob === 'string') return download(blob, name, opts);
var force = blob.type === 'application/octet-stream';
var isSafari = /constructor/i.test(_global.HTMLElement) || _global.safari;
var isChromeIOS = /CriOS\/[\d]+/.test(navigator.userAgent);
if ((isChromeIOS || force && isSafari || isMacOSWebView) && typeof FileReader !== 'undefined') {
var reader = new FileReader();
reader.onloadend = function () {
var url = reader.result;
url = isChromeIOS ? url : url.replace(/^data:[^;]*;/, 'data:attachment/file;');
if (popup) popup.location.href = url;else location = url;
popup = null;
};
reader.readAsDataURL(blob);
} else {
var URL = _global.URL || _global.webkitURL;
var url = URL.createObjectURL(blob);
if (popup) popup.location = url;else location.href = url;
popup = null;
setTimeout(function () {
URL.revokeObjectURL(url);
}, 4E4);
}
});
_global.saveAs = saveAs.saveAs = saveAs;
if (typeof module !== 'undefined') {
module.exports = saveAs;
}
});
(function() {
'use strict';
var indexReg=/^(\w.*)?PART\b|^Prologue|^(\w.*)?Chapter\s*[\-_]?\d+|分卷|^序$|^序\s*[·言章]|^前\s*言|^附\s*[录錄]|^引\s*[言子]|^摘\s*要|^[楔契]\s*子|^后\s*记|^後\s*記|^附\s*言|^结\s*语|^結\s*語|^尾\s*[声聲]|^最終話|^最终话|^番\s*外|^\d+[\s\.、,,)\-_::][^\d#\.]|^(\d|\s|\.)*[第(]?\s*[\d〇零一二两三四五六七八九十百千万萬-]+\s*[、)章节節回卷折篇幕集话話]/i;
var innerNextPage=/^\s*(下一[页頁张張]|next\s*page|次のページ)/i;
var lang = navigator.appName=="Netscape"?navigator.language:navigator.userLanguage;
var i18n={};
var rCats=[];
var processFunc, nextPageFunc;
const AsyncFunction = Object.getPrototypeOf(async function(){}).constructor;
var win=(typeof unsafeWindow=='undefined'? window : unsafeWindow);
switch (lang){
case "zh-CN":
case "zh-SG":
i18n={
fetch:"开始下载小说",
info:"来源:#t#\n本文是使用怠惰小说下载器(DownloadAllContent)下载的",
error:"该段内容获取失败",
downloading:"已下载完成 %s 段,剩余 %s 段<br>正在下载 %s",
complete:"已全部下载完成,共 %s 段",
del:"设置文本干扰码的CSS选择器",
custom:"自定规则下载",
customInfo:"输入网址或者章节CSS选择器",
reSort:"按标题名重新排序章节",
reSortUrl:"按网址重新排序章节",
setting:"选项参数设置",
searchRule:"搜索网站规则",
abort:"跳过此章",
save:"保存当前",
saveAsMd:"存为 Markdown",
downThreadNum:"设置同时下载的线程数",
customTitle:"自定义章节标题,输入内页文字对应选择器",
reSortDefault:"默认按页面中位置排序章节",
reverseOrder:"反转章节排序",
saveBtn:"保存设置",
saveOk:"保存成功",
nextPage:"嗅探章节内分页",
nextPageReg:"自定义分页正则",
retainImage:"保留正文中图片的网址",
minTxtLength:"当检测到的正文字数小于此数,则尝试重新抓取",
showFilterList:"下载前显示章节筛选排序窗口",
ok:"确定",
close:"关闭",
dacSortByPos:"按页内位置排序",
dacSortByUrl:"按网址排序",
dacSortByName:"按章节名排序",
reverse:"反选",
dacUseIframe:"使用 iframe 后台加载内容(慢速)",
dacSaveAsZip:"下载为 zip",
dacSetCustomRule:"修改规则",
dacAddUrl:"添加章节",
dacStartDownload:"下载选中",
downloadShortcut:"下载章节",
downloadSingleShortcut:"下载单页",
downloadCustomShortcut:"自定义下载"
};
break;
case "zh":
case "zh-TW":
case "zh-HK":
i18n={
fetch:"開始下載小說",
info:"來源:#t#\n本文是使用怠惰小說下載器(DownloadAllContent)下載的",
error:"該段內容獲取失敗",
downloading:"已下載完成 %s 段,剩餘 %s 段<br>正在下載 %s",
complete:"已全部下載完成,共 %s 段",
del:"設置文本干擾碼的CSS選擇器",
custom:"自訂規則下載",
customInfo:"輸入網址或者章節CSS選擇器",
reSort:"按標題名重新排序章節",
reSortUrl:"按網址重新排序章節",
setting:"選項參數設定",
searchRule:"搜尋網站規則",
abort:"跳過此章",
save:"保存當前",
saveAsMd:"存爲 Markdown",
downThreadNum:"設置同時下載的綫程數",
customTitle:"自訂章節標題,輸入內頁文字對應選擇器",
reSortDefault:"預設依頁面中位置排序章節",
reverseOrder:"反轉章節排序",
saveBtn:"儲存設定",
saveOk:"儲存成功",
nextPage:"嗅探章節內分頁",
nextPageReg:"自訂分頁正規",
retainImage:"保留內文圖片的網址",
minTxtLength:"當偵測到的正文字數小於此數,則嘗試重新抓取",
showFilterList:"下載前顯示章節篩選排序視窗",
ok:"確定",
close:"關閉",
dacSortByPos:"依頁內位置排序",
dacSortByUrl:"依網址排序",
dacSortByName:"依章節名排序",
reverse:"反選",
dacUseIframe:"使用 iframe 背景載入內容(慢速)",
dacSaveAsZip:"下載為 zip",
dacSetCustomRule:"修改規則",
dacAddUrl:"新增章節",
dacStartDownload:"下載選取",
downloadShortcut:"下載章節",
downloadSingleShortcut:"下載單頁",
downloadCustomShortcut:"自設下載"
};
break;
case "ar":
case "ar-AE":
case "ar-BH":
case "ar-DZ":
case "ar-EG":
case "ar-IQ":
case "ar-JO":
case "ar-KW":
case "ar-LB":
case "ar-LY":
case "ar-MA":
case "ar-OM":
case "ar-QA":
case "ar-SA":
case "ar-SY":
case "ar-TN":
case "ar-YE":
i18n={
fetch: "تحميل",
info: "المصدر: #t#\nتم تنزيل الـ TXT بواسطة 'DownloadAllContent'",
error: "فشل في تحميل الفصل الحالي",
downloading: "......%s تحميل<br>صفحات متبقية %s صفحات تم تحميلها، هناك %s",
complete: "صفحات في المجموع %s اكتمل! حصلت على",
del: "لتجاهل CSS تعيين محددات",
custom: "تحميل مخصص",
customInfo: "لروابط الفصول sss إدخال الروابط أو محددات",
reSort: "إعادة الترتيب حسب العنوان",
reSortUrl: "إعادة الترتيب حسب الروابط",
setting: "فتح الإعدادات",
searchRule: "قاعدة البحث",
abort: "إيقاف",
save: "حفظ",
saveAsMd: "Markdown حفظ كـ",
downThreadNum: "تعيين عدد الخيوط للتحميل",
customTitle: "تخصيص عنوان الفصل، إدخال المحدد في الصفحة الداخلية",
reSortDefault: "الترتيب الافتراضي حسب الموقع في الصفحة",
reverseOrder: "عكس ترتيب الفصول",
saveBtn: "حفظ الإعدادات",
saveOk: "تم الحفظ",
nextPage: "التحقق من الصفحة التالية في الفصل",
nextPageReg: "مخصص للصفحة التالية RegExp",
retainImage: "الاحتفاظ بعنوان الصورة إذا كانت هناك صور في النص",
minTxtLength: "المحاولة مرة أخرى عندما يكون طول المحتوى أقل من هذا",
showFilterList: "عرض نافذة التصفية والترتيب قبل التحميل",
ok: "موافق",
close: "إغلاق",
dacSortByPos: "الترتيب حسب الموقع",
dacSortByUrl: "الترتيب حسب الرابط",
dacSortByName: "الترتيب حسب الاسم",
reverse: "عكس الاختيار",
dacUseIframe: "لتحميل المحتوى (بطيء) iframe استخدام",
dacSaveAsZip: "zip حفظ كـ",
dacSetCustomRule: "تعديل القواعد",
dacAddUrl: "إضافة فصل",
dacStartDownload: "تحميل المحدد",
downloadShortcut: "تحميل الفصل",
downloadSingleShortcut: "تحميل صفحة واحدة",
downloadCustomShortcut: "تحميل مخصص"
};
break;
default:
i18n={
fetch:"Download",
info:"Source: #t#\nThe TXT is downloaded by 'DownloadAllContent'",
error:"Failed in downloading current chapter",
downloading:"%s pages are downloaded, there are still %s pages left<br>Downloading %s ......",
complete:"Completed! Get %s pages in total",
del:"Set css selectors for ignore",
custom:"Custom to download",
customInfo:"Input urls OR sss selectors for chapter links",
reSort:"ReSort by title",
reSortUrl:"Resort by URLs",
setting:"Open Setting",
searchRule:"Search rule",
abort:"Abort",
save:"Save",
saveAsMd:"Save as Markdown",
downThreadNum:"Set threadNum for download",
customTitle: "Customize the chapter title, enter the selector on inner page",
reSortDefault: "Default sort by position in the page",
reverseOrder:"Reverse chapter ordering",
saveBtn:"Save Setting",
saveOk:"Save Over",
nextPage:"Check next page in chapter",
nextPageReg:"Custom RegExp of next page",
retainImage:"Keep the URL of image if there are images in the text",
minTxtLength:"Try to crawl again when the length of content is less than this",
showFilterList: "Show chapter filtering and sorting window before downloading",
ok:"OK",
close:"Close",
dacSortByPos:"Sort by position",
dacSortByUrl:"Sort by URL",
dacSortByName:"Sort by name",
reverse:"Reverse selection",
dacUseIframe: "Use iframe to load content (slow)",
dacSaveAsZip: "Save as zip",
dacSetCustomRule:"Modify rules",
dacAddUrl:"Add Chapter",
dacStartDownload:"Download selected",
downloadShortcut:"Download chapter",
downloadSingleShortcut:"Download single page",
downloadCustomShortcut:"Custom download"
};
break;
}
var firefox=navigator.userAgent.toLowerCase().indexOf('firefox')!=-1,curRequests=[],useIframe=false,iframeSandbox=false,iframeInit=false;
var filterListContainer,txtDownContent,txtDownWords,txtDownQuit,dacLinksCon,dacUseIframe,shadowContainer;
const escapeHTMLPolicy = (win.trustedTypes && win.trustedTypes.createPolicy) ? win.trustedTypes.createPolicy('dac_default', {
createHTML: (string, sink) => string
}) : null;
function createHTML(html) {
return escapeHTMLPolicy ? escapeHTMLPolicy.createHTML(html) : html;
}
function str2Num(str) {
str = str.replace(/^番\s*外/, "99999+").replace(/[一①Ⅰ壹]/g, "1").replace(/[二②Ⅱ贰]/g, "2").replace(/[三③Ⅲ叁]/g, "3").replace(/[四④Ⅳ肆]/g, "4").replace(/[五⑤Ⅴ伍]/g, "5").replace(/[六⑥Ⅵ陆]/g, "6").replace(/[七⑦Ⅶ柒]/g, "7").replace(/[八⑧Ⅷ捌]/g, "8").replace(/[九⑨Ⅸ玖]/g, "9").replace(/[十⑩Ⅹ拾]/g, "*10+").replace(/[百佰]/g, "*100+").replace(/[千仟]/g, "*1000+").replace(/[万萬]/g, "*10000+").replace(/\s/g, "").match(/[\d\*\+]+/);
if (!str) return 0;
str = str[0];
let mul = str.match(/(\d*)\*(\d+)/);
while(mul) {
let result = parseInt(mul[1] || 1) * parseInt(mul[2]);
str = str.replace(mul[0], result);
mul = str.match(/(\d+)\*(\d+)/);
}
let plus = str.match(/(\d+)\+(\d+)/);
while(plus) {
let result = parseInt(plus[1]) + parseInt(plus[2]);
str = str.replace(plus[0], result);
plus = str.match(/(\d+)\+(\d+)/);
}
return parseInt(str);
}
var dragOverItem, dragFrom, linkDict;
function createLinkItem(aEle) {
let item = document.createElement("div");
item.innerHTML = createHTML(`
<input type="checkbox" checked>
<a class="dacLink" draggable="false" target="_blank" href="${aEle.href}">${aEle.innerText || "📄"}</a>
<span>🖱️</span>
`);
item.title = aEle.innerText;
item.setAttribute("draggable", "true");
item.addEventListener("dragover", e => {
e.preventDefault();
});
item.addEventListener("dragenter", e => {
if (dragOverItem) dragOverItem.style.opacity = "";
item.style.opacity = 0.3;
dragOverItem = item;
});
item.addEventListener('dragstart', e => {
dragFrom = item;
});
item.addEventListener('drop', e => {
if (!dragFrom) return;
if (e.clientX < item.getBoundingClientRect().left + 142) {
dacLinksCon.insertBefore(dragFrom, item);
} else {
if (item.nextElementSibling) {
dacLinksCon.insertBefore(dragFrom, item.nextElementSibling);
} else {
dacLinksCon.appendChild(dragFrom);
}
}
e.preventDefault();
});
linkDict[aEle.href] = item;
dacLinksCon.appendChild(item);
}
var saveAsZip = true;
function filterList(list) {
if (!GM_getValue("showFilterList")) {
indexDownload(list);
return;
}
if (txtDownContent) {
txtDownContent.style.display = "none";
}
if (filterListContainer) {
filterListContainer.style.display = "";
filterListContainer.classList.remove("customRule");
dacLinksCon.innerHTML = createHTML("");
} else {
document.addEventListener('dragend', e => {
if (dragOverItem) dragOverItem.style.opacity = "";
}, true);
filterListContainer = document.createElement("div");
filterListContainer.id = "filterListContainer";
filterListContainer.innerHTML = createHTML(`
<div id="dacFilterBg" style="height: 100%; width: 100%; position: fixed; top: 0; z-index: 99998; opacity: 0.3; filter: alpha(opacity=30); background-color: #000;"></div>
<div id="filterListBody">
<div class="dacCustomRule">
${i18n.custom}
<textarea id="dacCustomInput"></textarea>
<div class="fun">
<input id="dacConfirmRule" value="${i18n.ok}" type="button"/>
<input id="dacCustomClose" value="${i18n.close}" type="button"/>
</div>
</div>
<div class="sort">
<input id="dacSortByPos" value="${i18n.dacSortByPos}" type="button"/>
<input id="dacSortByUrl" value="${i18n.dacSortByUrl}" type="button"/>
<input id="dacSortByName" value="${i18n.dacSortByName}" type="button"/>
<input id="reverse" value="${i18n.reverse}" type="button"/>
</div>
<div id="dacLinksCon" style="max-height: calc(80vh - 100px); min-height: 100px; display: grid; grid-template-columns: auto auto; width: 100%; overflow: auto; white-space: nowrap;"></div>
<p style="margin: 5px; text-align: center; font-size: 14px; height: 20px;"><span><input id="dacUseIframe" type="checkbox"/><label for="dacUseIframe"> ${i18n.dacUseIframe}</label></span> <span style="display:${win.downloadAllContentSaveAsZip ? "inline" : "none"}"><input id="dacSaveAsZip" type="checkbox" checked="checked"/><label for="dacSaveAsZip"> ${i18n.dacSaveAsZip}</label></span></p>
<div class="fun">
<input id="dacSetCustomRule" value="${i18n.dacSetCustomRule}" type="button"/>
<input id="dacAddUrl" value="${i18n.dacAddUrl}" type="button"/>
<input id="dacStartDownload" value="${i18n.dacStartDownload}" type="button"/>
<input id="dacLinksClose" value="${i18n.close}" type="button"/>
</div>
</div>`);
let dacSortByPos = filterListContainer.querySelector("#dacSortByPos");
let dacSortByUrl = filterListContainer.querySelector("#dacSortByUrl");
let dacSortByName = filterListContainer.querySelector("#dacSortByName");
let reverse = filterListContainer.querySelector("#reverse");
let dacSetCustomRule = filterListContainer.querySelector("#dacSetCustomRule");
let dacCustomInput = filterListContainer.querySelector("#dacCustomInput");
let dacConfirmRule = filterListContainer.querySelector("#dacConfirmRule");
let dacCustomClose = filterListContainer.querySelector("#dacCustomClose");
let dacAddUrl = filterListContainer.querySelector("#dacAddUrl");
let dacStartDownload = filterListContainer.querySelector("#dacStartDownload");
let dacLinksClose = filterListContainer.querySelector("#dacLinksClose");
let dacFilterBg = filterListContainer.querySelector("#dacFilterBg");
let dacSaveAsZip = filterListContainer.querySelector("#dacSaveAsZip");
dacUseIframe = filterListContainer.querySelector("#dacUseIframe");
dacSaveAsZip.onchange = e => {
saveAsZip = dacSaveAsZip.checked;
};
dacSortByPos.onclick = e => {
let linkList = [].slice.call(dacLinksCon.children);
if (linkList[0].children[1].href != list[0].href) {
list.reverse().forEach(a => {
let link = linkDict[a.href];
if (!link) return;
dacLinksCon.insertBefore(link, dacLinksCon.children[0]);
});
} else {
list.forEach(a => {
let link = linkDict[a.href];
if (!link) return;
dacLinksCon.insertBefore(link, dacLinksCon.children[0]);
});
}
};
dacSortByUrl.onclick = e => {
let linkList = [].slice.call(dacLinksCon.children);
linkList.sort((a, b) => {
const nameA = a.children[1].href.toUpperCase();
const nameB = b.children[1].href.toUpperCase();
if (nameA < nameB) {
return -1;
}
if (nameA > nameB) {
return 1;
}
return 0;
});
if (linkList[0] == dacLinksCon.children[0]) {
linkList = linkList.reverse();
}
linkList.forEach(link => {
dacLinksCon.appendChild(link);
});
};
dacSortByName.onclick = e => {
let linkList = [].slice.call(dacLinksCon.children);
linkList.sort((a, b) => {
return str2Num(a.innerText) - str2Num(b.innerText);
});
if (linkList[0] == dacLinksCon.children[0]) {
linkList = linkList.reverse();
}
linkList.forEach(link => {
dacLinksCon.appendChild(link);
});
};
reverse.onclick = e => {
let linkList = [].slice.call(dacLinksCon.children);
linkList.forEach(link => {
link.children[0].checked=!link.children[0].checked;
});
};
dacSetCustomRule.onclick = e => {
filterListContainer.classList.add("customRule");
dacCustomInput.value = GM_getValue("DACrules_" + document.domain) || "";
};
dacConfirmRule.onclick = e => {
if (dacCustomInput.value) {
customDown(dacCustomInput.value);
}
};
dacCustomClose.onclick = e => {
filterListContainer.classList.remove("customRule");
};
dacAddUrl.onclick = e => {
let addUrls = window.prompt(i18n.customInfo, "https://xxx.xxx/book-[20-99].html, https://xxx.xxx/book-[01-10].html");
if (!addUrls || !/^http|^ftp/.test(addUrls)) return;
let index = 1;
[].forEach.call(addUrls.split(","), function(i) {
var curEle;
var varNum = /\[\d+\-\d+\]/.exec(i);
if (varNum) {
varNum = varNum[0].trim();
} else {
curEle = document.createElement("a");
curEle.href = i;
curEle.innerText = "Added Url";
createLinkItem(curEle);
return;
}
var num1 = /\[(\d+)/.exec(varNum)[1].trim();
var num2 = /(\d+)\]/.exec(varNum)[1].trim();
var num1Int = parseInt(num1);
var num2Int = parseInt(num2);
var numLen = num1.length;
var needAdd = num1.charAt(0) == "0";
if (num1Int >= num2Int) return;
for (var j = num1Int; j <= num2Int; j++) {
var urlIndex = j.toString();
if (needAdd) {
while(urlIndex.length < numLen) urlIndex = "0" + urlIndex;
}
var curUrl = i.replace(/\[\d+\-\d+\]/, urlIndex).trim();
curEle = document.createElement("a");
curEle.href = curUrl;
curEle.innerText = "Added Url " + index++;
createLinkItem(curEle);
}
});
};
dacStartDownload.onclick = e => {
let linkList = [].slice.call(dacLinksCon.querySelectorAll("input:checked+.dacLink"));
useIframe = !!dacUseIframe.checked;
indexDownload(linkList, true);
};
dacLinksClose.onclick = e => {
filterListContainer.style.display = "none";
};
dacFilterBg.onclick = e => {
filterListContainer.style.display = "none";
};
let listStyle = GM_addStyle(`
#filterListContainer * {
font-size: 13px;
float: initial;
background-image: initial;
height: fit-content;
color: black;
}
#filterListContainer.customRule .dacCustomRule {
display: flex;
}
#filterListContainer .dacCustomRule>textarea {
height: 300px;
width: 100%;
border: 1px #DADADA solid;
background: #ededed70;
margin: 5px;
}
#filterListContainer.customRule .dacCustomRule~* {
display: none!important;
}
#dacLinksCon>div {
padding: 5px 0;
display: flex;
}
#dacLinksCon>div>a {
max-width: 245px;
display: inline-block;
text-overflow: ellipsis;
overflow: hidden;
}
#dacLinksCon>div>input {
margin-right: 5px;
}
#filterListContainer .dacCustomRule {
border-radius: 8px;
font-weight: bold;
font-size: 16px;
outline: none;
align-items: center;
flex-wrap: nowrap;
white-space: nowrap;
flex-direction: column;
display: none;
}
#filterListContainer input {
border-width: 2px;
border-style: outset;
border-color: buttonface;
border-image: initial;
border: 1px #DADADA solid;
padding: 5px;
border-radius: 8px;
font-weight: bold;
font-size: 9pt;
outline: none;
cursor: pointer;
line-height: initial;
width: initial;
min-width: initial;
max-width: initial;
height: initial;
min-height: initial;
max-height: initial;
}
#dacLinksCon>div:nth-of-type(4n),
#dacLinksCon>div:nth-of-type(4n+1) {
background: #ffffff;
}
#dacLinksCon>div:nth-of-type(4n+2),
#dacLinksCon>div:nth-of-type(4n+3) {
background: #f5f5f5;
}
#filterListContainer .fun,#filterListContainer .sort {
display: flex;
justify-content: space-around;
flex-wrap: nowrap;
width: 100%;
height: 28px;
}
#filterListContainer input[type=button]:hover {
border: 1px #C6C6C6 solid;
box-shadow: 1px 1px 1px #EAEAEA;
color: #333333;
background: #F7F7F7;
}
#filterListContainer input[type=button]:active {
box-shadow: inset 1px 1px 1px #DFDFDF;
}
#filterListBody {
padding: 5px;
box-sizing: border-box;
overflow: hidden;
width: 600px;
height: auto;
max-height: 80vh;
min-height: 200px;
position: fixed;
left: 50%;
top: 10%;
margin-left: -300px;
z-index: 99998;
background-color: #ffffff;
border: 1px solid #afb3b6;
border-radius: 10px;
opacity: 0.95;
filter: alpha(opacity=95);
box-shadow: 5px 5px 20px 0px #000;
}
@media screen and (max-width: 800px) {
#filterListBody {
width: 90%;
margin-left: -45%;
}
}
`);
dacLinksCon = filterListContainer.querySelector("#dacLinksCon");
shadowContainer = document.createElement("div");
document.body.appendChild(shadowContainer);
let shadow = shadowContainer.attachShadow({ mode: "open" });
shadow.appendChild(listStyle);
shadow.appendChild(filterListContainer);
}
if (shadowContainer.parentNode) shadowContainer.parentNode.removeChild(shadowContainer);
linkDict = {};
list.forEach(a => {
createLinkItem(a);
});
dacUseIframe.checked = useIframe;
document.body.appendChild(shadowContainer);
}
function initTxtDownDiv() {
if (txtDownContent) {
txtDownContent.style.display = "";
return;
}
txtDownContent = document.createElement("div");
txtDownContent.id = "txtDownContent";
let shadowContainer = document.createElement("div");
document.body.appendChild(shadowContainer);
let shadow = shadowContainer.attachShadow({ mode: "open" });
shadow.appendChild(txtDownContent);
txtDownContent.innerHTML=createHTML(`
<style>
#txtDownContent>div{
font-size:16px;
color:#333333;
width:362px;
height:110px;
position:fixed;
left:50%;
top:50%;
margin-top:-25px;
margin-left:-191px;
z-index:100000;
background-color:#ffffff;
border:1px solid #afb3b6;
border-radius:10px;
opacity:0.95;
filter:alpha(opacity=95);
box-shadow:5px 5px 20px 0px #000;
}
#txtDownWords{
position:absolute;
width:275px;
height: 90px;
max-height: 90%;
border: 1px solid #f3f1f1;
padding: 8px;
border-radius: 10px;
overflow: auto;
}
#txtDownQuit{
width: 30px;height: 30px;border-radius: 30px;position:absolute;right:2px;top:2px;cursor: pointer;background-color:#ff5a5a;
}
#txtDownQuit>span{
height: 30px;line-height: 30px;display:block;color:#FFF;text-align:center;font-size: 12px;font-weight: bold;font-family: arial;background: initial; float: initial;
}
#txtDownQuit+div{
position:absolute;right:0px;bottom:2px;cursor: pointer;max-width:85px;
}
#txtDownQuit+div>button{
background: #008aff;border: 0;padding: 5px;border-radius: 6px;color: white;float: right;margin: 1px;height: 25px;line-height: 16px;cursor: pointer;overflow: hidden;
}
</style>
<div>
<div id="txtDownWords">
Analysing......
</div>
<div id="txtDownQuit">
<span>╳</span>
</div>
<div>
<button id="abortRequest" style="display:none;">${getI18n('abort')}</button>
<button id="tempSaveTxt">${getI18n('save')}</button>
<button id="saveAsMd" title="${getI18n('saveAsMd')}">Markdown</button>
</div>
</div>`);
txtDownWords=txtDownContent.querySelector("#txtDownWords");
txtDownQuit=txtDownContent.querySelector("#txtDownQuit");
txtDownQuit.onclick=function(){
txtDownContent.style.display="none";
};
initTempSave(txtDownContent);
win.txtDownWords = txtDownWords;
}
function saveContent() {
if (win.downloadAllContentSaveAsZip && saveAsZip) {
win.downloadAllContentSaveAsZip(rCats, i18n.info.replace("#t#", location.href), content => {
saveAs(content, document.title.replace(/[\*\/:<>\?\\\|\r\n,]/g, "_") + ".zip");
});
} else {
var blob = new Blob([i18n.info.replace("#t#", location.href) + "\r\n\r\n" + document.title + "\r\n\r\n" + rCats.join("\r\n\r\n")], {type: "text/plain;charset=utf-8"});
saveAs(blob, document.title.replace(/[\*\/:<>\?\\\|\r\n,]/g, "_") + ".txt");
}
}
function initTempSave(txtDownContent){
var tempSavebtn = txtDownContent.querySelector('#tempSaveTxt');
var abortbtn = txtDownContent.querySelector('#abortRequest');
var saveAsMd = txtDownContent.querySelector('#saveAsMd');
tempSavebtn.onclick = function(){
saveContent();
console.log(curRequests);
}
abortbtn.onclick = function(){
let curRequest = curRequests.pop();
if(curRequest)curRequest[1].abort();
}
saveAsMd.onclick = function(){
let txt = i18n.info.replace("#t#", location.href)+"\n\n---\n"+document.title+"\n===\n";
rCats.forEach(cat => {
cat = cat.replace("\r\n", "\n---").replace(/(\r\n|\n\r)+/g, "\n\n").replace(/[\n\r]\t+/g, "\n");
txt += '\n\n'+cat;
});
var blob = new Blob([txt], {type: "text/plain;charset=utf-8"});
saveAs(blob, document.title.replace(/[\*\/:<>\?\\\|\r\n,]/g, "_") + ".md");
}
}
let charset = (document.characterSet || document.charset || document.inputEncoding);
let equiv = document.querySelector('[http-equiv="Content-Type"]'), charsetValid = true;
if (equiv && equiv.content) {
let innerCharSet = equiv.content.match(/charset\=([^;]+)/);
if (!innerCharSet) {
charsetValid = false;
} else if (innerCharSet[1].replace("-", "").toLowerCase() != charset.replace("-", "").toLowerCase()) {
charsetValid = false;
}
} else charsetValid = false;
function indexDownload(aEles, noSort){
if(aEles.length<1)return;
initTxtDownDiv();
if(!noSort) {
if(GM_getValue("contentSort")){
aEles.sort((a, b) => {
return str2Num(a.innerText) - str2Num(b.innerText);
});
}
if(GM_getValue("contentSortUrl")){
aEles.sort((a, b) => {
const nameA = a.href.toUpperCase();
const nameB = b.href.toUpperCase();
if (nameA < nameB) {
return -1;
}
if (nameA > nameB) {
return 1;
}
return 0;
});
}
if(GM_getValue("reverse")){
aEles=aEles.reverse();
}
}
rCats=[];
var minTxtLength=GM_getValue("minTxtLength") || 100;
var customTitle=GM_getValue("customTitle");
var disableNextPage=!!GM_getValue("disableNextPage");
var customNextPageReg=GM_getValue("nextPageReg");
if (customNextPageReg) {
try {
innerNextPage = new RegExp(customNextPageReg);
} catch(e) {
console.warn(e);
}
}
var insertSigns=[];
// var j=0,rCats=[];
var downIndex=0,downNum=0,downOnce=function(wait){
if(downNum>=aEles.length)return;
let curIndex=downIndex;
let aTag=aEles[curIndex];
let request=(aTag, curIndex)=>{
let tryTimes=0;
let validTimes=0;
function requestDoc(_charset) {
if (!_charset) _charset = charset;
return GM_xmlhttpRequest({
method: 'GET',
url: aTag.href,
headers:{
referer:aTag.href,
"Content-Type":"text/html;charset="+_charset
},
timeout:10000,
overrideMimeType:"text/html;charset="+_charset,
onload: async function(result) {
let doc = getDocEle(result.responseText);
if (charsetValid) {
let equiv = doc.querySelector('[http-equiv="Content-Type"]');
if (equiv && equiv.content) {
let innerCharSet = equiv.content.match(/charset\=([^;]+)/);
if (innerCharSet && innerCharSet[1].replace("-", "").toLowerCase() != _charset.replace("-", "").toLowerCase()) {
charset = innerCharSet[1];
return requestDoc(charset);
}
}
}
downIndex++;
downNum++;
if (/^{/.test(result.responseText)) {
doc.json = () => {
try {
return JSON.parse(result.responseText);
} catch(e) {}
return {};
}
}