怠惰小说下载器

通用网站内容抓取工具,可批量抓取任意站点的小说、论坛内容等并保存为TXT文档

当前为 2023-10-26 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name DownloadAllContent
  3. // @name:zh-CN 怠惰小说下载器
  4. // @name:zh-TW 怠惰小説下載器
  5. // @name:ja 怠惰者小説ダウンロードツール
  6. // @namespace hoothin
  7. // @version 2.7.5.2
  8. // @description Fetch and download main content on current page, provide special support for novel
  9. // @description:zh-CN 通用网站内容抓取工具,可批量抓取任意站点的小说、论坛内容等并保存为TXT文档
  10. // @description:zh-TW 通用網站內容抓取工具,可批量抓取任意站點的小說、論壇內容等並保存為TXT文檔
  11. // @description:ja ユニバーサルサイトコンテンツクロールツール、クロール、フォーラム内容など
  12. // @author hoothin
  13. // @match http://*/*
  14. // @match https://*/*
  15. // @match ftp://*/*
  16. // @grant GM_xmlhttpRequest
  17. // @grant GM_registerMenuCommand
  18. // @grant GM_setValue
  19. // @grant GM_getValue
  20. // @grant GM_openInTab
  21. // @grant GM_setClipboard
  22. // @grant GM_addStyle
  23. // @grant unsafeWindow
  24. // @license MIT License
  25. // @compatible chrome
  26. // @compatible firefox
  27. // @compatible opera 未测试
  28. // @compatible safari 未测试
  29. // @contributionURL https://ko-fi.com/hoothin
  30. // @contributionAmount 1
  31. // ==/UserScript==
  32.  
  33. if (window.top != window.self) {
  34. try {
  35. if (window.self.innerWidth < 250 || window.self.innerHeight < 250) {
  36. return;
  37. }
  38. } catch(e) {
  39. return;
  40. }
  41. }
  42.  
  43. (function (global, factory) {
  44. if (typeof define === "function" && define.amd) {
  45. define([], factory);
  46. } else if (typeof exports !== "undefined") {
  47. factory();
  48. } else {
  49. var mod = {
  50. exports: {}
  51. };
  52. factory();
  53. global.FileSaver = mod.exports;
  54. }
  55. })(this, function () {
  56. "use strict";
  57.  
  58. /*
  59. * FileSaver.js
  60. * A saveAs() FileSaver implementation.
  61. *
  62. * By Eli Grey, http://eligrey.com
  63. *
  64. * License : https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md (MIT)
  65. * source : http://purl.eligrey.com/github/FileSaver.js
  66. */
  67. 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;
  68.  
  69. function bom(blob, opts) {
  70. if (typeof opts === 'undefined') opts = {
  71. autoBom: false
  72. };else if (typeof opts !== 'object') {
  73. console.warn('Deprecated: Expected third argument to be a object');
  74. opts = {
  75. autoBom: !opts
  76. };
  77. }
  78.  
  79. if (opts.autoBom && /^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) {
  80. return new Blob([String.fromCharCode(0xFEFF), blob], {
  81. type: blob.type
  82. });
  83. }
  84.  
  85. return blob;
  86. }
  87.  
  88. function download(url, name, opts) {
  89. var xhr = new XMLHttpRequest();
  90. xhr.open('GET', url);
  91. xhr.responseType = 'blob';
  92.  
  93. xhr.onload = function () {
  94. saveAs(xhr.response, name, opts);
  95. };
  96.  
  97. xhr.onerror = function () {
  98. console.error('could not download file');
  99. };
  100.  
  101. xhr.send();
  102. }
  103.  
  104. function corsEnabled(url) {
  105. var xhr = new XMLHttpRequest();
  106.  
  107. xhr.open('HEAD', url, false);
  108.  
  109. try {
  110. xhr.send();
  111. } catch (e) {}
  112.  
  113. return xhr.status >= 200 && xhr.status <= 299;
  114. }
  115.  
  116.  
  117. function click(node) {
  118. try {
  119. node.dispatchEvent(new MouseEvent('click'));
  120. } catch (e) {
  121. var evt = document.createEvent('MouseEvents');
  122. evt.initMouseEvent('click', true, true, window, 0, 0, 0, 80, 20, false, false, false, false, 0, null);
  123. node.dispatchEvent(evt);
  124. }
  125. }
  126.  
  127.  
  128. var isMacOSWebView = _global.navigator && /Macintosh/.test(navigator.userAgent) && /AppleWebKit/.test(navigator.userAgent) && !/Safari/.test(navigator.userAgent);
  129. var saveAs = _global.saveAs || (
  130. typeof window !== 'object' || window !== _global ? function saveAs() {}
  131.  
  132. : 'download' in HTMLAnchorElement.prototype && !isMacOSWebView ? function saveAs(blob, name, opts) {
  133. var URL = _global.URL || _global.webkitURL;
  134. var a = document.createElement('a');
  135. name = name || blob.name || 'download';
  136. a.download = name;
  137. a.rel = 'noopener';
  138.  
  139. if (typeof blob === 'string') {
  140. a.href = blob;
  141.  
  142. if (a.origin !== location.origin) {
  143. corsEnabled(a.href) ? download(blob, name, opts) : click(a, a.target = '_blank');
  144. } else {
  145. click(a);
  146. }
  147. } else {
  148. a.href = URL.createObjectURL(blob);
  149. setTimeout(function () {
  150. URL.revokeObjectURL(a.href);
  151. }, 4E4);
  152.  
  153. setTimeout(function () {
  154. click(a);
  155. }, 0);
  156. }
  157. }
  158. : 'msSaveOrOpenBlob' in navigator ? function saveAs(blob, name, opts) {
  159. name = name || blob.name || 'download';
  160.  
  161. if (typeof blob === 'string') {
  162. if (corsEnabled(blob)) {
  163. download(blob, name, opts);
  164. } else {
  165. var a = document.createElement('a');
  166. a.href = blob;
  167. a.target = '_blank';
  168. setTimeout(function () {
  169. click(a);
  170. });
  171. }
  172. } else {
  173. navigator.msSaveOrOpenBlob(bom(blob, opts), name);
  174. }
  175. }
  176. : function saveAs(blob, name, opts, popup) {
  177. popup = popup || open('', '_blank');
  178.  
  179. if (popup) {
  180. popup.document.title = popup.document.body.innerText = 'downloading...';
  181. }
  182.  
  183. if (typeof blob === 'string') return download(blob, name, opts);
  184. var force = blob.type === 'application/octet-stream';
  185.  
  186. var isSafari = /constructor/i.test(_global.HTMLElement) || _global.safari;
  187.  
  188. var isChromeIOS = /CriOS\/[\d]+/.test(navigator.userAgent);
  189.  
  190. if ((isChromeIOS || force && isSafari || isMacOSWebView) && typeof FileReader !== 'undefined') {
  191. var reader = new FileReader();
  192.  
  193. reader.onloadend = function () {
  194. var url = reader.result;
  195. url = isChromeIOS ? url : url.replace(/^data:[^;]*;/, 'data:attachment/file;');
  196. if (popup) popup.location.href = url;else location = url;
  197. popup = null;
  198. };
  199.  
  200. reader.readAsDataURL(blob);
  201. } else {
  202. var URL = _global.URL || _global.webkitURL;
  203. var url = URL.createObjectURL(blob);
  204. if (popup) popup.location = url;else location.href = url;
  205. popup = null;
  206.  
  207. setTimeout(function () {
  208. URL.revokeObjectURL(url);
  209. }, 4E4);
  210. }
  211. });
  212. _global.saveAs = saveAs.saveAs = saveAs;
  213.  
  214. if (typeof module !== 'undefined') {
  215. module.exports = saveAs;
  216. }
  217. });
  218.  
  219. (function() {
  220. 'use strict';
  221. var indexReg=/PART\b|^Prologue|Chapter\s*[\-_]?\d+|分卷|^序$|^序\s*言|^序\s*章|^前\s*言|^附\s*[录錄]|^引\s*[言子]|^摘\s*要|^[楔契]\s*子|^后\s*记|^後\s*記|^附\s*言|^结\s*语|^結\s*語|^尾\s*[声聲]|^最終話|^最终话|^番\s*外|^\d+[\s\.、,,)\-_::][^\d#\.]+$|^[第(]?\s*[\d〇零一二三四五六七八九十百千万萬-]+\s*[、)章节節回卷折篇幕集话話]/i;
  222. var innerNextPage=/^\s*(下一[页頁张張]|next\s*page|次のページ)/i;
  223. var lang = navigator.appName=="Netscape"?navigator.language:navigator.userLanguage;
  224. var i18n={};
  225. var rCats=[];
  226. var processFunc;
  227. var win=(typeof unsafeWindow=='undefined'? window : unsafeWindow);
  228. switch (lang){
  229. case "zh-CN":
  230. case "zh-SG":
  231. i18n={
  232. fetch:"开始下载小说【Ctrl+F9】",
  233. info:"本文是使用怠惰小说下载器(DownloadAllContent)下载的",
  234. error:"该段内容获取失败",
  235. downloading:"已下载完成 %s 段,剩余 %s 段<br>正在下载 %s",
  236. complete:"已全部下载完成,共 %s 段",
  237. del:"设置文本干扰码的CSS选择器",
  238. custom:"自定规则下载",
  239. customInfo:"输入网址或者章节CSS选择器",
  240. reSort:"按标题名重新排序章节",
  241. reSortUrl:"按网址重新排序章节",
  242. setting:"选项参数设置",
  243. searchRule:"搜索网站规则",
  244. abort:"跳过此章",
  245. save:"保存当前",
  246. saveAsMd:"存为 Markdown",
  247. downThreadNum:"设置同时下载的线程数",
  248. customTitle:"自定义章节标题,输入内页文字对应选择器",
  249. reSortDefault:"默认按页面中位置排序章节",
  250. reverse:"反转章节排序",
  251. saveBtn:"保存设置",
  252. saveOk:"保存成功",
  253. nextPage:"嗅探章节内分页",
  254. nextPageReg:"自定义分页正则",
  255. retainImage:"保留正文中图片的网址",
  256. minTxtLength:"当检测到的正文字数小于此数,则尝试重新抓取",
  257. showFilterList:"下载前显示章节筛选排序窗口",
  258. ok:"确定",
  259. close:"关闭",
  260. dacSortByPos:"按页内位置排序",
  261. dacSortByUrl:"按网址排序",
  262. dacSortByName:"按章节名排序",
  263. dacUseIframe:"使用 iframe 后台加载内容(慢速)",
  264. dacSetCustomRule:"修改规则",
  265. dacAddUrl:"添加章节",
  266. dacStartDownload:"下载选中"
  267. };
  268. break;
  269. case "zh-TW":
  270. case "zh-HK":
  271. i18n={
  272. fetch:"開始下載小說【Ctrl+F9】",
  273. info:"本文是使用怠惰小說下載器(DownloadAllContent)下載的",
  274. error:"該段內容獲取失敗",
  275. downloading:"已下載完成 %s 段,剩餘 %s 段<br>正在下載 %s",
  276. complete:"已全部下載完成,共 %s 段",
  277. del:"設置文本干擾碼的CSS選擇器",
  278. custom:"自訂規則下載",
  279. customInfo:"輸入網址或者章節CSS選擇器",
  280. reSort:"按標題名重新排序章節",
  281. reSortUrl:"按網址重新排序章節",
  282. setting:"選項參數設定",
  283. searchRule:"搜尋網站規則",
  284. abort:"跳過此章",
  285. save:"保存當前",
  286. saveAsMd:"存爲 Markdown",
  287. downThreadNum:"設置同時下載的綫程數",
  288. customTitle:"自訂章節標題,輸入內頁文字對應選擇器",
  289. reSortDefault:"預設依頁面中位置排序章節",
  290. reverse:"反轉章節排序",
  291. saveBtn:"儲存設定",
  292. saveOk:"儲存成功",
  293. nextPage:"嗅探章節內分頁",
  294. nextPageReg:"自訂分頁正規",
  295. retainImage:"保留內文圖片的網址",
  296. minTxtLength:"當偵測到的正文字數小於此數,則嘗試重新抓取",
  297. showFilterList:"下載前顯示章節篩選排序視窗",
  298. ok:"確定",
  299. close:"關閉",
  300. dacSortByPos:"依頁內位置排序",
  301. dacSortByUrl:"依網址排序",
  302. dacSortByName:"依章節名排序",
  303. dacUseIframe:"使用 iframe 背景載入內容(慢速)",
  304. dacSetCustomRule:"修改規則",
  305. dacAddUrl:"新增章節",
  306. dacStartDownload:"下載選取"
  307. };
  308. break;
  309. default:
  310. i18n={
  311. fetch:"Download [Ctrl+F9]",
  312. info:"The TXT is downloaded by 'DownloadAllContent'",
  313. error:"Failed in downloading current chapter",
  314. downloading:"%s pages are downloaded, there are still %s pages left<br>Downloading %s ......",
  315. complete:"Completed! Get %s pages in total",
  316. del:"Set css selectors for ignore",
  317. custom:"Custom to download",
  318. customInfo:"Input urls OR sss selectors for chapter links",
  319. reSort:"ReSort by title",
  320. reSortUrl:"Resort by URLs",
  321. setting:"Open Setting",
  322. searchRule:"Search rule",
  323. abort:"Abort",
  324. save:"Save",
  325. saveAsMd:"Save as Markdown",
  326. downThreadNum:"Set threadNum for download",
  327. customTitle: "Customize the chapter title, enter the selector on inner page",
  328. reSortDefault: "Default sort by position in the page",
  329. reverse:"Reverse chapter ordering",
  330. saveBtn:"Save Setting",
  331. saveOk:"Save Over",
  332. nextPage:"Check next page in chapter",
  333. nextPageReg:"Custom RegExp of next page",
  334. retainImage:"Keep the URL of image if there are images in the text",
  335. minTxtLength:"Try to crawl again when the length of content is less than this",
  336. showFilterList: "Show chapter filtering and sorting window before downloading",
  337. ok:"OK",
  338. close:"Close",
  339. dacSortByPos:"Sort by position",
  340. dacSortByUrl:"Sort by URL",
  341. dacSortByName:"Sort by name",
  342. dacUseIframe: "Use iframe to load content in the background (slow)",
  343. dacSetCustomRule:"Modify rules",
  344. dacAddUrl:"Add Chapter",
  345. dacStartDownload:"Download selected"
  346. };
  347. break;
  348. }
  349. var firefox=navigator.userAgent.toLowerCase().indexOf('firefox')!=-1,curRequests=[],useIframe=false,iframeSandbox=false,iframeInit=false;
  350. var filterListContainer,txtDownContent,txtDownWords,txtDownQuit,dacLinksCon,dacUseIframe;
  351.  
  352. const escapeHTMLPolicy = (win.trustedTypes && win.trustedTypes.createPolicy) ? win.trustedTypes.createPolicy('dac_default', {
  353. createHTML: (string, sink) => string
  354. }) : null;
  355.  
  356. function createHTML(html) {
  357. return escapeHTMLPolicy ? escapeHTMLPolicy.createHTML(html) : html;
  358. }
  359.  
  360. function str2Num(str) {
  361. 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\*\+]+/);
  362. if (!str) return 0;
  363. str = str[0];
  364. let mul = str.match(/(\d*)\*(\d+)/);
  365. while(mul) {
  366. let result = parseInt(mul[1] || 1) * parseInt(mul[2]);
  367. str = str.replace(mul[0], result);
  368. mul = str.match(/(\d+)\*(\d+)/);
  369. }
  370. let plus = str.match(/(\d+)\+(\d+)/);
  371. while(plus) {
  372. let result = parseInt(plus[1]) + parseInt(plus[2]);
  373. str = str.replace(plus[0], result);
  374. plus = str.match(/(\d+)\+(\d+)/);
  375. }
  376. return parseInt(str);
  377. }
  378.  
  379. var dragOverItem, dragFrom;
  380. function createLinkItem(aEle) {
  381. let item = document.createElement("div");
  382. item.innerHTML = createHTML(`
  383. <input type="checkbox" checked>
  384. <a class="dacLink" draggable="false" target="_blank" href="${aEle.href}">${aEle.innerText || "📄"}</a>
  385. <span>🖱️</span>
  386. `);
  387. item.title = aEle.innerText;
  388. item.setAttribute("draggable", "true");
  389. item.addEventListener("dragover", e => {
  390. e.preventDefault();
  391. });
  392. item.addEventListener("dragenter", e => {
  393. if (dragOverItem) dragOverItem.style.opacity = "";
  394. item.style.opacity = 0.3;
  395. dragOverItem = item;
  396. });
  397. item.addEventListener('dragstart', e => {
  398. dragFrom = item;
  399. });
  400. item.addEventListener('drop', e => {
  401. if (!dragFrom) return;
  402. if (e.clientX < item.getBoundingClientRect().left + 142) {
  403. dacLinksCon.insertBefore(dragFrom, item);
  404. } else {
  405. if (item.nextElementSibling) {
  406. dacLinksCon.insertBefore(dragFrom, item.nextElementSibling);
  407. } else {
  408. dacLinksCon.appendChild(dragFrom);
  409. }
  410. }
  411. e.preventDefault();
  412. });
  413. dacLinksCon.appendChild(item);
  414. }
  415.  
  416. function filterList(list) {
  417. if (!GM_getValue("showFilterList")) {
  418. indexDownload(list);
  419. return;
  420. }
  421. if (filterListContainer) {
  422. filterListContainer.style.display = "";
  423. filterListContainer.classList.remove("customRule");
  424. dacLinksCon.innerHTML = createHTML("");
  425. } else {
  426. document.addEventListener('dragend', e => {
  427. if (dragOverItem) dragOverItem.style.opacity = "";
  428. }, true);
  429. filterListContainer = document.createElement("div");
  430. filterListContainer.id = "filterListContainer";
  431. document.body.appendChild(filterListContainer);
  432. filterListContainer.innerHTML = createHTML(`
  433. <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>
  434. <div style="padding: 5px; box-sizing: border-box; overflow: hidden; width: 600px; height: auto; max-height: 80%; 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;">
  435. <div class="dacCustomRule">
  436. ${i18n.custom}
  437. <textarea id="dacCustomInput"></textarea>
  438. <div class="fun">
  439. <input id="dacConfirmRule" value="${i18n.ok}" type="button"/>
  440. <input id="dacCustomClose" value="${i18n.close}" type="button"/>
  441. </div>
  442. </div>
  443. <div class="sort">
  444. <input id="dacSortByPos" value="${i18n.dacSortByPos}" type="button"/>
  445. <input id="dacSortByUrl" value="${i18n.dacSortByUrl}" type="button"/>
  446. <input id="dacSortByName" value="${i18n.dacSortByName}" type="button"/>
  447. </div>
  448. <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>
  449. <p style="margin: 5px; text-align: center; font-size: 14px;"><input id="dacUseIframe" type="checkbox"/><label for="dacUseIframe"> ${i18n.dacUseIframe}</label></p>
  450. <div class="fun">
  451. <input id="dacSetCustomRule" value="${i18n.dacSetCustomRule}" type="button"/>
  452. <input id="dacAddUrl" value="${i18n.dacAddUrl}" type="button"/>
  453. <input id="dacStartDownload" value="${i18n.dacStartDownload}" type="button"/>
  454. <input id="dacLinksClose" value="${i18n.close}" type="button"/>
  455. </div>
  456. </div>`);
  457. let dacSortByPos = filterListContainer.querySelector("#dacSortByPos");
  458. let dacSortByUrl = filterListContainer.querySelector("#dacSortByUrl");
  459. let dacSortByName = filterListContainer.querySelector("#dacSortByName");
  460. let dacSetCustomRule = filterListContainer.querySelector("#dacSetCustomRule");
  461. let dacCustomInput = filterListContainer.querySelector("#dacCustomInput");
  462. let dacConfirmRule = filterListContainer.querySelector("#dacConfirmRule");
  463. let dacCustomClose = filterListContainer.querySelector("#dacCustomClose");
  464. let dacAddUrl = filterListContainer.querySelector("#dacAddUrl");
  465. let dacStartDownload = filterListContainer.querySelector("#dacStartDownload");
  466. let dacLinksClose = filterListContainer.querySelector("#dacLinksClose");
  467. let dacFilterBg = filterListContainer.querySelector("#dacFilterBg");
  468. dacUseIframe = filterListContainer.querySelector("#dacUseIframe");
  469. dacSortByPos.onclick = e => {
  470. let linkList = [].slice.call(dacLinksCon.children);
  471. if (linkList[0].children[1].href != list[0].href) {
  472. list.reverse().forEach(a => {
  473. for (let i = 0; i < linkList.length; i++) {
  474. let link = linkList[i];
  475. if (link.children[1].href == a.href) {
  476. dacLinksCon.insertBefore(link, dacLinksCon.children[0]);
  477. }
  478. }
  479. });
  480. } else {
  481. list.forEach(a => {
  482. for (let i = 0; i < linkList.length; i++) {
  483. let link = linkList[i];
  484. if (link.children[1].href == a.href) {
  485. dacLinksCon.insertBefore(link, dacLinksCon.children[0]);
  486. }
  487. }
  488. });
  489. }
  490. };
  491. dacSortByUrl.onclick = e => {
  492. let linkList = [].slice.call(dacLinksCon.children);
  493. linkList.sort((a, b) => {
  494. const nameA = a.children[1].href.toUpperCase();
  495. const nameB = b.children[1].href.toUpperCase();
  496. if (nameA < nameB) {
  497. return -1;
  498. }
  499. if (nameA > nameB) {
  500. return 1;
  501. }
  502. return 0;
  503. });
  504. if (linkList[0] == dacLinksCon.children[0]) {
  505. linkList = linkList.reverse();
  506. }
  507. linkList.forEach(link => {
  508. dacLinksCon.appendChild(link);
  509. });
  510. };
  511. dacSortByName.onclick = e => {
  512. let linkList = [].slice.call(dacLinksCon.children);
  513. linkList.sort((a, b) => {
  514. return str2Num(a.innerText) - str2Num(b.innerText);
  515. });
  516. if (linkList[0] == dacLinksCon.children[0]) {
  517. linkList = linkList.reverse();
  518. }
  519. linkList.forEach(link => {
  520. dacLinksCon.appendChild(link);
  521. });
  522. };
  523. dacSetCustomRule.onclick = e => {
  524. filterListContainer.classList.add("customRule");
  525. dacCustomInput.value = GM_getValue("DACrules_" + document.domain) || "";
  526. };
  527. dacConfirmRule.onclick = e => {
  528. if (dacCustomInput.value) {
  529. customDown(dacCustomInput.value);
  530. }
  531. };
  532. dacCustomClose.onclick = e => {
  533. filterListContainer.classList.remove("customRule");
  534. };
  535. dacAddUrl.onclick = e => {
  536. let addUrls = window.prompt(i18n.customInfo, "https://xxx.xxx/book-[20-99].html, https://xxx.xxx/book-[01-10].html");
  537. if (!addUrls || !/^http|^ftp/.test(addUrls)) return;
  538. let index = 1;
  539. [].forEach.call(addUrls.split(","), function(i) {
  540. var curEle;
  541. var varNum = /\[\d+\-\d+\]/.exec(i);
  542. if (varNum) {
  543. varNum = varNum[0].trim();
  544. } else {
  545. curEle = document.createElement("a");
  546. curEle.href = i;
  547. curEle.innerText = "Added Url";
  548. createLinkItem(curEle);
  549. return;
  550. }
  551. var num1 = /\[(\d+)/.exec(varNum)[1].trim();
  552. var num2 = /(\d+)\]/.exec(varNum)[1].trim();
  553. var num1Int = parseInt(num1);
  554. var num2Int = parseInt(num2);
  555. var numLen = num1.length;
  556. var needAdd = num1.charAt(0) == "0";
  557. if (num1Int >= num2Int) return;
  558. for (var j = num1Int; j <= num2Int; j++) {
  559. var urlIndex = j.toString();
  560. if (needAdd) {
  561. while(urlIndex.length < numLen) urlIndex = "0" + urlIndex;
  562. }
  563. var curUrl = i.replace(/\[\d+\-\d+\]/, urlIndex).trim();
  564. curEle = document.createElement("a");
  565. curEle.href = curUrl;
  566. curEle.innerText = "Added Url " + index++;
  567. createLinkItem(curEle);
  568. }
  569. });
  570. };
  571. dacStartDownload.onclick = e => {
  572. let linkList = [].slice.call(dacLinksCon.querySelectorAll("input:checked+.dacLink"));
  573. useIframe = !!dacUseIframe.checked;
  574. indexDownload(linkList, true);
  575. filterListContainer.style.display = "none";
  576. };
  577. dacLinksClose.onclick = e => {
  578. filterListContainer.style.display = "none";
  579. };
  580. dacFilterBg.onclick = e => {
  581. filterListContainer.style.display = "none";
  582. };
  583. GM_addStyle(`
  584. #filterListContainer * {
  585. font-size: 13px;
  586. float: initial;
  587. background-image: initial;
  588. }
  589. #filterListContainer.customRule .dacCustomRule {
  590. display: flex;
  591. }
  592. #filterListContainer .dacCustomRule>textarea {
  593. height: 300px;
  594. width: 100%;
  595. border: 1px #DADADA solid;
  596. background: #ededed70;
  597. margin: 5px;
  598. }
  599. #filterListContainer.customRule .dacCustomRule~* {
  600. display: none!important;
  601. }
  602. #dacLinksCon>div {
  603. padding: 5px 0;
  604. display: flex;
  605. }
  606. #dacLinksCon>div>a {
  607. max-width: 245px;
  608. display: inline-block;
  609. text-overflow: ellipsis;
  610. overflow: hidden;
  611. }
  612. #dacLinksCon>div>input {
  613. margin-right: 5px;
  614. }
  615. #filterListContainer .dacCustomRule {
  616. border-radius: 8px;
  617. font-weight: bold;
  618. font-size: 16px;
  619. outline: none;
  620. align-items: center;
  621. flex-wrap: nowrap;
  622. white-space: nowrap;
  623. flex-direction: column;
  624. display: none;
  625. }
  626. #filterListContainer input {
  627. border-width: 2px;
  628. border-style: outset;
  629. border-color: buttonface;
  630. border-image: initial;
  631. border: 1px #DADADA solid;
  632. padding: 5px;
  633. border-radius: 8px;
  634. font-weight: bold;
  635. font-size: 9pt;
  636. outline: none;
  637. cursor: pointer;
  638. }
  639. #dacLinksCon>div:nth-of-type(odd) {
  640. background: #ffffff;
  641. }
  642. #dacLinksCon>div:nth-of-type(even) {
  643. background: #f5f5f5;
  644. }
  645. #filterListContainer .fun,#filterListContainer .sort {
  646. display: flex;
  647. justify-content: space-around;
  648. flex-wrap: nowrap;
  649. width: 100%;
  650. }
  651. #filterListContainer input[type=button]:hover {
  652. border: 1px #C6C6C6 solid;
  653. box-shadow: 1px 1px 1px #EAEAEA;
  654. color: #333333;
  655. background: #F7F7F7;
  656. }
  657. #filterListContainer input[type=button]:active {
  658. box-shadow: inset 1px 1px 1px #DFDFDF;
  659. }
  660. `);
  661. dacLinksCon = filterListContainer.querySelector("#dacLinksCon");
  662. }
  663. list.forEach(a => {
  664. createLinkItem(a);
  665. });
  666. dacUseIframe.checked = useIframe;
  667. }
  668.  
  669. function initTxtDownDiv(){
  670. if(txtDownContent){
  671. txtDownContent.style.display="";
  672. return;
  673. }
  674. txtDownContent=document.createElement("div");
  675. txtDownContent.id="txtDownContent";
  676. document.body.appendChild(txtDownContent);
  677. txtDownContent.innerHTML=createHTML(`
  678. <div style="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;">
  679. <div id="txtDownWords" style="position:absolute;width:275px;height: 90px;max-height: 90%;border: 1px solid #f3f1f1;padding: 8px;border-radius: 10px;overflow: auto;">
  680. Analysing......
  681. </div>
  682. <div id="txtDownQuit" style="width: 30px;height: 30px;border-radius: 30px;position:absolute;right:2px;top:2px;cursor: pointer;background-color:#ff5a5a;">
  683. <span style="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;">╳</span>
  684. </div>
  685. <div style="position:absolute;right:0px;bottom:2px;cursor: pointer;max-width:85px">
  686. <button id="abortRequest" style="background: #008aff;border: 0;padding: 5px;border-radius: 6px;color: white;float: right;margin: 1px;height: 25px;display:none;line-height: 16px;">${getI18n('abort')}</button>
  687. <button id="tempSaveTxt" style="background: #008aff;border: 0;padding: 5px;border-radius: 6px;color: white;float: right;margin: 1px;height: 25px;line-height: 16px;cursor: pointer;">${getI18n('save')}</button>
  688. <button id="saveAsMd" style="background: #008aff;border: 0;padding: 5px;border-radius: 6px;color: white;float: right;margin: 1px;height: 25px;line-height: 16px;cursor: pointer;overflow: hidden;" title="${getI18n('saveAsMd')}">Markdown</button>
  689. </div>
  690. </div>`);
  691. txtDownWords=txtDownContent.querySelector("#txtDownWords");
  692. txtDownQuit=txtDownContent.querySelector("#txtDownQuit");
  693. txtDownQuit.onclick=function(){
  694. txtDownContent.style.display="none";
  695. };
  696. initTempSave();
  697. }
  698.  
  699. function saveContent() {
  700. if (win.downloadAllContentSaveAsZip) {
  701. win.downloadAllContentSaveAsZip(rCats, i18n.info, content => {
  702. saveAs(content, document.title + ".zip");
  703. });
  704. } else {
  705. var blob = new Blob([i18n.info + "\r\n\r\n" + document.title + "\r\n\r\n" + rCats.join("\r\n\r\n")], {type: "text/plain;charset=utf-8"});
  706. saveAs(blob, document.title + ".txt");
  707. }
  708. }
  709.  
  710. function initTempSave(){
  711. var tempSavebtn = document.getElementById('tempSaveTxt');
  712. var abortbtn = document.getElementById('abortRequest');
  713. var saveAsMd = document.getElementById('saveAsMd');
  714. tempSavebtn.onclick = function(){
  715. saveContent();
  716. console.log(curRequests);
  717. }
  718. abortbtn.onclick = function(){
  719. let curRequest = curRequests.pop();
  720. if(curRequest)curRequest[1].abort();
  721. }
  722. saveAsMd.onclick = function(){
  723. let txt = i18n.info+"\n\n---\n"+document.title+"\n===\n";
  724. rCats.forEach(cat => {
  725. cat = cat.replace("\r\n", "\n---").replace(/(\r\n|\n\r)+/g, "\n\n").replace(/[\n\r]\t+/g, "\n");
  726. txt += '\n\n'+cat;
  727. });
  728. var blob = new Blob([txt], {type: "text/plain;charset=utf-8"});
  729. saveAs(blob, document.title+".md");
  730. }
  731. }
  732.  
  733. function indexDownload(aEles, noSort){
  734. if(aEles.length<1)return;
  735. initTxtDownDiv();
  736. if(!noSort) {
  737. if(GM_getValue("contentSort")){
  738. aEles.sort((a, b) => {
  739. return str2Num(a.innerText) - str2Num(b.innerText);
  740. });
  741. }
  742. if(GM_getValue("contentSortUrl")){
  743. aEles.sort((a, b) => {
  744. const nameA = a.href.toUpperCase();
  745. const nameB = b.href.toUpperCase();
  746. if (nameA < nameB) {
  747. return -1;
  748. }
  749. if (nameA > nameB) {
  750. return 1;
  751. }
  752. return 0;
  753. });
  754. }
  755. if(GM_getValue("reverse")){
  756. aEles=aEles.reverse();
  757. }
  758. }
  759. rCats=[];
  760. var minTxtLength=GM_getValue("minTxtLength") || 100;
  761. var customTitle=GM_getValue("customTitle");
  762. var disableNextPage=!!GM_getValue("disableNextPage");
  763. var customNextPageReg=GM_getValue("nextPageReg");
  764. if (customNextPageReg) {
  765. try {
  766. innerNextPage = new RegExp(customNextPageReg);
  767. } catch(e) {
  768. console.warn(e);
  769. }
  770. }
  771. var insertSigns=[];
  772. // var j=0,rCats=[];
  773. var downIndex=0,downNum=0,downOnce=function(wait){
  774. if(downNum>=aEles.length)return;
  775. let curIndex=downIndex;
  776. let aTag=aEles[curIndex];
  777. let request=(aTag, curIndex)=>{
  778. let tryTimes=0;
  779. let validTimes=0;
  780. let requestBody={
  781. method: 'GET',
  782. url: aTag.href,
  783. headers:{
  784. referer:aTag.href,
  785. "Content-Type":"text/html;charset="+document.charset
  786. },
  787. timeout:10000,
  788. overrideMimeType:"text/html;charset="+document.charset,
  789. onload: function(result) {
  790. downIndex++;
  791. downNum++;
  792. let doc = getDocEle(result.responseText);
  793. let base = doc.querySelector("base");
  794. let nextPage = !disableNextPage && !processFunc && checkNextPage(doc, base ? base.href : aTag.href);
  795. if(nextPage){
  796. var inArr=false;
  797. for(var ai=0;ai<aEles.length;ai++){
  798. if(aEles[ai].href==nextPage.href){
  799. inArr=true;
  800. break;
  801. }
  802. }
  803. if(!inArr){
  804. nextPage.innerText=aTag.innerText+"\t>>";
  805. aEles.push(nextPage);
  806. let targetIndex = curIndex;
  807. for(let a=0;a<insertSigns.length;a++){
  808. let signs=insertSigns[a],breakSign=false;
  809. if(signs){
  810. for(let b=0;b<signs.length;b++){
  811. let sign=signs[b];
  812. if(sign==curIndex){
  813. targetIndex=a;
  814. breakSign=true;
  815. break;
  816. }
  817. }
  818. }
  819. if(breakSign)break;
  820. }
  821. let insertSign = insertSigns[targetIndex];
  822. if(!insertSign)insertSigns[targetIndex] = [];
  823. insertSigns[targetIndex].push(aEles.length-1);
  824. }
  825. }
  826. if (result.status >= 400) {
  827. console.warn("error:", `status: ${result.status} from: ${aTag.href}`);
  828. } else {
  829. console.log(result.status);
  830. }
  831. if (customTitle) {
  832. try {
  833. let title = doc.querySelector(customTitle);
  834. if (title && title.innerText) {
  835. aTag.innerText = title.innerText;
  836. }
  837. } catch(e) {
  838. console.warn(e);
  839. }
  840. }
  841. let validData = processDoc(curIndex, aTag, doc, (result.status>=400?` status: ${result.status} from: ${aTag.href} `:""), validTimes < 5);
  842. if (!validData && validTimes++ < 5) {
  843. downIndex--;
  844. downNum--;
  845. setTimeout(() => {
  846. GM_xmlhttpRequest(requestBody);
  847. }, 500);
  848. return;
  849. }
  850. if (wait) {
  851. setTimeout(() => {
  852. downOnce(wait);
  853. }, wait);
  854. } else downOnce();
  855. },
  856. onerror: function(e) {
  857. console.warn("error:", e);
  858. if(tryTimes++ < 5){
  859. setTimeout(() => {
  860. GM_xmlhttpRequest(requestBody);
  861. }, 500);
  862. return;
  863. }
  864. downIndex++;
  865. downNum++;
  866. processDoc(curIndex, aTag, null, ` NETWORK ERROR: '+${(e.response||e.responseText)} from: ${aTag.href} `);
  867. if (wait) {
  868. setTimeout(() => {
  869. downOnce(wait);
  870. }, wait);
  871. } else downOnce();
  872. },
  873. ontimeout: function(e) {
  874. console.warn("timeout: times="+tryTimes+" url="+aTag.href);
  875. //console.log(e);
  876. if(tryTimes++ < 5){
  877. setTimeout(() => {
  878. GM_xmlhttpRequest(requestBody);
  879. }, 500);
  880. return;
  881. }
  882. downIndex++;
  883. downNum++;
  884. processDoc(curIndex, aTag, null, ` TIMEOUT: '+${aTag.href} `);
  885. if (wait) {
  886. setTimeout(() => {
  887. downOnce(wait);
  888. }, wait);
  889. } else downOnce();
  890. }
  891. };
  892. if (useIframe) {
  893. let iframe = document.createElement('iframe');
  894. iframe.name = 'pagetual-iframe';
  895. iframe.width = '100%';
  896. iframe.height = '1000';
  897. iframe.frameBorder = '0';
  898. iframe.sandbox = iframeSandbox || "allow-same-origin allow-scripts allow-popups allow-forms";
  899. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;flex:0;opacity:0!important;pointer-events:none!important;position:fixed;top:0px;left:0px;z-index:-2147483647;';
  900. iframe.addEventListener('load', e => {
  901. if (e.data != 'pagetual-iframe:DOMLoaded' && e.type != 'load') return;
  902. let tryTimes = 0;
  903. function checkIframe() {
  904. try {
  905. let doc = iframe.contentDocument || iframe.contentWindow.document;
  906. doc.body.scrollTop = 9999999;
  907. doc.documentElement.scrollTop = 9999999;
  908. if (validTimes++ > 10) {
  909. iframe.src = iframe.src;
  910. validTimes = 0;
  911. return;
  912. }
  913. if (customTitle) {
  914. try {
  915. let title = doc.querySelector(customTitle);
  916. if (title && title.innerText) {
  917. aTag.innerText = title.innerText;
  918. }
  919. } catch(e) {
  920. console.warn(e);
  921. }
  922. }
  923. downIndex++;
  924. downNum++;
  925. let validData = processDoc(curIndex, aTag, doc, "", true);
  926. if (!validData) {
  927. downIndex--;
  928. downNum--;
  929. setTimeout(() => {
  930. checkIframe();
  931. }, 500);
  932. return;
  933. }
  934. if (wait) {
  935. setTimeout(() => {
  936. downOnce(wait);
  937. }, wait);
  938. } else downOnce();
  939. } catch(e) {
  940. console.debug("Stop as cors");
  941. }
  942. if (iframe && iframe.parentNode) iframe.parentNode.removeChild(iframe);
  943. }
  944. setTimeout(() => {
  945. checkIframe();
  946. }, 500);
  947. }, false);
  948. let checkReady = setInterval(() => {
  949. let doc;
  950. try {
  951. doc = iframe.contentDocument || (iframe.contentWindow && iframe.contentWindow.document);
  952. } catch(e) {
  953. clearInterval(checkReady);
  954. return;
  955. }
  956. if (doc) {
  957. try {
  958. Function('win', 'iframe', '"use strict";' + (iframeInit || "win.self=win.top;"))(iframe.contentWindow, iframe);
  959. clearInterval(checkReady);
  960. } catch(e) {
  961. console.debug(e);
  962. }
  963. }
  964. }, 50);
  965. iframe.src = aTag.href;
  966. document.body.appendChild(iframe);
  967. return [curIndex, null, aTag.href];
  968. } else {
  969. return [curIndex, GM_xmlhttpRequest(requestBody), aTag.href];
  970. }
  971. }
  972. if(!aTag){
  973. let waitAtagReadyInterval=setInterval(function(){
  974. if(downNum>=aEles.length)clearInterval(waitAtagReadyInterval);
  975. aTag=aEles[curIndex];
  976. if(aTag){
  977. clearInterval(waitAtagReadyInterval);
  978. request(aTag, curIndex);
  979. }
  980. },1000);
  981. return null;
  982. }
  983. let result = request(aTag, curIndex);
  984. if (result) curRequests.push(result);
  985. return result;
  986. };
  987. function getDocEle(str){
  988. var doc = null;
  989. try {
  990. doc = document.implementation.createHTMLDocument('');
  991. doc.documentElement.innerHTML = str;
  992. }
  993. catch (e) {
  994. console.log('parse error');
  995. }
  996. return doc;
  997. }
  998. function sortInnerPage(){
  999. var pageArrs=[],maxIndex=0,i,j;
  1000. for(i=0;i<insertSigns.length;i++){
  1001. var signs=insertSigns[i];
  1002. if(signs){
  1003. for(j=0;j<signs.length;j++){
  1004. var sign=signs[j];
  1005. var cat=rCats[sign];
  1006. rCats[sign]=null;
  1007. if(!pageArrs[i])pageArrs[i]=[];
  1008. pageArrs[i].push(cat);
  1009. }
  1010. }
  1011. }
  1012. for(i=pageArrs.length-1;i>=0;i--){
  1013. let pageArr=pageArrs[i];
  1014. if(pageArr){
  1015. for(j=pageArr.length-1;j>=0;j--){
  1016. rCats.splice(i+1, 0, pageArr[j]);
  1017. }
  1018. }
  1019. }
  1020. rCats = rCats.filter(function(e){return e!=null});
  1021. }
  1022. var waitForComplete;
  1023. function processDoc(i, aTag, doc, cause, check){
  1024. let cbFunc=content=>{
  1025. rCats[i]=(aTag.innerText.replace(/[\r\n\t]/g, "") + "\r\n" + (cause || '') + content.replace(/\s*$/, ""));
  1026. curRequests = curRequests.filter(function(e){return e[0]!=i});
  1027. txtDownContent.style.display="block";
  1028. txtDownWords.innerHTML=getI18n("downloading",[downNum,(aEles.length-downNum),aTag.innerText]);
  1029. if(downNum==aEles.length){
  1030. if(waitForComplete) clearTimeout(waitForComplete);
  1031. waitForComplete=setTimeout(()=>{
  1032. if(downNum==aEles.length){
  1033. txtDownWords.innerHTML=getI18n("complete",[downNum]);
  1034. sortInnerPage();
  1035. saveContent();
  1036. }
  1037. },3000);
  1038. }
  1039. };
  1040. let contentResult=getPageContent(doc, content=>{
  1041. cbFunc(content);
  1042. }, aTag.href);
  1043. if(contentResult!==false){
  1044. if(check && contentResult && contentResult.replace(/\s/g, "").length<minTxtLength){
  1045. return false;
  1046. }
  1047. cbFunc(contentResult);
  1048. }
  1049. return true;
  1050. }
  1051. var downThreadNum = parseInt(GM_getValue("downThreadNum"));
  1052. downThreadNum = downThreadNum || 20;
  1053. if (useIframe && downThreadNum > 5) {
  1054. downThreadNum = 5;
  1055. }
  1056. if (downThreadNum > 0) {
  1057. for (var i = 0; i < downThreadNum; i++) {
  1058. downOnce();
  1059. if (downIndex >= aEles.length - 1 || downIndex >= downThreadNum - 1) break;
  1060. else downIndex++;
  1061. }
  1062. } else {
  1063. downOnce(-downThreadNum * 1000);
  1064. if (downIndex < aEles.length - 1 && downIndex < downThreadNum - 1) downIndex++;
  1065. }
  1066.  
  1067. /*for(let i=0;i<aEles.length;i++){
  1068. let aTag=aEles[i];
  1069. GM_xmlhttpRequest({
  1070. method: 'GET',
  1071. url: aTag.href,
  1072. overrideMimeType:"text/html;charset="+document.charset,
  1073. onload: function(result) {
  1074. var doc = getDocEle(result.responseText);
  1075. processDoc(i, aTag, doc);
  1076. }
  1077. });
  1078. }*/
  1079. }
  1080.  
  1081. function canonicalUri(src, baseUrl) {
  1082. if (!src) {
  1083. return "";
  1084. }
  1085. if (src.charAt(0) == "#") return baseUrl + src;
  1086. if (src.charAt(0) == "?") return baseUrl.replace(/^([^\?#]+).*/, "$1" + src);
  1087. let origin = location.protocol + '//' + location.host;
  1088. let url = baseUrl || origin;
  1089. url = url.replace(/(\?|#).*/, "");
  1090. if (/https?:\/\/[^\/]+$/.test(url)) url = url + '/';
  1091. if (url.indexOf("http") !== 0) url = origin + url;
  1092. var root_page = /^[^\?#]*\//.exec(url)[0],
  1093. root_domain = /^\w+\:\/\/\/?[^\/]+/.exec(root_page)[0],
  1094. absolute_regex = /^\w+\:\/\//;
  1095. while (src.indexOf("../") === 0) {
  1096. src = src.substr(3);
  1097. root_page = root_page.replace(/\/[^\/]+\/$/, "/");
  1098. }
  1099. src = src.replace(/\.\//, "");
  1100. if (/^\/\/\/?/.test(src)) {
  1101. src = location.protocol + src;
  1102. }
  1103. return (absolute_regex.test(src) ? src : ((src.charAt(0) == "/" ? root_domain : root_page) + src));
  1104. }
  1105.  
  1106. function checkNextPage(doc, baseUrl) {
  1107. let aTags = doc.querySelectorAll("a"), nextPage = null;
  1108. for (var i = 0; i < aTags.length; i++) {
  1109. let aTag = aTags[i];
  1110. if (innerNextPage.test(aTag.innerText) && aTag.href && !/javascript:|#/.test(aTag.href)) {
  1111. let nextPageHref = canonicalUri(aTag.getAttribute("href"), baseUrl || location.href);
  1112. if (nextPageHref != location.href) {
  1113. nextPage = aTag;
  1114. nextPage.href = nextPageHref;
  1115. break;
  1116. }
  1117. }
  1118. }
  1119. return nextPage;
  1120. }
  1121.  
  1122. function textNodesUnder(el){
  1123. var n, a=[], walk=document.createTreeWalker(el,NodeFilter.SHOW_TEXT,null,false);
  1124. while(n=walk.nextNode()) a.push(n);
  1125. return a;
  1126. }
  1127.  
  1128. function getPageContent(doc, cb, url){
  1129. if(!doc)return i18n.error;
  1130. if(processFunc){
  1131. return processFunc(doc, cb, url);
  1132. }
  1133. [].forEach.call(doc.querySelectorAll("span,div,ul"),function(item){
  1134. var thisStyle=doc.defaultView?doc.defaultView.getComputedStyle(item):item.style;
  1135. if(thisStyle && (thisStyle.display=="none" || (item.nodeName=="SPAN" && thisStyle.fontSize=="0px"))){
  1136. item.innerHTML="";
  1137. }
  1138. });
  1139. var i,j,k,rStr="",pageData=(doc.body?doc.body:doc).cloneNode(true),delList=[];
  1140. pageData.innerHTML=pageData.innerHTML.replace(/\<\!\-\-((.|[\n|\r|\r\n])*?)\-\-\>/g,"");
  1141. [].forEach.call(pageData.querySelectorAll("font.jammer"),function(item){
  1142. item.innerHTML="";
  1143. });
  1144. var selectors=GM_getValue("selectors");
  1145. if(selectors){
  1146. [].forEach.call(pageData.querySelectorAll(selectors),function(item){
  1147. item.innerHTML="";
  1148. });
  1149. }
  1150. [].forEach.call(pageData.querySelectorAll("script,style,link,img,noscript,iframe"),function(item){delList.push(item);});
  1151. [].forEach.call(delList,function(item){item.innerHTML="";});
  1152. var endEle = ele => {
  1153. return /^(I|STRONG|B|FONT|P|DL|DD|H\d)$/.test(ele.nodeName) && ele.children.length <= 1;
  1154. };
  1155. var largestContent,contents=pageData.querySelectorAll("span,div,article,p,td"),largestNum=0;
  1156. for(i=0;i<contents.length;i++){
  1157. let content=contents[i],hasText=false,allSingle=true,item,curNum=0;
  1158. if(/footer/.test(content.className))continue;
  1159. for(j=content.childNodes.length-1;j>=0;j--){
  1160. item=content.childNodes[j];
  1161. if(item.nodeType==3){
  1162. if(/^\s*$/.test(item.data)){
  1163. item.innerHTML="";
  1164. }else hasText=true;
  1165. }else if(/^(I|A|STRONG|B|FONT|P|DL|DD|H\d)$/.test(item.nodeName)){
  1166. hasText=true;
  1167. }else if(item.nodeType==1&&item.children.length==1&&/^(I|A|STRONG|B|FONT|P|DL|DD|H\d)$/.test(item.children[0].nodeName)){
  1168. hasText=true;
  1169. }
  1170. }
  1171. for(j=content.childNodes.length-1;j>=0;j--){
  1172. item=content.childNodes[j];
  1173. if(item.nodeType==1 && !/^(I|A|STRONG|B|FONT|BR)$/.test(item.nodeName) && /^[\s\-\_\?\>\|]*$/.test(item.innerHTML)){
  1174. item.innerHTML="";
  1175. }
  1176. }
  1177. if(content.childNodes.length>1){
  1178. let indexItem=0;
  1179. for(j=0;j<content.childNodes.length;j++){
  1180. item=content.childNodes[j];
  1181. if(item.nodeType==1){
  1182. if(item.innerText && item.innerText.length<50 && indexReg.test(item.innerText))indexItem++;
  1183. for(k=0;k<item.childNodes.length;k++){
  1184. var childNode=item.childNodes[k];
  1185. if(childNode.nodeType!=3 && !/^(I|A|STRONG|B|FONT|BR)$/.test(childNode.nodeName)){
  1186. allSingle=false;
  1187. break;
  1188. }
  1189. }
  1190. if(!allSingle)break;
  1191. }
  1192. }
  1193. if(indexItem>=5)continue;
  1194. }else{
  1195. allSingle=false;
  1196. }
  1197. if(!allSingle && !hasText){
  1198. continue;
  1199. }else {
  1200. if(pageData==document && content.offsetWidth<=0 && content.offsetHeight<=0){
  1201. continue;
  1202. }
  1203. [].forEach.call(content.childNodes,function(item){
  1204. if(item.nodeType==3)curNum+=item.data.trim().length;
  1205. else if(endEle(item) || (item.nodeType == 1 && item.children.length == 1 && endEle(item.children[0]))) curNum += (firefox ? item.textContent.trim().length : item.innerText.trim().length);
  1206. });
  1207. }
  1208. if(curNum>largestNum){
  1209. largestNum=curNum;
  1210. largestContent=content;
  1211. }
  1212. }
  1213. if(!largestContent)return i18n.error+" : NO TEXT CONTENT";
  1214. var retainImage=!!GM_getValue("retainImage");
  1215. var childlist=pageData.querySelectorAll(largestContent.nodeName);//+(largestContent.className?"."+largestContent.className.replace(/(^\s*)|(\s*$)/g, '').replace(/\s+/g, '.'):""));
  1216. function getRightStr(ele, noTextEnable){
  1217. if(retainImage){
  1218. [].forEach.call(ele.querySelectorAll("img[src]"), img => {
  1219. let imgTxtNode=document.createTextNode(`![img](${canonicalUri(img.getAttribute("src"), url || location.href)})`);
  1220. img.parentNode.replaceChild(imgTxtNode, img);
  1221. });
  1222. }
  1223. let childNodes=ele.childNodes,cStr="\r\n",hasText=false;
  1224. [].forEach.call(ele.querySelectorAll("a[href]"), a => {
  1225. a.parentNode && a.parentNode.removeChild(a);
  1226. });
  1227. for(let j=0;j<childNodes.length;j++){
  1228. let childNode=childNodes[j];
  1229. if(childNode.nodeType==3 && childNode.data && !/^[\s\-\_\?\>\|]*$/.test(childNode.data))hasText=true;
  1230. if(childNode.innerHTML){
  1231. childNode.innerHTML=childNode.innerHTML.replace(/\<\s*br\s*\>/gi,"\r\n").replace(/\n+/gi,"\n").replace(/\r+/gi,"\r");
  1232. }
  1233. let content=childNode.textContent;
  1234. if(content){
  1235. if(!content.trim())continue;
  1236. cStr+=content.replace(/ +/g," ").replace(/([^\r]|^)\n([^\r]|$)/gi,"$1\r\n$2");
  1237. }
  1238. if(childNode.nodeType!=3 && !/^(I|A|STRONG|B|FONT|IMG)$/.test(childNode.nodeName))cStr+="\r\n";
  1239. }
  1240. if(hasText || noTextEnable || ele==largestContent)rStr+=cStr+"\r\n";
  1241. }
  1242. for(i=0;i<childlist.length;i++){
  1243. var child=childlist[i];
  1244. if(getDepth(child)==getDepth(largestContent)){
  1245. if(largestContent.className != child.className)continue;
  1246. if((largestContent.className && largestContent.className == child.className) || largestContent.parentNode == child.parentNode){
  1247. getRightStr(child, true);
  1248. }else {
  1249. getRightStr(child, false);
  1250. }
  1251. }
  1252. }
  1253. return rStr.replace(/[\n\r]+/g,"\n\r");
  1254. }
  1255.  
  1256. function getI18n(key, args){
  1257. var resultStr=i18n[key];
  1258. if(args && args.length>0){
  1259. args.forEach(function(item){
  1260. resultStr=resultStr.replace(/%s/,item);
  1261. });
  1262. }
  1263. return resultStr;
  1264. }
  1265.  
  1266. function getDepth(dom){
  1267. var pa=dom,i=0;
  1268. while(pa.parentNode){
  1269. pa=pa.parentNode;
  1270. i++;
  1271. }
  1272. return i;
  1273. }
  1274.  
  1275. function fetch(forceSingle){
  1276. forceSingle=forceSingle===true;
  1277. processFunc=null;
  1278. var aEles=document.body.querySelectorAll("a"),list=[];
  1279. for(var i=0;i<aEles.length;i++){
  1280. var aEle=aEles[i],has=false;
  1281. if((!aEle.href || aEle.href.indexOf("javascript")!=-1) && aEle.dataset.href){
  1282. aEle.href=aEle.dataset.href;
  1283. }
  1284. if(aEle.href==location.href)continue;
  1285. for(var j=0;j<list.length;j++){
  1286. if(list[j].href==aEle.href){
  1287. aEle=list[j];
  1288. list.splice(j,1);
  1289. list.push(aEle);
  1290. has=true;
  1291. break;
  1292. }
  1293. }
  1294. if(!has && aEle.href && /^http/i.test(aEle.href) && ((aEle.innerText.trim()!="" && indexReg.test(aEle.innerText.trim())) || /chapter[\-_]?\d/.test(aEle.href))){
  1295. list.push(aEle);
  1296. }
  1297. }
  1298. if(list.length>2 && !forceSingle){
  1299. useIframe = false;
  1300. filterList(list);
  1301. }else{
  1302. var blob = new Blob([i18n.info+"\r\n\r\n"+document.title+"\r\n\r\n"+getPageContent(document)], {type: "text/plain;charset=utf-8"});
  1303. saveAs(blob, document.title+".txt");
  1304. }
  1305. }
  1306.  
  1307. function customDown(urls){
  1308. processFunc = null;
  1309. useIframe = false;
  1310. if(urls){
  1311. urls=decodeURIComponent(urls.replace(/%/g,'%25'));
  1312. GM_setValue("DACrules_"+document.domain, urls);
  1313. var processEles=[];
  1314. let urlsArr=urls.split("@@"),eles=[];
  1315. if(/^http|^ftp/.test(urlsArr[0])){
  1316. [].forEach.call(urlsArr[0].split(","),function(i){
  1317. var curEle;
  1318. var varNum=/\[\d+\-\d+\]/.exec(i);
  1319. if(varNum){
  1320. varNum=varNum[0].trim();
  1321. }else{
  1322. curEle=document.createElement("a");
  1323. curEle.href=i;
  1324. curEle.innerText="Added Url";
  1325. processEles.push(curEle);
  1326. return;
  1327. }
  1328. var num1=/\[(\d+)/.exec(varNum)[1].trim();
  1329. var num2=/(\d+)\]/.exec(varNum)[1].trim();
  1330. var num1Int=parseInt(num1);
  1331. var num2Int=parseInt(num2);
  1332. var numLen=num1.length;
  1333. var needAdd=num1.charAt(0)=="0";
  1334. if(num1Int>=num2Int)return;
  1335. for(var j=num1Int;j<=num2Int;j++){
  1336. var urlIndex=j.toString();
  1337. if(needAdd){
  1338. while(urlIndex.length<numLen)urlIndex="0"+urlIndex;
  1339. }
  1340. var curUrl=i.replace(/\[\d+\-\d+\]/,urlIndex).trim();
  1341. curEle=document.createElement("a");
  1342. curEle.href=curUrl;
  1343. curEle.innerText="Added Url " + processEles.length.toString();
  1344. processEles.push(curEle);
  1345. }
  1346. });
  1347. }else{
  1348. let urlSel=urlsArr[0].split(">>");
  1349. try{
  1350. eles=document.querySelectorAll(urlSel[0]);
  1351. eles=[].filter.call(eles, ele=>{
  1352. return ele.nodeName=='BODY'||(!!ele.offsetParent&&getComputedStyle(ele).display!=='none');
  1353. })
  1354. }catch(e){}
  1355. if(eles.length==0){
  1356. eles=[];
  1357. var eleTxts=urlsArr[0].split(/(?<=[^\\])[,,]/),exmpEles=[],excludeTxts={};
  1358. [].forEach.call(document.querySelectorAll("a"),function(item){
  1359. if(!item.offsetParent)return;
  1360. eleTxts.forEach(txt=>{
  1361. var txtArr=txt.split("!");
  1362. if(item.innerText.indexOf(txtArr[0])!=-1){
  1363. exmpEles.push(item);
  1364. excludeTxts[item]=txtArr.splice(1);
  1365. }
  1366. });
  1367. })
  1368. exmpEles.forEach(e=>{
  1369. var cssSelStr="a",pa=e.parentNode,excludeTxt=excludeTxts[e];
  1370. if(e.className)cssSelStr+="."+CSS.escape(e.className);
  1371. while(pa && pa.nodeName!="BODY"){
  1372. cssSelStr=pa.nodeName+">"+cssSelStr;
  1373. pa=pa.parentNode;
  1374. }
  1375. cssSelStr="body>"+cssSelStr;;
  1376. [].forEach.call(document.querySelectorAll(cssSelStr),function(item){
  1377. if(!item.offsetParent)return;
  1378. var isExclude=false;
  1379. for(var t in excludeTxt){
  1380. if(item.innerText.indexOf(excludeTxt[t])!=-1){
  1381. isExclude=true;
  1382. break;
  1383. }
  1384. }
  1385. if(!isExclude && eles.indexOf(item)==-1){
  1386. eles.push(item);
  1387. }
  1388. });
  1389. });
  1390. }
  1391. function addItem(item) {
  1392. let has=false;
  1393. for(var j=0;j<processEles.length;j++){
  1394. if(processEles[j].href==item.href){
  1395. processEles.splice(j,1);
  1396. processEles.push(item);
  1397. has=true;
  1398. break;
  1399. }
  1400. }
  1401. if((!item.href || item.href.indexOf("javascript")!=-1) && item.dataset.href){
  1402. item.href=item.dataset.href;
  1403. }
  1404. if(!has && item.href && /^http/i.test(item.href)){
  1405. processEles.push(item.cloneNode(1));
  1406. }
  1407. }
  1408. [].forEach.call(eles,function(item){
  1409. if(urlSel[1]){
  1410. item=Function("item",urlSel[1])(item);
  1411. let items;
  1412. if (Array.isArray(item)) {
  1413. items = item;
  1414. } else items = [item];
  1415. items.forEach(item => {
  1416. if(!item || !item.href)return;
  1417. if(!item.nodeName || item.nodeName!="A"){
  1418. let href=item.href;
  1419. let innerText=item.innerText;
  1420. item=document.createElement("a");
  1421. item.href=href;
  1422. item.innerText=innerText;
  1423. }
  1424. addItem(item);
  1425. });
  1426. } else {
  1427. addItem(item);
  1428. }
  1429. });
  1430. }
  1431. if(urlsArr[1]){
  1432. processEles.forEach(ele=>{
  1433. ele.href=ele.href.replace(new RegExp(urlsArr[1]), urlsArr[2]);
  1434. });
  1435. }
  1436. var retainImage=!!GM_getValue("retainImage");
  1437. var evalCode = urlsArr[3];
  1438. if (evalCode && /^iframe:/.test(evalCode.trim())) {
  1439. evalCode = evalCode.trim().replace("iframe:", "");
  1440. useIframe = true;
  1441. iframeSandbox = false;
  1442. iframeInit = false;
  1443. while (/^(sandbox|init):/.test(evalCode)) {
  1444. iframeSandbox = evalCode.match(/^sandbox:{(.*?)}/);
  1445. if (iframeSandbox) {
  1446. iframeSandbox = iframeSandbox[1];
  1447. evalCode = evalCode.replace(/^sandbox:{(.*?)}/, "");
  1448. }
  1449. iframeInit = evalCode.match(/^init:{(.*?)}/);
  1450. if (iframeInit) {
  1451. iframeInit = iframeInit[1];
  1452. evalCode = evalCode.replace(/^init:{(.*?)}/, "");
  1453. }
  1454. }
  1455. }
  1456. if(evalCode){
  1457. processFunc=(data, cb, url)=>{
  1458. let doc=data;
  1459. if(evalCode.indexOf("return ")==-1){
  1460. if(evalCode.indexOf("@")==0){
  1461. let content="";
  1462. if(retainImage){
  1463. [].forEach.call(data.querySelectorAll("img[src]"), img => {
  1464. let imgTxt=`![img](${canonicalUri(img.getAttribute("src"), location.href)})`;
  1465. let imgTxtNode=document.createTextNode(imgTxt);
  1466. img.parentNode.replaceChild(imgTxtNode, img);
  1467. });
  1468. }
  1469. [].forEach.call(data.querySelectorAll(evalCode.slice(1)), ele=>{
  1470. [].forEach.call(ele.childNodes, child=>{
  1471. if(child.innerHTML){
  1472. child.innerHTML=child.innerHTML.replace(/\<\s*br\s*\>/gi,"\r\n").replace(/\n+/gi,"\n").replace(/\r+/gi,"\r");
  1473. }
  1474. if(child.textContent){
  1475. content+=(child.textContent.replace(/ +/g," ").replace(/([^\r]|^)\n([^\r]|$)/gi,"$1\r\n$2")+"\r\n");
  1476. }
  1477. });
  1478. content+="\r\n";
  1479. });
  1480. return content;
  1481. }else return eval(evalCode);
  1482. }else{
  1483. return Function("data", "doc", "cb", "url", evalCode)(data, doc, cb, url);
  1484. }
  1485. };
  1486. }else{
  1487. if(win.dacProcess){
  1488. processFunc=win.dacProcess;
  1489. }
  1490. }
  1491. filterList(processEles);
  1492. }
  1493. }
  1494. const configPage = "https://hoothin.github.io/UserScripts/DownloadAllContent/";
  1495. const copySvg = '<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" style="transition: all ease 0.5s;top: 5px;right: 5px;position: absolute;cursor: pointer;"><title>Copy</title><path d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 0 1 0 1.5h-1.5a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-1.5a.75.75 0 0 1 1.5 0v1.5A1.75 1.75 0 0 1 9.25 16h-7.5A1.75 1.75 0 0 1 0 14.25Z"></path><path d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0 1 14.25 11h-7.5A1.75 1.75 0 0 1 5 9.25Zm1.75-.25a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-7.5a.25.25 0 0 0-.25-.25Z"></path></svg>';
  1496. function searchRule(){
  1497. GM_openInTab(configPage + "#@" + location.hostname, {active: true});
  1498. }
  1499. if (location.origin + location.pathname == configPage) {
  1500. let exampleNode = document.getElementById("example");
  1501. if (!exampleNode) return;
  1502.  
  1503. exampleNode = exampleNode.parentNode;
  1504. let ruleList = exampleNode.nextElementSibling.nextElementSibling;
  1505. let searchInput = document.createElement("input");
  1506. let inputTimer;
  1507. function searchByInput() {
  1508. clearTimeout(inputTimer);
  1509. inputTimer = setTimeout(() => {
  1510. let curValue = searchInput.value;
  1511. let matchRules = [];
  1512. let dontMatchRules = [];
  1513. if (curValue) {
  1514. for (let i = 0; i < ruleList.children.length; i++) {
  1515. let curRule = ruleList.children[i];
  1516. let aHref = curRule.firstChild.href;
  1517. if (aHref.indexOf(curValue) == -1) {
  1518. dontMatchRules.push(curRule);
  1519. } else {
  1520. matchRules.push(curRule);
  1521. }
  1522. }
  1523. } else {
  1524. dontMatchRules = ruleList.children;
  1525. }
  1526. if (matchRules.length) {
  1527. for (let i = 0; i < dontMatchRules.length; i++) {
  1528. let curRule = dontMatchRules[i];
  1529. curRule.style.display = "none";
  1530. }
  1531. for (let i = 0; i < matchRules.length; i++) {
  1532. let curRule = matchRules[i];
  1533. curRule.style.display = "";
  1534. }
  1535. } else {
  1536. for (let i = 0; i < dontMatchRules.length; i++) {
  1537. let curRule = dontMatchRules[i];
  1538. curRule.style.display = "";
  1539. }
  1540. }
  1541. }, 500);
  1542. }
  1543. searchInput.style.margin = "10px";
  1544. searchInput.style.width = "100%";
  1545. searchInput.placeholder = i18n.searchRule;
  1546. searchInput.addEventListener("input", function(e) {
  1547. searchByInput();
  1548. });
  1549. if (location.hash) {
  1550. let hash = location.hash.slice(1);
  1551. if (hash.indexOf("@") == 0) {
  1552. setTimeout(() => {
  1553. exampleNode.scrollIntoView();
  1554. }, 500);
  1555. searchInput.value = hash.slice(1);
  1556. searchByInput();
  1557. }
  1558. }
  1559. [].forEach.call(ruleList.querySelectorAll("div.highlight"), highlight => {
  1560. highlight.style.position = "relative";
  1561. highlight.innerHTML = highlight.innerHTML + copySvg;
  1562. let svg = highlight.children[1];
  1563. svg.addEventListener("click", function(e) {
  1564. GM_setClipboard(highlight.children[0].innerText);
  1565. svg.style.opacity = 0;
  1566. setTimeout(() => {
  1567. svg.style.opacity = 1;
  1568. }, 1000);
  1569. });
  1570. });
  1571. exampleNode.parentNode.insertBefore(searchInput, ruleList);
  1572.  
  1573.  
  1574. let donateNode = document.querySelector("[alt='donate']");
  1575. if (!donateNode) return;
  1576. let insertPos = donateNode.parentNode.nextElementSibling;
  1577. let radioIndex = 0;
  1578. function createOption(_name, _value, _type) {
  1579. if (!_type) _type = "input";
  1580. let con = document.createElement("div");
  1581. let option = document.createElement("input");
  1582. let cap = document.createElement("b");
  1583. option.type = _type;
  1584. option.value = _value;
  1585. option.checked = _value;
  1586. cap.style.margin = "0px 10px 0px 0px";
  1587. if (_type == "radio") {
  1588. let label = document.createElement("label");
  1589. label.innerText = _name;
  1590. radioIndex++;
  1591. option.id = "radio" + radioIndex;
  1592. label.setAttribute("for", option.id);
  1593. cap.appendChild(label);
  1594. } else {
  1595. if (_type == "input") {
  1596. option.style.flexGrow = "1";
  1597. }
  1598. cap.innerText = _name;
  1599. }
  1600. con.style.margin = "10px 0";
  1601. con.style.display = "flex";
  1602. con.style.alignItems = "center";
  1603. con.appendChild(cap);
  1604. con.appendChild(option);
  1605. insertPos.parentNode.insertBefore(con, insertPos);
  1606. return option;
  1607. }
  1608. let delSelector = createOption(i18n.del, GM_getValue("selectors") || "");
  1609. delSelector.setAttribute("placeHolder", ".mask,.ksam");
  1610. let downThreadNum = createOption(i18n.downThreadNum, GM_getValue("downThreadNum") || "20", "number");
  1611. let customTitle = createOption(i18n.customTitle, GM_getValue("customTitle") || "");
  1612. customTitle.setAttribute("placeHolder", "title");
  1613. let minTxtLength = createOption(i18n.minTxtLength, GM_getValue("minTxtLength") || "100", "number");
  1614. let contentSortUrlValue = GM_getValue("contentSortUrl") || false;
  1615. let contentSortValue = GM_getValue("contentSort") || false;
  1616. let reSortDefault = createOption(i18n.reSortDefault, !contentSortUrlValue && !contentSortValue, "radio");
  1617. let reSortUrl = createOption(i18n.reSortUrl, contentSortUrlValue || false, "radio");
  1618. let contentSort = createOption(i18n.reSort, contentSortValue || false, "radio");
  1619. reSortDefault.name = "sort";
  1620. reSortUrl.name = "sort";
  1621. contentSort.name = "sort";
  1622. let reverse = createOption(i18n.reverse, !!GM_getValue("reverse"), "checkbox");
  1623. let retainImage = createOption(i18n.retainImage, !!GM_getValue("retainImage"), "checkbox");
  1624. let showFilterList = createOption(i18n.showFilterList, !!GM_getValue("showFilterList"), "checkbox");
  1625. let disableNextPage = !!GM_getValue("disableNextPage");
  1626. let nextPage = createOption(i18n.nextPage, !disableNextPage, "checkbox");
  1627. let nextPageReg = createOption(i18n.nextPageReg, GM_getValue("nextPageReg") || "");
  1628. nextPageReg.setAttribute("placeHolder", "^\\s*(下一[页頁张張]|next\\s*page|次のページ)");
  1629. if (disableNextPage) {
  1630. nextPageReg.parentNode.style.display = "none";
  1631. }
  1632. nextPage.onclick = e => {
  1633. nextPageReg.parentNode.style.display = nextPage.checked ? "flex" : "none";
  1634. }
  1635. let saveBtn = document.createElement("button");
  1636. saveBtn.innerText = i18n.saveBtn;
  1637. saveBtn.style.margin = "0 0 20px 0";
  1638. insertPos.parentNode.insertBefore(saveBtn, insertPos);
  1639. saveBtn.onclick = e => {
  1640. GM_setValue("selectors", delSelector.value || "");
  1641. GM_setValue("downThreadNum", downThreadNum.value || 20);
  1642. GM_setValue("minTxtLength", minTxtLength.value || 100);
  1643. GM_setValue("customTitle", customTitle.value || "");
  1644. if (reSortUrl.checked) {
  1645. GM_setValue("contentSortUrl", true);
  1646. GM_setValue("contentSort", false);
  1647. } else if (contentSort.checked) {
  1648. GM_setValue("contentSortUrl", false);
  1649. GM_setValue("contentSort", true);
  1650. } else {
  1651. GM_setValue("contentSortUrl", false);
  1652. GM_setValue("contentSort", false);
  1653. }
  1654. GM_setValue("reverse", reverse.checked);
  1655. GM_setValue("retainImage", retainImage.checked);
  1656. GM_setValue("showFilterList", showFilterList.checked);
  1657. GM_setValue("disableNextPage", !nextPage.checked);
  1658. GM_setValue("nextPageReg", nextPageReg.value || "");
  1659. alert(i18n.saveOk);
  1660. };
  1661. return;
  1662. }
  1663.  
  1664. function setDel(){
  1665. GM_openInTab(configPage + "#操作說明", {active: true});
  1666. return;
  1667. /*var selValue=GM_getValue("selectors");
  1668. var selectors=prompt(i18n.del,selValue?selValue:"");
  1669. GM_setValue("selectors",selectors);
  1670. selValue=GM_getValue("downThreadNum");
  1671. var downThreadNum=prompt(i18n.downThreadNum,selValue?selValue:"20");
  1672. GM_setValue("downThreadNum",downThreadNum);
  1673. var sortByUrl=window.confirm(i18n.reSortUrl);
  1674. GM_setValue("contentSortUrl",sortByUrl);
  1675. if(!sortByUrl)GM_setValue("contentSort",window.confirm(i18n.reSort));*/
  1676. }
  1677.  
  1678. document.addEventListener("keydown", function(e) {
  1679. if(e.keyCode == 120 && e.ctrlKey) {
  1680. fetch(e.shiftKey);
  1681. }
  1682. });
  1683. GM_registerMenuCommand(i18n.fetch, fetch);
  1684. GM_registerMenuCommand(i18n.custom, () => {
  1685. var customRules = GM_getValue("DACrules_" + document.domain);
  1686. var urls = window.prompt(i18n.customInfo, customRules ? customRules : "https://xxx.xxx/book-[20-99].html, https://xxx.xxx/book-[01-10].html");
  1687. if (urls) {
  1688. customDown(urls);
  1689. }
  1690. });
  1691. GM_registerMenuCommand(i18n.setting, setDel);
  1692. GM_registerMenuCommand(i18n.searchRule, searchRule);
  1693. })();