怠惰小说下载器

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

当前为 2023-11-01 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name DownloadAllContent
  3. // @name:zh-CN 怠惰小说下载器
  4. // @name:zh-TW 怠惰小説下載器
  5. // @name:ja 怠惰者小説ダウンロードツール
  6. // @namespace hoothin
  7. // @version 2.7.5.3
  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. line-height: initial;
  639. width: initial;
  640. min-width: initial;
  641. max-width: initial;
  642. height: initial;
  643. min-height: initial;
  644. max-height: initial;
  645. }
  646. #dacLinksCon>div:nth-of-type(4n),
  647. #dacLinksCon>div:nth-of-type(4n+1) {
  648. background: #ffffff;
  649. }
  650. #dacLinksCon>div:nth-of-type(4n+2),
  651. #dacLinksCon>div:nth-of-type(4n+3) {
  652. background: #f5f5f5;
  653. }
  654. #filterListContainer .fun,#filterListContainer .sort {
  655. display: flex;
  656. justify-content: space-around;
  657. flex-wrap: nowrap;
  658. width: 100%;
  659. }
  660. #filterListContainer input[type=button]:hover {
  661. border: 1px #C6C6C6 solid;
  662. box-shadow: 1px 1px 1px #EAEAEA;
  663. color: #333333;
  664. background: #F7F7F7;
  665. }
  666. #filterListContainer input[type=button]:active {
  667. box-shadow: inset 1px 1px 1px #DFDFDF;
  668. }
  669. `);
  670. dacLinksCon = filterListContainer.querySelector("#dacLinksCon");
  671. }
  672. list.forEach(a => {
  673. createLinkItem(a);
  674. });
  675. dacUseIframe.checked = useIframe;
  676. }
  677.  
  678. function initTxtDownDiv(){
  679. if(txtDownContent){
  680. txtDownContent.style.display="";
  681. return;
  682. }
  683. txtDownContent=document.createElement("div");
  684. txtDownContent.id="txtDownContent";
  685. document.body.appendChild(txtDownContent);
  686. txtDownContent.innerHTML=createHTML(`
  687. <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;">
  688. <div id="txtDownWords" style="position:absolute;width:275px;height: 90px;max-height: 90%;border: 1px solid #f3f1f1;padding: 8px;border-radius: 10px;overflow: auto;">
  689. Analysing......
  690. </div>
  691. <div id="txtDownQuit" style="width: 30px;height: 30px;border-radius: 30px;position:absolute;right:2px;top:2px;cursor: pointer;background-color:#ff5a5a;">
  692. <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>
  693. </div>
  694. <div style="position:absolute;right:0px;bottom:2px;cursor: pointer;max-width:85px">
  695. <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>
  696. <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>
  697. <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>
  698. </div>
  699. </div>`);
  700. txtDownWords=txtDownContent.querySelector("#txtDownWords");
  701. txtDownQuit=txtDownContent.querySelector("#txtDownQuit");
  702. txtDownQuit.onclick=function(){
  703. txtDownContent.style.display="none";
  704. };
  705. initTempSave();
  706. }
  707.  
  708. function saveContent() {
  709. if (win.downloadAllContentSaveAsZip) {
  710. win.downloadAllContentSaveAsZip(rCats, i18n.info, content => {
  711. saveAs(content, document.title + ".zip");
  712. });
  713. } else {
  714. 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"});
  715. saveAs(blob, document.title + ".txt");
  716. }
  717. }
  718.  
  719. function initTempSave(){
  720. var tempSavebtn = document.getElementById('tempSaveTxt');
  721. var abortbtn = document.getElementById('abortRequest');
  722. var saveAsMd = document.getElementById('saveAsMd');
  723. tempSavebtn.onclick = function(){
  724. saveContent();
  725. console.log(curRequests);
  726. }
  727. abortbtn.onclick = function(){
  728. let curRequest = curRequests.pop();
  729. if(curRequest)curRequest[1].abort();
  730. }
  731. saveAsMd.onclick = function(){
  732. let txt = i18n.info+"\n\n---\n"+document.title+"\n===\n";
  733. rCats.forEach(cat => {
  734. cat = cat.replace("\r\n", "\n---").replace(/(\r\n|\n\r)+/g, "\n\n").replace(/[\n\r]\t+/g, "\n");
  735. txt += '\n\n'+cat;
  736. });
  737. var blob = new Blob([txt], {type: "text/plain;charset=utf-8"});
  738. saveAs(blob, document.title+".md");
  739. }
  740. }
  741.  
  742. function indexDownload(aEles, noSort){
  743. if(aEles.length<1)return;
  744. initTxtDownDiv();
  745. if(!noSort) {
  746. if(GM_getValue("contentSort")){
  747. aEles.sort((a, b) => {
  748. return str2Num(a.innerText) - str2Num(b.innerText);
  749. });
  750. }
  751. if(GM_getValue("contentSortUrl")){
  752. aEles.sort((a, b) => {
  753. const nameA = a.href.toUpperCase();
  754. const nameB = b.href.toUpperCase();
  755. if (nameA < nameB) {
  756. return -1;
  757. }
  758. if (nameA > nameB) {
  759. return 1;
  760. }
  761. return 0;
  762. });
  763. }
  764. if(GM_getValue("reverse")){
  765. aEles=aEles.reverse();
  766. }
  767. }
  768. rCats=[];
  769. var minTxtLength=GM_getValue("minTxtLength") || 100;
  770. var customTitle=GM_getValue("customTitle");
  771. var disableNextPage=!!GM_getValue("disableNextPage");
  772. var customNextPageReg=GM_getValue("nextPageReg");
  773. if (customNextPageReg) {
  774. try {
  775. innerNextPage = new RegExp(customNextPageReg);
  776. } catch(e) {
  777. console.warn(e);
  778. }
  779. }
  780. var insertSigns=[];
  781. // var j=0,rCats=[];
  782. var downIndex=0,downNum=0,downOnce=function(wait){
  783. if(downNum>=aEles.length)return;
  784. let curIndex=downIndex;
  785. let aTag=aEles[curIndex];
  786. let request=(aTag, curIndex)=>{
  787. let tryTimes=0;
  788. let validTimes=0;
  789. let requestBody={
  790. method: 'GET',
  791. url: aTag.href,
  792. headers:{
  793. referer:aTag.href,
  794. "Content-Type":"text/html;charset="+document.charset
  795. },
  796. timeout:10000,
  797. overrideMimeType:"text/html;charset="+document.charset,
  798. onload: function(result) {
  799. downIndex++;
  800. downNum++;
  801. let doc = getDocEle(result.responseText);
  802. let base = doc.querySelector("base");
  803. let nextPage = !disableNextPage && !processFunc && checkNextPage(doc, base ? base.href : aTag.href);
  804. if(nextPage){
  805. var inArr=false;
  806. for(var ai=0;ai<aEles.length;ai++){
  807. if(aEles[ai].href==nextPage.href){
  808. inArr=true;
  809. break;
  810. }
  811. }
  812. if(!inArr){
  813. nextPage.innerText=aTag.innerText+"\t>>";
  814. aEles.push(nextPage);
  815. let targetIndex = curIndex;
  816. for(let a=0;a<insertSigns.length;a++){
  817. let signs=insertSigns[a],breakSign=false;
  818. if(signs){
  819. for(let b=0;b<signs.length;b++){
  820. let sign=signs[b];
  821. if(sign==curIndex){
  822. targetIndex=a;
  823. breakSign=true;
  824. break;
  825. }
  826. }
  827. }
  828. if(breakSign)break;
  829. }
  830. let insertSign = insertSigns[targetIndex];
  831. if(!insertSign)insertSigns[targetIndex] = [];
  832. insertSigns[targetIndex].push(aEles.length-1);
  833. }
  834. }
  835. if (result.status >= 400) {
  836. console.warn("error:", `status: ${result.status} from: ${aTag.href}`);
  837. } else {
  838. console.log(result.status);
  839. }
  840. if (customTitle) {
  841. try {
  842. let title = doc.querySelector(customTitle);
  843. if (title && title.innerText) {
  844. aTag.innerText = title.innerText;
  845. }
  846. } catch(e) {
  847. console.warn(e);
  848. }
  849. }
  850. let validData = processDoc(curIndex, aTag, doc, (result.status>=400?` status: ${result.status} from: ${aTag.href} `:""), validTimes < 5);
  851. if (!validData && validTimes++ < 5) {
  852. downIndex--;
  853. downNum--;
  854. setTimeout(() => {
  855. GM_xmlhttpRequest(requestBody);
  856. }, 500);
  857. return;
  858. }
  859. if (wait) {
  860. setTimeout(() => {
  861. downOnce(wait);
  862. }, wait);
  863. } else downOnce();
  864. },
  865. onerror: function(e) {
  866. console.warn("error:", e);
  867. if(tryTimes++ < 5){
  868. setTimeout(() => {
  869. GM_xmlhttpRequest(requestBody);
  870. }, 500);
  871. return;
  872. }
  873. downIndex++;
  874. downNum++;
  875. processDoc(curIndex, aTag, null, ` NETWORK ERROR: '+${(e.response||e.responseText)} from: ${aTag.href} `);
  876. if (wait) {
  877. setTimeout(() => {
  878. downOnce(wait);
  879. }, wait);
  880. } else downOnce();
  881. },
  882. ontimeout: function(e) {
  883. console.warn("timeout: times="+tryTimes+" url="+aTag.href);
  884. //console.log(e);
  885. if(tryTimes++ < 5){
  886. setTimeout(() => {
  887. GM_xmlhttpRequest(requestBody);
  888. }, 500);
  889. return;
  890. }
  891. downIndex++;
  892. downNum++;
  893. processDoc(curIndex, aTag, null, ` TIMEOUT: '+${aTag.href} `);
  894. if (wait) {
  895. setTimeout(() => {
  896. downOnce(wait);
  897. }, wait);
  898. } else downOnce();
  899. }
  900. };
  901. if (useIframe) {
  902. let iframe = document.createElement('iframe'), inited = false;
  903. iframe.name = 'pagetual-iframe';
  904. iframe.width = '100%';
  905. iframe.height = '1000';
  906. iframe.frameBorder = '0';
  907. iframe.sandbox = iframeSandbox || "allow-same-origin allow-scripts allow-popups allow-forms";
  908. 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;';
  909. iframe.addEventListener('load', e => {
  910. if (e.data != 'pagetual-iframe:DOMLoaded' && e.type != 'load') return;
  911. if (inited) return;
  912. inited = true;
  913. function checkIframe() {
  914. try {
  915. let doc = iframe.contentDocument || iframe.contentWindow.document;
  916. if (!doc || !doc.body) {
  917. setTimeout(() => {
  918. checkIframe();
  919. }, 1000);
  920. return;
  921. }
  922. doc.body.scrollTop = 9999999;
  923. doc.documentElement.scrollTop = 9999999;
  924. if (validTimes++ > 10) {
  925. iframe.src = iframe.src;
  926. validTimes = 0;
  927. return;
  928. }
  929. if (customTitle) {
  930. try {
  931. let title = doc.querySelector(customTitle);
  932. if (title && title.innerText) {
  933. aTag.innerText = title.innerText;
  934. }
  935. } catch(e) {
  936. console.warn(e);
  937. }
  938. }
  939. downIndex++;
  940. downNum++;
  941. let validData = processDoc(curIndex, aTag, doc, "", true);
  942. if (!validData) {
  943. downIndex--;
  944. downNum--;
  945. setTimeout(() => {
  946. checkIframe();
  947. }, 500);
  948. return;
  949. }
  950. if (wait) {
  951. setTimeout(() => {
  952. downOnce(wait);
  953. }, wait);
  954. } else downOnce();
  955. } catch(e) {
  956. console.debug("Stop as cors");
  957. }
  958. if (iframe && iframe.parentNode) iframe.parentNode.removeChild(iframe);
  959. }
  960. setTimeout(() => {
  961. checkIframe();
  962. }, 500);
  963. }, false);
  964. let checkReady = setInterval(() => {
  965. let doc;
  966. try {
  967. doc = iframe.contentDocument || (iframe.contentWindow && iframe.contentWindow.document);
  968. } catch(e) {
  969. clearInterval(checkReady);
  970. return;
  971. }
  972. if (doc) {
  973. try {
  974. Function('win', 'iframe', '"use strict";' + (iframeInit || "win.self=win.top;"))(iframe.contentWindow, iframe);
  975. clearInterval(checkReady);
  976. } catch(e) {
  977. console.debug(e);
  978. }
  979. }
  980. }, 50);
  981. iframe.src = aTag.href;
  982. document.body.appendChild(iframe);
  983. return [curIndex, null, aTag.href];
  984. } else {
  985. return [curIndex, GM_xmlhttpRequest(requestBody), aTag.href];
  986. }
  987. }
  988. if(!aTag){
  989. let waitAtagReadyInterval=setInterval(function(){
  990. if(downNum>=aEles.length)clearInterval(waitAtagReadyInterval);
  991. aTag=aEles[curIndex];
  992. if(aTag){
  993. clearInterval(waitAtagReadyInterval);
  994. request(aTag, curIndex);
  995. }
  996. },1000);
  997. return null;
  998. }
  999. let result = request(aTag, curIndex);
  1000. if (result) curRequests.push(result);
  1001. return result;
  1002. };
  1003. function getDocEle(str){
  1004. var doc = null;
  1005. try {
  1006. doc = document.implementation.createHTMLDocument('');
  1007. doc.documentElement.innerHTML = str;
  1008. }
  1009. catch (e) {
  1010. console.log('parse error');
  1011. }
  1012. return doc;
  1013. }
  1014. function sortInnerPage(){
  1015. var pageArrs=[],maxIndex=0,i,j;
  1016. for(i=0;i<insertSigns.length;i++){
  1017. var signs=insertSigns[i];
  1018. if(signs){
  1019. for(j=0;j<signs.length;j++){
  1020. var sign=signs[j];
  1021. var cat=rCats[sign];
  1022. rCats[sign]=null;
  1023. if(!pageArrs[i])pageArrs[i]=[];
  1024. pageArrs[i].push(cat);
  1025. }
  1026. }
  1027. }
  1028. for(i=pageArrs.length-1;i>=0;i--){
  1029. let pageArr=pageArrs[i];
  1030. if(pageArr){
  1031. for(j=pageArr.length-1;j>=0;j--){
  1032. rCats.splice(i+1, 0, pageArr[j]);
  1033. }
  1034. }
  1035. }
  1036. rCats = rCats.filter(function(e){return e!=null});
  1037. }
  1038. var waitForComplete;
  1039. function processDoc(i, aTag, doc, cause, check){
  1040. let cbFunc=content=>{
  1041. rCats[i]=(aTag.innerText.replace(/[\r\n\t]/g, "") + "\r\n" + (cause || '') + content.replace(/\s*$/, ""));
  1042. curRequests = curRequests.filter(function(e){return e[0]!=i});
  1043. txtDownContent.style.display="block";
  1044. txtDownWords.innerHTML=getI18n("downloading",[downNum,(aEles.length-downNum),aTag.innerText]);
  1045. if(downNum==aEles.length){
  1046. if(waitForComplete) clearTimeout(waitForComplete);
  1047. waitForComplete=setTimeout(()=>{
  1048. if(downNum==aEles.length){
  1049. txtDownWords.innerHTML=getI18n("complete",[downNum]);
  1050. sortInnerPage();
  1051. saveContent();
  1052. }
  1053. },3000);
  1054. }
  1055. };
  1056. let contentResult=getPageContent(doc, content=>{
  1057. cbFunc(content);
  1058. }, aTag.href);
  1059. if(contentResult!==false){
  1060. if(check && contentResult && contentResult.replace(/\s/g, "").length<minTxtLength){
  1061. return false;
  1062. }
  1063. cbFunc(contentResult);
  1064. }
  1065. return true;
  1066. }
  1067. var downThreadNum = parseInt(GM_getValue("downThreadNum"));
  1068. downThreadNum = downThreadNum || 20;
  1069. if (useIframe && downThreadNum > 5) {
  1070. downThreadNum = 5;
  1071. }
  1072. if (downThreadNum > 0) {
  1073. for (var i = 0; i < downThreadNum; i++) {
  1074. downOnce();
  1075. if (downIndex >= aEles.length - 1 || downIndex >= downThreadNum - 1) break;
  1076. else downIndex++;
  1077. }
  1078. } else {
  1079. downOnce(-downThreadNum * 1000);
  1080. if (downIndex < aEles.length - 1 && downIndex < downThreadNum - 1) downIndex++;
  1081. }
  1082.  
  1083. /*for(let i=0;i<aEles.length;i++){
  1084. let aTag=aEles[i];
  1085. GM_xmlhttpRequest({
  1086. method: 'GET',
  1087. url: aTag.href,
  1088. overrideMimeType:"text/html;charset="+document.charset,
  1089. onload: function(result) {
  1090. var doc = getDocEle(result.responseText);
  1091. processDoc(i, aTag, doc);
  1092. }
  1093. });
  1094. }*/
  1095. }
  1096.  
  1097. function canonicalUri(src, baseUrl) {
  1098. if (!src) {
  1099. return "";
  1100. }
  1101. if (src.charAt(0) == "#") return baseUrl + src;
  1102. if (src.charAt(0) == "?") return baseUrl.replace(/^([^\?#]+).*/, "$1" + src);
  1103. let origin = location.protocol + '//' + location.host;
  1104. let url = baseUrl || origin;
  1105. url = url.replace(/(\?|#).*/, "");
  1106. if (/https?:\/\/[^\/]+$/.test(url)) url = url + '/';
  1107. if (url.indexOf("http") !== 0) url = origin + url;
  1108. var root_page = /^[^\?#]*\//.exec(url)[0],
  1109. root_domain = /^\w+\:\/\/\/?[^\/]+/.exec(root_page)[0],
  1110. absolute_regex = /^\w+\:\/\//;
  1111. while (src.indexOf("../") === 0) {
  1112. src = src.substr(3);
  1113. root_page = root_page.replace(/\/[^\/]+\/$/, "/");
  1114. }
  1115. src = src.replace(/\.\//, "");
  1116. if (/^\/\/\/?/.test(src)) {
  1117. src = location.protocol + src;
  1118. }
  1119. return (absolute_regex.test(src) ? src : ((src.charAt(0) == "/" ? root_domain : root_page) + src));
  1120. }
  1121.  
  1122. function checkNextPage(doc, baseUrl) {
  1123. let aTags = doc.querySelectorAll("a"), nextPage = null;
  1124. for (var i = 0; i < aTags.length; i++) {
  1125. let aTag = aTags[i];
  1126. if (innerNextPage.test(aTag.innerText) && aTag.href && !/javascript:|#/.test(aTag.href)) {
  1127. let nextPageHref = canonicalUri(aTag.getAttribute("href"), baseUrl || location.href);
  1128. if (nextPageHref != location.href) {
  1129. nextPage = aTag;
  1130. nextPage.href = nextPageHref;
  1131. break;
  1132. }
  1133. }
  1134. }
  1135. return nextPage;
  1136. }
  1137.  
  1138. function textNodesUnder(el){
  1139. var n, a=[], walk=document.createTreeWalker(el,NodeFilter.SHOW_TEXT,null,false);
  1140. while(n=walk.nextNode()) a.push(n);
  1141. return a;
  1142. }
  1143.  
  1144. function getPageContent(doc, cb, url){
  1145. if(!doc)return i18n.error;
  1146. if(processFunc){
  1147. return processFunc(doc, cb, url);
  1148. }
  1149. [].forEach.call(doc.querySelectorAll("span,div,ul"),function(item){
  1150. var thisStyle=doc.defaultView?doc.defaultView.getComputedStyle(item):item.style;
  1151. if(thisStyle && (thisStyle.display=="none" || (item.nodeName=="SPAN" && thisStyle.fontSize=="0px"))){
  1152. item.innerHTML="";
  1153. }
  1154. });
  1155. var i,j,k,rStr="",pageData=(doc.body?doc.body:doc).cloneNode(true),delList=[];
  1156. pageData.innerHTML=pageData.innerHTML.replace(/\<\!\-\-((.|[\n|\r|\r\n])*?)\-\-\>/g,"");
  1157. [].forEach.call(pageData.querySelectorAll("font.jammer"),function(item){
  1158. item.innerHTML="";
  1159. });
  1160. var selectors=GM_getValue("selectors");
  1161. if(selectors){
  1162. [].forEach.call(pageData.querySelectorAll(selectors),function(item){
  1163. item.innerHTML="";
  1164. });
  1165. }
  1166. [].forEach.call(pageData.querySelectorAll("script,style,link,img,noscript,iframe"),function(item){delList.push(item);});
  1167. [].forEach.call(delList,function(item){item.innerHTML="";});
  1168. var endEle = ele => {
  1169. return /^(I|STRONG|B|FONT|P|DL|DD|H\d)$/.test(ele.nodeName) && ele.children.length <= 1;
  1170. };
  1171. var largestContent,contents=pageData.querySelectorAll("span,div,article,p,td"),largestNum=0;
  1172. for(i=0;i<contents.length;i++){
  1173. let content=contents[i],hasText=false,allSingle=true,item,curNum=0;
  1174. if(/footer/.test(content.className))continue;
  1175. for(j=content.childNodes.length-1;j>=0;j--){
  1176. item=content.childNodes[j];
  1177. if(item.nodeType==3){
  1178. if(/^\s*$/.test(item.data)){
  1179. item.innerHTML="";
  1180. }else hasText=true;
  1181. }else if(/^(I|A|STRONG|B|FONT|P|DL|DD|H\d)$/.test(item.nodeName)){
  1182. hasText=true;
  1183. }else if(item.nodeType==1&&item.children.length==1&&/^(I|A|STRONG|B|FONT|P|DL|DD|H\d)$/.test(item.children[0].nodeName)){
  1184. hasText=true;
  1185. }
  1186. }
  1187. for(j=content.childNodes.length-1;j>=0;j--){
  1188. item=content.childNodes[j];
  1189. if(item.nodeType==1 && !/^(I|A|STRONG|B|FONT|BR)$/.test(item.nodeName) && /^[\s\-\_\?\>\|]*$/.test(item.innerHTML)){
  1190. item.innerHTML="";
  1191. }
  1192. }
  1193. if(content.childNodes.length>1){
  1194. let indexItem=0;
  1195. for(j=0;j<content.childNodes.length;j++){
  1196. item=content.childNodes[j];
  1197. if(item.nodeType==1){
  1198. if(item.innerText && item.innerText.length<50 && indexReg.test(item.innerText))indexItem++;
  1199. for(k=0;k<item.childNodes.length;k++){
  1200. var childNode=item.childNodes[k];
  1201. if(childNode.nodeType!=3 && !/^(I|A|STRONG|B|FONT|BR)$/.test(childNode.nodeName)){
  1202. allSingle=false;
  1203. break;
  1204. }
  1205. }
  1206. if(!allSingle)break;
  1207. }
  1208. }
  1209. if(indexItem>=5)continue;
  1210. }else{
  1211. allSingle=false;
  1212. }
  1213. if(!allSingle && !hasText){
  1214. continue;
  1215. }else {
  1216. if(pageData==document && content.offsetWidth<=0 && content.offsetHeight<=0){
  1217. continue;
  1218. }
  1219. [].forEach.call(content.childNodes,function(item){
  1220. if(item.nodeType==3)curNum+=item.data.trim().length;
  1221. 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);
  1222. });
  1223. }
  1224. if(curNum>largestNum){
  1225. largestNum=curNum;
  1226. largestContent=content;
  1227. }
  1228. }
  1229. if(!largestContent)return i18n.error+" : NO TEXT CONTENT";
  1230. var retainImage=!!GM_getValue("retainImage");
  1231. var childlist=pageData.querySelectorAll(largestContent.nodeName);//+(largestContent.className?"."+largestContent.className.replace(/(^\s*)|(\s*$)/g, '').replace(/\s+/g, '.'):""));
  1232. function getRightStr(ele, noTextEnable){
  1233. if(retainImage){
  1234. [].forEach.call(ele.querySelectorAll("img[src]"), img => {
  1235. let imgTxtNode=document.createTextNode(`![img](${canonicalUri(img.getAttribute("src"), url || location.href)})`);
  1236. img.parentNode.replaceChild(imgTxtNode, img);
  1237. });
  1238. }
  1239. let childNodes=ele.childNodes,cStr="\r\n",hasText=false;
  1240. [].forEach.call(ele.querySelectorAll("a[href]"), a => {
  1241. a.parentNode && a.parentNode.removeChild(a);
  1242. });
  1243. for(let j=0;j<childNodes.length;j++){
  1244. let childNode=childNodes[j];
  1245. if(childNode.nodeType==3 && childNode.data && !/^[\s\-\_\?\>\|]*$/.test(childNode.data))hasText=true;
  1246. if(childNode.innerHTML){
  1247. childNode.innerHTML=childNode.innerHTML.replace(/\<\s*br\s*\>/gi,"\r\n").replace(/\n+/gi,"\n").replace(/\r+/gi,"\r");
  1248. }
  1249. let content=childNode.textContent;
  1250. if(content){
  1251. if(!content.trim())continue;
  1252. cStr+=content.replace(/ +/g," ").replace(/([^\r]|^)\n([^\r]|$)/gi,"$1\r\n$2");
  1253. }
  1254. if(childNode.nodeType!=3 && !/^(I|A|STRONG|B|FONT|IMG)$/.test(childNode.nodeName))cStr+="\r\n";
  1255. }
  1256. if(hasText || noTextEnable || ele==largestContent)rStr+=cStr+"\r\n";
  1257. }
  1258. for(i=0;i<childlist.length;i++){
  1259. var child=childlist[i];
  1260. if(getDepth(child)==getDepth(largestContent)){
  1261. if(largestContent.className != child.className)continue;
  1262. if((largestContent.className && largestContent.className == child.className) || largestContent.parentNode == child.parentNode){
  1263. getRightStr(child, true);
  1264. }else {
  1265. getRightStr(child, false);
  1266. }
  1267. }
  1268. }
  1269. return rStr.replace(/[\n\r]+/g,"\n\r");
  1270. }
  1271.  
  1272. function getI18n(key, args){
  1273. var resultStr=i18n[key];
  1274. if(args && args.length>0){
  1275. args.forEach(function(item){
  1276. resultStr=resultStr.replace(/%s/,item);
  1277. });
  1278. }
  1279. return resultStr;
  1280. }
  1281.  
  1282. function getDepth(dom){
  1283. var pa=dom,i=0;
  1284. while(pa.parentNode){
  1285. pa=pa.parentNode;
  1286. i++;
  1287. }
  1288. return i;
  1289. }
  1290.  
  1291. function fetch(forceSingle){
  1292. forceSingle=forceSingle===true;
  1293. processFunc=null;
  1294. var aEles=document.body.querySelectorAll("a"),list=[];
  1295. for(var i=0;i<aEles.length;i++){
  1296. var aEle=aEles[i],has=false;
  1297. if((!aEle.href || aEle.href.indexOf("javascript")!=-1) && aEle.dataset.href){
  1298. aEle.href=aEle.dataset.href;
  1299. }
  1300. if(aEle.href==location.href)continue;
  1301. for(var j=0;j<list.length;j++){
  1302. if(list[j].href==aEle.href){
  1303. aEle=list[j];
  1304. list.splice(j,1);
  1305. list.push(aEle);
  1306. has=true;
  1307. break;
  1308. }
  1309. }
  1310. if(!has && aEle.href && /^http/i.test(aEle.href) && ((aEle.innerText.trim()!="" && indexReg.test(aEle.innerText.trim())) || /chapter[\-_]?\d/.test(aEle.href))){
  1311. list.push(aEle);
  1312. }
  1313. }
  1314. if(list.length>2 && !forceSingle){
  1315. useIframe = false;
  1316. filterList(list);
  1317. }else{
  1318. var blob = new Blob([i18n.info+"\r\n\r\n"+document.title+"\r\n\r\n"+getPageContent(document)], {type: "text/plain;charset=utf-8"});
  1319. saveAs(blob, document.title+".txt");
  1320. }
  1321. }
  1322.  
  1323. function customDown(urls){
  1324. processFunc = null;
  1325. useIframe = false;
  1326. if(urls){
  1327. urls=decodeURIComponent(urls.replace(/%/g,'%25'));
  1328. GM_setValue("DACrules_"+document.domain, urls);
  1329. var processEles=[];
  1330. let urlsArr=urls.split("@@"),eles=[];
  1331. if(/^http|^ftp/.test(urlsArr[0])){
  1332. [].forEach.call(urlsArr[0].split(","),function(i){
  1333. var curEle;
  1334. var varNum=/\[\d+\-\d+\]/.exec(i);
  1335. if(varNum){
  1336. varNum=varNum[0].trim();
  1337. }else{
  1338. curEle=document.createElement("a");
  1339. curEle.href=i;
  1340. curEle.innerText="Added Url";
  1341. processEles.push(curEle);
  1342. return;
  1343. }
  1344. var num1=/\[(\d+)/.exec(varNum)[1].trim();
  1345. var num2=/(\d+)\]/.exec(varNum)[1].trim();
  1346. var num1Int=parseInt(num1);
  1347. var num2Int=parseInt(num2);
  1348. var numLen=num1.length;
  1349. var needAdd=num1.charAt(0)=="0";
  1350. if(num1Int>=num2Int)return;
  1351. for(var j=num1Int;j<=num2Int;j++){
  1352. var urlIndex=j.toString();
  1353. if(needAdd){
  1354. while(urlIndex.length<numLen)urlIndex="0"+urlIndex;
  1355. }
  1356. var curUrl=i.replace(/\[\d+\-\d+\]/,urlIndex).trim();
  1357. curEle=document.createElement("a");
  1358. curEle.href=curUrl;
  1359. curEle.innerText="Added Url " + processEles.length.toString();
  1360. processEles.push(curEle);
  1361. }
  1362. });
  1363. }else{
  1364. let urlSel=urlsArr[0].split(">>");
  1365. try{
  1366. eles=document.querySelectorAll(urlSel[0]);
  1367. eles=[].filter.call(eles, ele=>{
  1368. return ele.nodeName=='BODY'||(!!ele.offsetParent&&getComputedStyle(ele).display!=='none');
  1369. })
  1370. }catch(e){}
  1371. if(eles.length==0){
  1372. eles=[];
  1373. var eleTxts=urlsArr[0].split(/(?<=[^\\])[,,]/),exmpEles=[],excludeTxts={};
  1374. [].forEach.call(document.querySelectorAll("a"),function(item){
  1375. if(!item.offsetParent)return;
  1376. eleTxts.forEach(txt=>{
  1377. var txtArr=txt.split("!");
  1378. if(item.innerText.indexOf(txtArr[0])!=-1){
  1379. exmpEles.push(item);
  1380. excludeTxts[item]=txtArr.splice(1);
  1381. }
  1382. });
  1383. })
  1384. exmpEles.forEach(e=>{
  1385. var cssSelStr="a",pa=e.parentNode,excludeTxt=excludeTxts[e];
  1386. if(e.className)cssSelStr+="."+CSS.escape(e.className);
  1387. while(pa && pa.nodeName!="BODY"){
  1388. cssSelStr=pa.nodeName+">"+cssSelStr;
  1389. pa=pa.parentNode;
  1390. }
  1391. cssSelStr="body>"+cssSelStr;;
  1392. [].forEach.call(document.querySelectorAll(cssSelStr),function(item){
  1393. if(!item.offsetParent)return;
  1394. var isExclude=false;
  1395. for(var t in excludeTxt){
  1396. if(item.innerText.indexOf(excludeTxt[t])!=-1){
  1397. isExclude=true;
  1398. break;
  1399. }
  1400. }
  1401. if(!isExclude && eles.indexOf(item)==-1){
  1402. eles.push(item);
  1403. }
  1404. });
  1405. });
  1406. }
  1407. function addItem(item) {
  1408. let has=false;
  1409. for(var j=0;j<processEles.length;j++){
  1410. if(processEles[j].href==item.href){
  1411. processEles.splice(j,1);
  1412. processEles.push(item);
  1413. has=true;
  1414. break;
  1415. }
  1416. }
  1417. if((!item.href || item.href.indexOf("javascript")!=-1) && item.dataset.href){
  1418. item.href=item.dataset.href;
  1419. }
  1420. if(!has && item.href && /^http/i.test(item.href)){
  1421. processEles.push(item.cloneNode(1));
  1422. }
  1423. }
  1424. [].forEach.call(eles,function(item){
  1425. if(urlSel[1]){
  1426. item=Function("item",urlSel[1])(item);
  1427. let items;
  1428. if (Array.isArray(item)) {
  1429. items = item;
  1430. } else items = [item];
  1431. items.forEach(item => {
  1432. if(!item || !item.href)return;
  1433. if(!item.nodeName || item.nodeName!="A"){
  1434. let href=item.href;
  1435. let innerText=item.innerText;
  1436. item=document.createElement("a");
  1437. item.href=href;
  1438. item.innerText=innerText;
  1439. }
  1440. addItem(item);
  1441. });
  1442. } else {
  1443. addItem(item);
  1444. }
  1445. });
  1446. }
  1447. if(urlsArr[1]){
  1448. processEles.forEach(ele=>{
  1449. ele.href=ele.href.replace(new RegExp(urlsArr[1]), urlsArr[2]);
  1450. });
  1451. }
  1452. var retainImage=!!GM_getValue("retainImage");
  1453. var evalCode = urlsArr[3];
  1454. if (evalCode && /^iframe:/.test(evalCode.trim())) {
  1455. evalCode = evalCode.trim().replace("iframe:", "");
  1456. useIframe = true;
  1457. iframeSandbox = false;
  1458. iframeInit = false;
  1459. while (/^(sandbox|init):/.test(evalCode)) {
  1460. iframeSandbox = evalCode.match(/^sandbox:{(.*?)}/);
  1461. if (iframeSandbox) {
  1462. iframeSandbox = iframeSandbox[1];
  1463. evalCode = evalCode.replace(/^sandbox:{(.*?)}/, "");
  1464. }
  1465. iframeInit = evalCode.match(/^init:{(.*?)}/);
  1466. if (iframeInit) {
  1467. iframeInit = iframeInit[1];
  1468. evalCode = evalCode.replace(/^init:{(.*?)}/, "");
  1469. }
  1470. }
  1471. }
  1472. if(evalCode){
  1473. processFunc=(data, cb, url)=>{
  1474. let doc=data;
  1475. if(evalCode.indexOf("return ")==-1){
  1476. if(evalCode.indexOf("@")==0){
  1477. let content="";
  1478. if(retainImage){
  1479. [].forEach.call(data.querySelectorAll("img[src]"), img => {
  1480. let imgTxt=`![img](${canonicalUri(img.getAttribute("src"), location.href)})`;
  1481. let imgTxtNode=document.createTextNode(imgTxt);
  1482. img.parentNode.replaceChild(imgTxtNode, img);
  1483. });
  1484. }
  1485. [].forEach.call(data.querySelectorAll(evalCode.slice(1)), ele=>{
  1486. [].forEach.call(ele.childNodes, child=>{
  1487. if(child.innerHTML){
  1488. child.innerHTML=child.innerHTML.replace(/\<\s*br\s*\>/gi,"\r\n").replace(/\n+/gi,"\n").replace(/\r+/gi,"\r");
  1489. }
  1490. if(child.textContent){
  1491. content+=(child.textContent.replace(/ +/g," ").replace(/([^\r]|^)\n([^\r]|$)/gi,"$1\r\n$2")+"\r\n");
  1492. }
  1493. });
  1494. content+="\r\n";
  1495. });
  1496. return content;
  1497. }else return eval(evalCode);
  1498. }else{
  1499. return Function("data", "doc", "cb", "url", evalCode)(data, doc, cb, url);
  1500. }
  1501. };
  1502. }else{
  1503. if(win.dacProcess){
  1504. processFunc=win.dacProcess;
  1505. }
  1506. }
  1507. filterList(processEles);
  1508. }
  1509. }
  1510. const configPage = "https://hoothin.github.io/UserScripts/DownloadAllContent/";
  1511. 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>';
  1512. function searchRule(){
  1513. GM_openInTab(configPage + "#@" + location.hostname, {active: true});
  1514. }
  1515. if (location.origin + location.pathname == configPage) {
  1516. let exampleNode = document.getElementById("example");
  1517. if (!exampleNode) return;
  1518.  
  1519. exampleNode = exampleNode.parentNode;
  1520. let ruleList = exampleNode.nextElementSibling.nextElementSibling;
  1521. let searchInput = document.createElement("input");
  1522. let inputTimer;
  1523. function searchByInput() {
  1524. clearTimeout(inputTimer);
  1525. inputTimer = setTimeout(() => {
  1526. let curValue = searchInput.value;
  1527. let matchRules = [];
  1528. let dontMatchRules = [];
  1529. if (curValue) {
  1530. for (let i = 0; i < ruleList.children.length; i++) {
  1531. let curRule = ruleList.children[i];
  1532. let aHref = curRule.firstChild.href;
  1533. if (aHref.indexOf(curValue) == -1) {
  1534. dontMatchRules.push(curRule);
  1535. } else {
  1536. matchRules.push(curRule);
  1537. }
  1538. }
  1539. } else {
  1540. dontMatchRules = ruleList.children;
  1541. }
  1542. if (matchRules.length) {
  1543. for (let i = 0; i < dontMatchRules.length; i++) {
  1544. let curRule = dontMatchRules[i];
  1545. curRule.style.display = "none";
  1546. }
  1547. for (let i = 0; i < matchRules.length; i++) {
  1548. let curRule = matchRules[i];
  1549. curRule.style.display = "";
  1550. }
  1551. } else {
  1552. for (let i = 0; i < dontMatchRules.length; i++) {
  1553. let curRule = dontMatchRules[i];
  1554. curRule.style.display = "";
  1555. }
  1556. }
  1557. }, 500);
  1558. }
  1559. searchInput.style.margin = "10px";
  1560. searchInput.style.width = "100%";
  1561. searchInput.placeholder = i18n.searchRule;
  1562. searchInput.addEventListener("input", function(e) {
  1563. searchByInput();
  1564. });
  1565. if (location.hash) {
  1566. let hash = location.hash.slice(1);
  1567. if (hash.indexOf("@") == 0) {
  1568. setTimeout(() => {
  1569. exampleNode.scrollIntoView();
  1570. }, 500);
  1571. searchInput.value = hash.slice(1);
  1572. searchByInput();
  1573. }
  1574. }
  1575. [].forEach.call(ruleList.querySelectorAll("div.highlight"), highlight => {
  1576. highlight.style.position = "relative";
  1577. highlight.innerHTML = highlight.innerHTML + copySvg;
  1578. let svg = highlight.children[1];
  1579. svg.addEventListener("click", function(e) {
  1580. GM_setClipboard(highlight.children[0].innerText);
  1581. svg.style.opacity = 0;
  1582. setTimeout(() => {
  1583. svg.style.opacity = 1;
  1584. }, 1000);
  1585. });
  1586. });
  1587. exampleNode.parentNode.insertBefore(searchInput, ruleList);
  1588.  
  1589.  
  1590. let donateNode = document.querySelector("[alt='donate']");
  1591. if (!donateNode) return;
  1592. let insertPos = donateNode.parentNode.nextElementSibling;
  1593. let radioIndex = 0;
  1594. function createOption(_name, _value, _type) {
  1595. if (!_type) _type = "input";
  1596. let con = document.createElement("div");
  1597. let option = document.createElement("input");
  1598. let cap = document.createElement("b");
  1599. option.type = _type;
  1600. option.value = _value;
  1601. option.checked = _value;
  1602. cap.style.margin = "0px 10px 0px 0px";
  1603. if (_type == "radio") {
  1604. let label = document.createElement("label");
  1605. label.innerText = _name;
  1606. radioIndex++;
  1607. option.id = "radio" + radioIndex;
  1608. label.setAttribute("for", option.id);
  1609. cap.appendChild(label);
  1610. } else {
  1611. if (_type == "input") {
  1612. option.style.flexGrow = "1";
  1613. }
  1614. cap.innerText = _name;
  1615. }
  1616. con.style.margin = "10px 0";
  1617. con.style.display = "flex";
  1618. con.style.alignItems = "center";
  1619. con.appendChild(cap);
  1620. con.appendChild(option);
  1621. insertPos.parentNode.insertBefore(con, insertPos);
  1622. return option;
  1623. }
  1624. let delSelector = createOption(i18n.del, GM_getValue("selectors") || "");
  1625. delSelector.setAttribute("placeHolder", ".mask,.ksam");
  1626. let downThreadNum = createOption(i18n.downThreadNum, GM_getValue("downThreadNum") || "20", "number");
  1627. let customTitle = createOption(i18n.customTitle, GM_getValue("customTitle") || "");
  1628. customTitle.setAttribute("placeHolder", "title");
  1629. let minTxtLength = createOption(i18n.minTxtLength, GM_getValue("minTxtLength") || "100", "number");
  1630. let contentSortUrlValue = GM_getValue("contentSortUrl") || false;
  1631. let contentSortValue = GM_getValue("contentSort") || false;
  1632. let reSortDefault = createOption(i18n.reSortDefault, !contentSortUrlValue && !contentSortValue, "radio");
  1633. let reSortUrl = createOption(i18n.reSortUrl, contentSortUrlValue || false, "radio");
  1634. let contentSort = createOption(i18n.reSort, contentSortValue || false, "radio");
  1635. reSortDefault.name = "sort";
  1636. reSortUrl.name = "sort";
  1637. contentSort.name = "sort";
  1638. let reverse = createOption(i18n.reverse, !!GM_getValue("reverse"), "checkbox");
  1639. let retainImage = createOption(i18n.retainImage, !!GM_getValue("retainImage"), "checkbox");
  1640. let showFilterList = createOption(i18n.showFilterList, !!GM_getValue("showFilterList"), "checkbox");
  1641. let disableNextPage = !!GM_getValue("disableNextPage");
  1642. let nextPage = createOption(i18n.nextPage, !disableNextPage, "checkbox");
  1643. let nextPageReg = createOption(i18n.nextPageReg, GM_getValue("nextPageReg") || "");
  1644. nextPageReg.setAttribute("placeHolder", "^\\s*(下一[页頁张張]|next\\s*page|次のページ)");
  1645. if (disableNextPage) {
  1646. nextPageReg.parentNode.style.display = "none";
  1647. }
  1648. nextPage.onclick = e => {
  1649. nextPageReg.parentNode.style.display = nextPage.checked ? "flex" : "none";
  1650. }
  1651. let saveBtn = document.createElement("button");
  1652. saveBtn.innerText = i18n.saveBtn;
  1653. saveBtn.style.margin = "0 0 20px 0";
  1654. insertPos.parentNode.insertBefore(saveBtn, insertPos);
  1655. saveBtn.onclick = e => {
  1656. GM_setValue("selectors", delSelector.value || "");
  1657. GM_setValue("downThreadNum", downThreadNum.value || 20);
  1658. GM_setValue("minTxtLength", minTxtLength.value || 100);
  1659. GM_setValue("customTitle", customTitle.value || "");
  1660. if (reSortUrl.checked) {
  1661. GM_setValue("contentSortUrl", true);
  1662. GM_setValue("contentSort", false);
  1663. } else if (contentSort.checked) {
  1664. GM_setValue("contentSortUrl", false);
  1665. GM_setValue("contentSort", true);
  1666. } else {
  1667. GM_setValue("contentSortUrl", false);
  1668. GM_setValue("contentSort", false);
  1669. }
  1670. GM_setValue("reverse", reverse.checked);
  1671. GM_setValue("retainImage", retainImage.checked);
  1672. GM_setValue("showFilterList", showFilterList.checked);
  1673. GM_setValue("disableNextPage", !nextPage.checked);
  1674. GM_setValue("nextPageReg", nextPageReg.value || "");
  1675. alert(i18n.saveOk);
  1676. };
  1677. return;
  1678. }
  1679.  
  1680. function setDel(){
  1681. GM_openInTab(configPage + "#操作說明", {active: true});
  1682. return;
  1683. /*var selValue=GM_getValue("selectors");
  1684. var selectors=prompt(i18n.del,selValue?selValue:"");
  1685. GM_setValue("selectors",selectors);
  1686. selValue=GM_getValue("downThreadNum");
  1687. var downThreadNum=prompt(i18n.downThreadNum,selValue?selValue:"20");
  1688. GM_setValue("downThreadNum",downThreadNum);
  1689. var sortByUrl=window.confirm(i18n.reSortUrl);
  1690. GM_setValue("contentSortUrl",sortByUrl);
  1691. if(!sortByUrl)GM_setValue("contentSort",window.confirm(i18n.reSort));*/
  1692. }
  1693.  
  1694. document.addEventListener("keydown", function(e) {
  1695. if(e.keyCode == 120 && e.ctrlKey) {
  1696. fetch(e.shiftKey);
  1697. }
  1698. });
  1699. GM_registerMenuCommand(i18n.fetch, fetch);
  1700. GM_registerMenuCommand(i18n.custom, () => {
  1701. var customRules = GM_getValue("DACrules_" + document.domain);
  1702. var urls = window.prompt(i18n.customInfo, customRules ? customRules : "https://xxx.xxx/book-[20-99].html, https://xxx.xxx/book-[01-10].html");
  1703. if (urls) {
  1704. customDown(urls);
  1705. }
  1706. });
  1707. GM_registerMenuCommand(i18n.setting, setDel);
  1708. GM_registerMenuCommand(i18n.searchRule, searchRule);
  1709. })();