東方永頁機

自動加載並拼接下一分頁內容(適用於論壇、漫畫站、小說站、資訊站、博客等),無需規則支持所有網頁

目前為 2022-03-09 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Pagetual
  3. // @name:zh-CN 东方永页机
  4. // @name:zh-TW 東方永頁機
  5. // @name:ja 東方永頁機
  6. // @name:ru Пейджетуал
  7. // @name:de Pagetual
  8. // @name:es Pagetual
  9. // @name:fr Pagetual
  10. // @name:it Pagetual
  11. // @name:ko 東方永頁機
  12. // @namespace hoothin
  13. // @version 1.5.6.8
  14. // @description Most compatible Auto pager script ever! Simply auto loading paginated web pages.
  15. // @description:zh-CN 自动加载并拼接下一分页内容(适用于论坛、漫画站、小说站、资讯站、博客等),无需规则支持所有网页
  16. // @description:zh-TW 自動加載並拼接下一分頁內容(適用於論壇、漫畫站、小說站、資訊站、博客等),無需規則支持所有網頁
  17. // @description:ja Webページを自動で読み込み継ぎ足し表示を行うブラウザ拡張です
  18. // @description:ru Просто автоматически загрузите следующую страницу
  19. // @description:de Laden Sie einfach automatisch die nächste Seite
  20. // @description:es Carga automática de páginas web paginadas
  21. // @description:fr Chargement automatique des pages Web paginées
  22. // @description:it Caricamento automatico di pagine Web impaginate
  23. // @description:ko 다음 페이지를 자동으로 로드하세요
  24. // @author hoothin
  25. // @include http://*
  26. // @include https://*
  27. // @license MIT
  28. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAdVBMVEUAAAD3VU33VU32VEz8U073VU32VU33VU32VUz0Uk/3VE32VU32VUz2VU32VU32VU32VU33VU33U0z2VU34Wkv3VE32VUz/mpj/nJj2VUz2VU32VE33VEz2VU32VU32VUz3VE32VEz3VE3/mZf2Vkz2VU3/mpilFFolAAAAJXRSTlMA3Lp/GvTBT5YQLuawZ/DOyZwlPQeKc21N04+FX1bqpm9DNoB4T68ePwAAAitJREFUWMPt1tuasiAUBuCFCG5Rs3QybTPV1/1f4v/3PDkyIojn8x5qBrI+ltAfh32/yysmBKvyXb+njb6bDL9kzTd5SzjDAsYT8nFoGSxYe6BVqoNDp2jFDit25BRgVUAODB4YWcETWVTwVNGiGN5iWtBgg4YMCpsoI38dNunmmWyxUTvbPwwbsYR0fIzZLQ0pTG8eieRmBLMmpdH9uimQEf6TNRnXXKLZHixpJtywLzOgMHtFCqdM64DahHRnOE1dsrekm9wr2WtLcAlpdHwcp1pAJySXYnERclzp4+v19jXdmcTvQUJtz+ZaI4i05/V/UGYrCxbaAsOYoNfIKEQxpqQuzCgJJJ/3f42O8ywEZuMVWi/8hODxGj3GW2b0udkbGULLDOjimAG0S3fLGlBnXQM9irG1CiQdVQi0dqQsOSDlyEEz7Vy9OxxfR71VCXsSB23jMrKJYZXSjw57sqgLn5Z0wolsOCz0RyJkyeYjgz7pwwVq20eboZwtVUl2EnN5gJ50dQZFdryATvABRTr/tJXkUMdaAK5pwtCapwtFLskguwuyMh/Sd9WChQ4sIvIUYSk3PYqQvCQlOC04IfN7PkdjOyRKWhdKXMmiAFt9i3sJ5jxoRuR0vqAghxxwHuqfQE5OHGDKOrwEnqs1DgAZ2e4Eev1d45TN7JfhrQLKgfwMFYAsvp33dXII073aVQLI2gN5S58lfmGnKKFtah7nkgnBZB7zlP7Y/QNiTM6sYNzawwAAAABJRU5ErkJggg==
  29. // @grant GM_xmlhttpRequest
  30. // @grant GM_registerMenuCommand
  31. // @grant GM_notification
  32. // @grant GM_getValue
  33. // @grant GM_setValue
  34. // @grant GM_addStyle
  35. // @grant GM_openInTab
  36. // @grant GM_deleteValue
  37. // @grant GM.xmlHttpRequest
  38. // @grant GM.registerMenuCommand
  39. // @grant GM.notification
  40. // @grant GM.getValue
  41. // @grant GM.setValue
  42. // @grant GM.addStyle
  43. // @grant GM.openInTab
  44. // @grant GM.deleteValue
  45. // @supportURL https://github.com/hoothin/UserScripts/issues
  46. // @connect wedata.net
  47. // @connect githubusercontent.com
  48. // @run-at document-idle
  49. // @exclude http://www.toodledo.com/tasks/*
  50. // @exclude http*://maps.google.com*/*
  51. // @exclude *://www.google.*/_/chrome/newtab*
  52. // @exclude *://mega.*/*
  53. // @exclude *://*.mega.*/*
  54. // @exclude *://*.youku.com/v_*
  55. // @exclude *://*pan.baidu.com
  56. // @exclude *://*.iqiyi.com/v_*
  57. // @exclude *://*.iqiyi.com/w_*
  58. // @exclude *://*.iqiyi.com/a_*
  59. // @exclude *://*.le.com/ptv/vplay/*
  60. // @exclude *://v.qq.com/x/cover/*
  61. // @exclude *://v.qq.com/x/page/*
  62. // @exclude *://v.qq.com/tv/*
  63. // @exclude *://*.tudou.com/listplay/*
  64. // @exclude *://*.tudou.com/albumplay/*
  65. // @exclude *://*.tudou.com/programs/view/*
  66. // @exclude *://*.mgtv.com/b/*
  67. // @exclude *://film.sohu.com/album/*
  68. // @exclude *://tv.sohu.com/v/*
  69. // @exclude *://*.bilibili.com/video/*
  70. // @exclude *://*.bilibili.com/bangumi/play/*
  71. // @exclude *://*.baofeng.com/play/*
  72. // @exclude *://vip.pptv.com/show/*
  73. // @exclude *://v.pptv.com/show/*
  74. // @exclude *://www.le.com/ptv/vplay/*
  75. // @exclude *://www.wasu.cn/Play/show/*
  76. // @exclude *://m.v.qq.com/*
  77. // @exclude *://m.iqiyi.com/*
  78. // @exclude *://m.youku.com/alipay_video/*
  79. // @exclude *://m.mgtv.com/b/*
  80. // @exclude *://m.tv.sohu.com/v/*
  81. // @exclude *://m.film.sohu.com/album/*
  82. // @exclude *://m.le.com/ptv/vplay/*
  83. // @exclude *://m.pptv.com/show/*
  84. // @exclude *://m.acfun.cn/v/*
  85. // @exclude *://m.bilibili.com/video/*
  86. // @exclude *://m.bilibili.com/anime/*
  87. // @exclude *://m.bilibili.com/bangumi/play/*
  88. // @exclude *://m.wasu.cn/Play/show/*
  89. // @exclude *://www.youtube.com
  90. // @exclude *://www.youtube.com/
  91. // @exclude *://www.youtube.com/watch*
  92. // @exclude *://baike.baidu.com/*
  93. // @exclude *://*.instagram.com/*
  94. // @exclude *://order.jd.com/*
  95. // @exclude *://pagetual.hoothin.com/*
  96. // @exclude *://hoothin.github.io/PagetualGuide/*
  97. // @connect *
  98. // ==/UserScript==
  99.  
  100. (function() {
  101. 'use strict';
  102.  
  103. if (window.name === 'pagetual-iframe' || (window.frameElement && window.frameElement.name === 'pagetual-iframe')) {
  104. var domloaded = function (){
  105. window.scroll(window.scrollX, 999999);
  106. //window.parent.postMessage('pagetual-iframe:DOMLoaded', '*');
  107. };
  108. if(window.opera){
  109. document.addEventListener('DOMContentLoaded', domloaded, false);
  110. } else {
  111. domloaded();
  112. }
  113. return;
  114. }
  115.  
  116. if(window.top != window.self){
  117. try{
  118. if (top.location.hostname != window.location.hostname || window.top != window.parent) {
  119. return;
  120. }
  121. }catch(e){
  122. return;
  123. }
  124. }
  125.  
  126. const lang = navigator.appName=="Netscape"?navigator.language:navigator.userLanguage;
  127. var i18n=(name, param)=>{
  128. let config={};
  129. switch (lang){
  130. case "zh-CN":
  131. case "zh-SG":
  132. config={
  133. enableDebug:"调试模式,输出信息至控制台",
  134. disable:"暂时禁用",
  135. disableSite:"在此站禁用",
  136. enable:"启用翻页",
  137. toTop:"回到顶部",
  138. toBottom:"前往页尾",
  139. current:"当前页",
  140. forceIframe:"强制拼接",
  141. cancelForceIframe:"取消强制拼接",
  142. configure:"打开配置页",
  143. firstUpdate:"点击此处初始化规则",
  144. update:"更新规则",
  145. click2update:"点击立即更新规则",
  146. loadNow:"立即翻页",
  147. loadConfirm:"要翻几页?(0为不间断)",
  148. noNext:"没有找到下一页,请新建规则",
  149. passSec:"更新于 #t# 秒前",
  150. passMin:"更新于 #t# 分钟前",
  151. passHour:"更新于 #t# 小时前",
  152. passDay:"更新于 #t# 天前",
  153. cantDel:"无法删除内置规则",
  154. confirmDel:"是否确认要删除此规则?",
  155. updateSucc:"更新成功",
  156. beginUpdate:"正在更新,请稍候",
  157. customUrls:"导入规则url,一行一条,AutoPagerize 格式规则需要以\"0|\"开头",
  158. customRules:"输入【东方永页机】格式的自定义规则",
  159. save:"保存设置",
  160. loadingText:"少女祈祷中...",
  161. opacity:"分页隔条不透明值",
  162. hideBar:"空白处双击隐藏分页隔条",
  163. dbClick2Stop:"空白处双击暂停翻页",
  164. sortTitle:"排序在下次更新规则后生效",
  165. autoRun:"自动启用,否则为白名单模式",
  166. inputPageNum:"输入页码跳转",
  167. enableHistory:"翻页后写入历史记录",
  168. initRun:"打开页面后立即尝试翻页,否则滚动至页尾再翻页",
  169. preload:"翻页前预读下一页,加速浏览",
  170. click2ImportRule:"点击下方添加特殊规则库:"
  171. };
  172. break;
  173. case "zh-TW":
  174. case "zh-HK":
  175. config={
  176. enableDebug:"調試模式,輸出信息至控制台",
  177. disable:"暫時禁用",
  178. disableSite:"在此站禁用",
  179. enable:"啟用翻頁",
  180. toTop:"回到頂部",
  181. toBottom:"前往頁尾",
  182. current:"當前頁",
  183. forceIframe:"強制拼接",
  184. cancelForceIframe:"取消强制拼接",
  185. configure:"打開配置頁",
  186. firstUpdate:"點擊此處初始化規則",
  187. update:"更新規則",
  188. click2update:"點擊立即更新規則",
  189. loadNow:"立即翻頁",
  190. loadConfirm:"要翻几頁?(0為不間斷)",
  191. noNext:"沒有找到下一頁,請新建規則",
  192. passSec:"更新于 #t# 秒前",
  193. passMin:"更新于 #t# 分鐘前",
  194. passHour:"更新于 #t# 小時前",
  195. passDay:"更新于 #t# 天前",
  196. cantDel:"無法刪除内置規則",
  197. confirmDel:"是否確認要刪除此規則?",
  198. updateSucc:"更新成功",
  199. beginUpdate:"正在更新,請稍候",
  200. customUrls:"導入規則url,一行一條,AutoPagerize 格式規則需要以\"0|\"開頭",
  201. customRules:"輸入【東方永頁機】格式的自定義規則",
  202. save:"存儲設置",
  203. loadingText:"少女祈禱中...",
  204. opacity:"分頁隔條不透明值",
  205. hideBar:"空白處雙擊隱藏分頁隔條",
  206. dbClick2Stop:"空白處雙擊暫停翻頁",
  207. sortTitle:"排序在下次更新規則後生效",
  208. autoRun:"自動啓用,否則為白名單模式",
  209. inputPageNum:"輸入頁碼跳轉",
  210. enableHistory:"翻頁后寫入歷史記錄",
  211. initRun:"打開頁面后立即嘗試翻頁,否則滾動至頁尾再翻頁",
  212. preload:"翻頁前預讀下一頁,加速瀏覽",
  213. click2ImportRule:"點擊下方添加特殊規則庫:"
  214. };
  215. break;
  216. case "ja":
  217. config = {
  218. enableDebug:"デバッグモード",
  219. disable: "一時的に無効にする",
  220. disableSite:"このサイト無効",
  221. enable: "ページめくりを有効にする",
  222. toTop: "トップに戻る",
  223. toBottom: "ページの下部に移動",
  224. current: "現在のページ",
  225. forceIframe: "強制ステッチ",
  226. cancelForceIframe: "強制ステッチをキャンセル",
  227. configure: "設定ページを開く",
  228. firstUpdate:"ここをクリックしてルールを初期化します",
  229. update: "更新ルール",
  230. click2update:"今すぐルールを更新してください",
  231. loadNow:"今すぐページをめくる",
  232. loadConfirm:"数ページめくりたいですか?(0は途切れない)",
  233. noNext:"次のページが見つかりません、新しいルールを作成してください",
  234. passSec: "#t#秒前に更新",
  235. passMin: "#t#分前に更新",
  236. passHour: "#t#時間前に更新",
  237. passDay: "#t#日前に更新",
  238. cantDel: "組み込みルールを削除できません",
  239. confirmDel: "このルールを削除してもよろしいですか?",
  240. updateSucc: "更新に成功しました",
  241. beginUpdate: "更新中、お待ちください",
  242. customUrls: "インポートルールのURL、1行に1つ、AutoPagerizeフォーマットルールは\"0|\"で始まる必要があります",
  243. customRules: "【東方永頁機】の形式でカスタムルールを入力してください",
  244. save: "設定を保存",
  245. loadingText: "少女祈祷中...",
  246. opacity:"ページネーションバーの不透明値",
  247. hideBar:"空白部分をダブルクリックして、ページ区切り文字を非表示にします",
  248. dbClick2Stop:"空白部分をダブルクリックしてページめくりを一時停止します",
  249. sortTitle:"並べ替えは、次のルールの更新後に有効になります",
  250. autoRun:"自動的に有効",
  251. inputPageNum:"ジャンプするページ番号を入力",
  252. enableHistory:"ページめくり後の履歴を書く",
  253. initRun:"Webページを開いた直後にページをめくる",
  254. preload:"事前に次のページを読む",
  255. click2ImportRule:"以下をクリックして、ルールベースを追加します:"
  256. };
  257. break;
  258. default:
  259. config={
  260. enableDebug:"Enable debug output",
  261. disable:"Disable",
  262. disableSite:"Disable on the site",
  263. enable:"Enable",
  264. toTop:"To Top",
  265. toBottom:"To Bottom",
  266. current:"Current Page",
  267. forceIframe:"Force to join",
  268. cancelForceIframe:"Cancel Force join",
  269. configure:"Configure",
  270. firstUpdate:"Click here to initialize the rules",
  271. update:"Update rules",
  272. click2update:"Click to update rules from url now",
  273. loadNow:"Load next now",
  274. loadConfirm:"How much pages do you want to load? (0 means infinite)",
  275. noNext:"No next link found, please create a new rule",
  276. passSec:"Updated #t# seconds ago",
  277. passMin:"Updated #t# minutes ago",
  278. passHour:"Updated #t# hours ago",
  279. passDay:"Updated #t# days ago",
  280. cantDel:"Can't delete buildin rules",
  281. confirmDel:"Are you sure you want to delete this rule?",
  282. updateSucc:"Update succeeded",
  283. beginUpdate:"Begin update, wait a minute please",
  284. customUrls:"Import rule url, One url per line, rules on AutoPagerize format need to start with \"0|\"",
  285. customRules:"Input custom rules with [Pagetual] format",
  286. save:"Save",
  287. loadingText:"Shojo Now Loading...",
  288. opacity:"Pagination spacer opacity",
  289. hideBar:"Double-click on the blank space to hide the paging spacer",
  290. dbClick2Stop:"Double-click on the blank space to stop",
  291. sortTitle:"Sorting takes effect after the next rule update",
  292. autoRun:"Auto run",
  293. inputPageNum:"Enter page number to jump",
  294. enableHistory:"Write history after page turning",
  295. initRun:"Turn pages immediately after opening",
  296. preload:"Preload next page",
  297. click2ImportRule:"Click to import base rules:"
  298. };
  299. break;
  300. }
  301. return config[name]?config[name].replace("#t#",param):name;
  302. };
  303.  
  304. var noRuleTest=false;
  305. var enableDebug=true;
  306. var debug=str=>{
  307. if(enableDebug){
  308. console.debug(str);
  309. }
  310. };
  311.  
  312. var _GM_xmlhttpRequest,_GM_registerMenuCommand,_GM_notification,_GM_addStyle,_GM_openInTab;
  313. if(typeof GM_xmlhttpRequest!='undefined'){
  314. _GM_xmlhttpRequest=GM_xmlhttpRequest;
  315. }else if(typeof GM!='undefined' && typeof GM.xmlHttpRequest!='undefined'){
  316. _GM_xmlhttpRequest=GM.xmlHttpRequest;
  317. }else{
  318. _GM_xmlhttpRequest=(f)=>{fetch(f.url).then(response=>response.text()).then(data=>{let res={response:data};f.onload(res)}).catch(f.onerror())};
  319. }
  320. if(typeof GM_registerMenuCommand!='undefined'){
  321. _GM_registerMenuCommand=GM_registerMenuCommand;
  322. }else if(typeof GM!='undefined' && typeof GM.registerMenuCommand!='undefined'){
  323. _GM_registerMenuCommand=GM.registerMenuCommand;
  324. }else{
  325. _GM_registerMenuCommand=(s,f)=>{};
  326. }
  327. if(typeof GM_notification!='undefined'){
  328. _GM_notification=GM_notification;
  329. }else if(typeof GM!='undefined' && typeof GM.notification!='undefined'){
  330. _GM_notification=GM.notification;
  331. }else{
  332. _GM_notification=(s)=>{alert(s)};
  333. }
  334. if(typeof GM_openInTab!='undefined'){
  335. _GM_openInTab=GM_openInTab;
  336. }else if(typeof GM!='undefined' && typeof GM.openInTab!='undefined'){
  337. _GM_openInTab=GM.openInTab;
  338. }else{
  339. _GM_openInTab=(s,t)=>{window.open(s)};
  340. }
  341. if(typeof GM_addStyle!='undefined'){
  342. _GM_addStyle=GM_addStyle;
  343. }else if(typeof GM!='undefined' && typeof GM.addStyle!='undefined'){
  344. _GM_addStyle=GM.addStyle;
  345. }else{
  346. _GM_addStyle=cssStr=>{
  347. let styleEle=document.createElement("style");
  348. styleEle.innerHTML=cssStr;
  349. document.head.appendChild(styleEle);
  350. };
  351. }
  352. var _unsafeWindow=(typeof unsafeWindow=='undefined')?window:unsafeWindow;//兼容 ios userscripts 的寫法
  353. var storage={
  354. supportGM: typeof GM_getValue=='function' && typeof GM_getValue('a','b')!='undefined',
  355. supportGMPromise: typeof GM!='undefined' && typeof GM.getValue=='function' && typeof GM.getValue('a','b')!='undefined',
  356. mxAppStorage:(function(){
  357. try{
  358. return window.external.mxGetRuntime().storage;
  359. }catch(e){
  360. }
  361. })(),
  362. operaUJSStorage:(function(){
  363. try{
  364. return window.opera.scriptStorage;
  365. }catch(e){
  366. }
  367. })(),
  368. setItem:function(key,value){
  369. if(this.operaUJSStorage){
  370. this.operaUJSStorage.setItem(key,value);
  371. }else if(this.mxAppStorage){
  372. this.mxAppStorage.setConfig(key,value);
  373. }else if(this.supportGM){
  374. GM_setValue(key,value);
  375. if(value==="" && typeof GM_deleteValue!='undefined'){
  376. GM_deleteValue(key);
  377. }
  378. }else if(this.supportGMPromise){
  379. GM.setValue(key,value);
  380. if(value==="" && typeof GM!='undefined' && typeof GM.deleteValue!='undefined'){
  381. GM.deleteValue(key);
  382. }
  383. }else if(window.localStorage){
  384. window.localStorage.setItem(key,value);
  385. }
  386. },
  387. getItem:function(key,cb){
  388. var value;
  389. if(this.operaUJSStorage){
  390. value=this.operaUJSStorage.getItem(key);
  391. }else if(this.mxAppStorage){
  392. value=this.mxAppStorage.getConfig(key);
  393. }else if(this.supportGM){
  394. value=GM_getValue(key);
  395. }else if(this.supportGMPromise){
  396. value=GM.getValue(key).then(v=>{cb(v)});
  397. return;
  398. }else if(window.localStorage){
  399. value=window.localStorage.getItem(key);
  400. };
  401. cb(value);
  402. }
  403. };
  404. var rulesData={},ruleUrls,updateDate,configPage="https://github.com/hoothin/UserScripts/tree/master/Pagetual";
  405. var ruleImportUrlReg=/greasyfork\.org\/.*scripts\/438684[^\/]*(\/discussions|\/?$)|github\.com\/hoothin\/UserScripts\/(tree\/master\/Pagetual|issues)/i;
  406. var allOfBody="body>*";
  407. _GM_registerMenuCommand(i18n("configure"), ()=>{
  408. _GM_openInTab(configPage,{active:true});
  409. });
  410.  
  411. function getElementByXpath(xpath, contextNode, doc){
  412. doc = doc || document;
  413. contextNode = contextNode || doc;
  414. try {
  415. var result = doc.evaluate(xpath, contextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
  416. return result.singleNodeValue && result.singleNodeValue.nodeType === 1 && result.singleNodeValue;
  417. } catch (err) {
  418. throw new Error(`Invalid xpath: ${xpath}`);
  419. }
  420. }
  421.  
  422. function getAllElementsByXpath(xpath, contextNode, doc){
  423. doc = doc || document;
  424. contextNode = contextNode || doc;
  425. var result = [];
  426. try {
  427. var query = doc.evaluate(xpath, contextNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  428. for (var i = 0; i < query.snapshotLength; i++) {
  429. var node = query.snapshotItem(i);
  430. if (node.nodeType === 1) result.push(node);
  431. }
  432. } catch (err) {
  433. throw new Error(`Invalid xpath: ${xpath}`);
  434. }
  435. return result;
  436. }
  437.  
  438. class RuleParser {
  439. constructor() {
  440. this.hpRules=[];
  441. this.customRules=[];
  442. this.rules=[];
  443. this.pageDoc=document;
  444. this.nextLinkHref=null;
  445. this.oldUrl="";
  446. this.curUrl=location.href;
  447. this.curSiteRule={};
  448. }
  449.  
  450. initSavedRules(callback){
  451. var self=this;
  452. storage.getItem("hpRules", hpRules=>{
  453. if(hpRules)self.hpRules=hpRules;
  454. storage.getItem("customRules", customRules=>{
  455. if(customRules)self.customRules=customRules;
  456. storage.getItem("rules", rules=>{
  457. if(rules)self.rules=rules;
  458. callback();
  459. });
  460. });
  461. });
  462. }
  463.  
  464. saveCurSiteRule(){
  465. if(!this.curSiteRule || !this.curSiteRule.url || this.curSiteRule.singleUrl)return;
  466. this.hpRules=this.hpRules.filter(item=>{return item&&item.url!=this.curSiteRule.url});
  467. this.hpRules.unshift(this.curSiteRule);
  468. if(this.hpRules.length>30){
  469. this.hpRules.pop();
  470. }
  471. storage.setItem("hpRules", this.hpRules);
  472. }
  473.  
  474. requestJSON(url, callback){
  475. _GM_xmlhttpRequest({
  476. url: url,
  477. method: 'GET',
  478. timeout: 20000,
  479. onload: function(res) {
  480. let json=null;
  481. try{
  482. json=JSON.parse(res.response||res.responseText);
  483. }catch(e){
  484. debug(e);
  485. }
  486. callback(json);
  487. },
  488. onerror: function(e) {
  489. callback(null, e);
  490. },
  491. ontimeout: function(e) {
  492. callback(null, e);
  493. }
  494. });
  495. }
  496.  
  497. formatRule(item, type, from){
  498. switch(type){
  499. case 0:
  500. return {
  501. from:from,
  502. type:type,
  503. name:item.name,
  504. action:item.data.forceIframe=="true"?1:0,
  505. url:item.data.url,
  506. pageElement:item.data.pageElement,
  507. nextLink:item.data.nextLink,
  508. insert:item.data.insertBefore,
  509. insertPos:1,
  510. updatedAt:item.data.updated_at,
  511. css:item.data.Stylus+item.data.CSS,
  512. pageAction:item.data.bookmarklet
  513. };
  514. break;
  515. case 1:
  516. default:
  517. item.from=from;
  518. if(typeof(item.type) == "undefined")item.type=type;
  519. return item;
  520. break;
  521. }
  522. return null;
  523. }
  524.  
  525. addRuleByUrl(url, type, from, callback) {
  526. if(url.indexOf("?")==-1){
  527. url=url+"?"+Date.now();
  528. }else{
  529. url=url+"&"+Date.now();
  530. }
  531. this.requestJSON(url, (json,err)=>{
  532. if(!json){
  533. debug("Update "+url+" rules fail!");
  534. debug(err);
  535. }
  536. this.addRules(json, type, from);
  537. callback(json, err);
  538. });
  539. }
  540.  
  541. addRules(rules, type, from) {
  542. if(rules && rules.length>0){
  543. this.rules=this.rules.filter(item=>{return item.from!=from});
  544. rules.forEach(item=>{
  545. let rule=this.formatRule(item, type, from);
  546. if(rule){
  547. this.rules.unshift(rule);
  548. }
  549. });
  550. }
  551. }
  552.  
  553. getRule(callback) {
  554. if(noRuleTest){
  555. this.curSiteRule={};
  556. this.curSiteRule.url=location.origin+location.pathname;
  557. this.curSiteRule.singleUrl=true;
  558. callback();
  559. return;
  560. }
  561. if(this.curSiteRule && this.curSiteRule.url){
  562. return this.curSiteRule;
  563. }
  564. var self=this;
  565.  
  566. function setRule(r){
  567. self.curSiteRule=r;
  568. debug(r);
  569. callback();
  570. }
  571.  
  572. function ruleMatch(r){
  573. let pageElement,nextLink,insert;
  574. if(r.pageElement)pageElement=r.type==0?getElementByXpath(r.pageElement):document.querySelector(r.pageElement);
  575. if(r.nextLink)nextLink=r.type==0?getElementByXpath(r.nextLink):document.querySelector(r.nextLink);
  576. if(r.insert)insert=r.type==0?getElementByXpath(r.insert):document.querySelector(r.insert);
  577. return !((r.pageElement && !pageElement) ||
  578. (r.nextLink && !nextLink) ||
  579. (r.insert && !insert));
  580. }
  581.  
  582. function checkRule(r){
  583. let urlReg=new RegExp(r.url, "i");
  584. if(urlReg.test(location.href)){
  585. if(r.wait){
  586. let waitTime=500,checkEval;
  587. if(isNaN(r.wait)){
  588. try{
  589. checkEval=Function("doc",'"use strict";' + r.wait);
  590. }catch(e){
  591. debug(e);
  592. }
  593. }else{
  594. waitTime=r.wait;
  595. }
  596. let checkReady=()=>{
  597. setTimeout(()=>{
  598. if(!ruleMatch(r) || (checkEval && !checkEval(document))){
  599. checkReady();
  600. }else{
  601. setRule(r);
  602. }
  603. },parseInt(waitTime));
  604. };
  605. checkReady();
  606. return true;
  607. }
  608. if(r.pinUrl){
  609. setRule(r);
  610. return true;
  611. }
  612. if(!ruleMatch(r)){
  613. return false;
  614. }
  615. setRule(r);
  616. return true;
  617. }
  618. return false;
  619. }
  620.  
  621. for(let i in this.hpRules){
  622. let rule=this.hpRules[i];
  623. if(!rule || !rule.url)continue;
  624. if(rule.singleUrl){
  625. if(location.origin+location.pathname==rule.url){
  626. setRule(rule);
  627. return;
  628. }
  629. continue;
  630. }
  631. if(checkRule(rule))return;
  632. }
  633. for(let i in this.customRules){
  634. let rule=this.customRules[i];
  635. if(!rule || !rule.url)continue;
  636. if(checkRule(rule))return;
  637. }
  638. let r=0;
  639. function searchByTime(){
  640. setTimeout(()=>{
  641. let end=r+80;
  642. end=end>self.rules.length?self.rules.length:end;
  643. for(;r<end;r++){
  644. let rule=self.rules[r];
  645. if(checkRule(rule))return;
  646. }
  647. if(end>=self.rules.length){
  648. self.curSiteRule={};
  649. self.curSiteRule.url=location.origin+location.pathname;
  650. self.curSiteRule.singleUrl=true;
  651. callback();
  652. return;
  653. }else{
  654. searchByTime();
  655. }
  656. },20);
  657. }
  658. searchByTime();
  659. }
  660.  
  661. geneSelector(ele){
  662. let selector=ele.tagName;
  663. //Google id class都是隨機。百度更過分,style script順序都是隨機的
  664. //if(ele.id) selector += '#' + ele.id;
  665. //if(ele.classList) selector += [].map.call(ele.classList,d=>'.'+d).join('');
  666. let parent = ele.parentElement;
  667. if(parent){
  668. let i,j=0;
  669. for(i=0;i<parent.children.length;i++){
  670. if(parent.children[i].tagName==selector){
  671. j++;
  672. if(parent.children[i]==ele){
  673. break;
  674. }
  675. }
  676. }
  677. selector = this.geneSelector(parent) + ' > ' + selector + (parent.tagName=="HTML"?"":`:nth-of-type(${j})`);
  678. }
  679. return selector;
  680. }
  681.  
  682. getPageElement(doc, curWin, dontFind) {
  683. let pageElement=null;
  684. let self=this;
  685. if(this.curSiteRule.pageElement){
  686. pageElement=this.curSiteRule.type==0?getAllElementsByXpath(this.curSiteRule.pageElement,doc,doc):doc.querySelectorAll(this.curSiteRule.pageElement);
  687. }
  688. if((!pageElement || pageElement.length==0) && curWin && !dontFind){
  689. let body=doc.body;
  690. if(!body)return null;
  691. let bodyHeight=parseInt(body.scrollHeight);
  692. let curHeight=bodyHeight;
  693. function checkElement(ele){
  694. if(ele.childNodes && ele.childNodes.length==1)ele=ele.childNodes[0];
  695. if(ele.tagName=="PICTURE"){
  696. self.curSiteRule.pageElement=self.geneSelector(ele.parentNode)+">"+ele.tagName;
  697. debug(self.curSiteRule.pageElement);
  698. return [ele];
  699. }
  700. if(curHeight/bodyHeight<=0.30){
  701. self.curSiteRule.pageElement=allOfBody;
  702. debug(self.curSiteRule.pageElement);
  703. return [body];
  704. }
  705. if(ele.tagName=="TBODY" || ele.tagName=="UL"){
  706. self.curSiteRule.pageElement=self.geneSelector(ele)+">*";
  707. if(ele.children.length>0 && ele.children[0].querySelector("th")){
  708. self.curSiteRule.pageElement+=":not(:first-child)";
  709. }
  710. debug(self.curSiteRule.pageElement);
  711. return ele.children;
  712. }
  713. if(ele.children.length==0 && !self.curSiteRule.pageElement){
  714. if(ele.parentNode.tagName=="P")ele=ele.parentNode;
  715. self.curSiteRule.pageElement=self.geneSelector(ele.parentNode)+">"+ele.tagName;
  716. debug(self.curSiteRule.pageElement);
  717. return [ele];
  718. }
  719. let i,maxHeight=curHeight*0.6,curMaxEle=null,curMaxArea=0,maxWidth=0;
  720. let isHori=true;
  721. let offsetTop=ele.children[0].offsetTop;
  722. for(i=1;i<ele.children.length;i++){
  723. if(ele.children[i].offsetTop!=offsetTop){
  724. isHori=false;
  725. break;
  726. }
  727. }
  728. for(i=0;i<ele.children.length;i++){
  729. let curNode=ele.children[i];
  730. if(curNode.tagName=="CANVAS")continue;
  731. if(curNode.tagName!="IMG" && curNode.innerHTML=="")continue;
  732. let comStyle=curWin.getComputedStyle(curNode);
  733. let h=parseInt(curNode.scrollHeight);
  734. let w=parseInt(curNode.scrollWidth);
  735. if(isNaN(h) || isNaN(w))continue;
  736. if(isHori && h==0)continue;
  737. let a=h*w+h,moreChild=curNode.children[0];
  738. while(moreChild){
  739. comStyle=curWin.getComputedStyle(moreChild);
  740. let ch=parseInt(moreChild.scrollHeight);
  741. let cw=parseInt(moreChild.scrollWidth);
  742. if(h<ch)h=ch;
  743. if(moreChild.innerText!="" && !isNaN(ch) && !isNaN(cw)){
  744. a+=ch*cw;
  745. }
  746. moreChild=moreChild.nextElementSibling;
  747. }
  748. let isMax=false;
  749. if(isHori){
  750. if(maxWidth<w){
  751. isMax=true;
  752. }else if(maxWidth==w && curMaxArea<a){
  753. isMax=true;
  754. }
  755. }else{
  756. isMax=curMaxArea<a;
  757. }
  758. if(curMaxEle==null || isMax){
  759. if(h>0 || !isHori)curHeight=h;
  760. curMaxArea=a;
  761. maxWidth=w;
  762. curMaxEle=curNode;
  763. }
  764. }
  765. if(curMaxEle && (isHori || curHeight>maxHeight)){
  766. return checkElement(curMaxEle);
  767. }
  768. if(ele.tagName=="P" || ele.tagName=="BR")ele=ele.parentNode;
  769. self.curSiteRule.pageElement=self.geneSelector(ele);
  770. if(ele.children.length>1){
  771. let middleChild=ele.children[parseInt(ele.children.length/2)];
  772. if((middleChild.style && middleChild.style.position=="absolute" && middleChild.style.left && middleChild.style.top) || ele.tagName=="UL" || curHeight==0){
  773. ele=[ele];
  774. }else{
  775. self.curSiteRule.pageElement+=">*";
  776. ele=ele.children;
  777. }
  778. }else{
  779. ele=[ele];
  780. }
  781. debug(self.curSiteRule.pageElement);
  782. return ele;
  783. }
  784. pageElement=checkElement(body);
  785. if(pageElement)this.saveCurSiteRule();
  786. }
  787. /*if(this.insert && this.insert.parentNode && pageElement && pageElement[0]){
  788. let example=this.insertPos==2?this.insert.children[0]:this.insert;
  789. let inTable=example.parentNode.tagName=="TABLE" ||
  790. example.tagName=="TR" ||
  791. example.tagName=="TBODY" ||
  792. (example.previousElementSibling && example.previousElementSibling.tagName=="TR") ||
  793. (example.previousElementSibling && example.previousElementSibling.tagName=="TBODY");
  794. if(inTable && pageElement[0].tagName!="TR" && pageElement[0].tagName!="TBODY"){
  795. pageElement=null;
  796. }
  797. }*/
  798. return pageElement;
  799. }
  800.  
  801. getPage(doc){
  802. if(_unsafeWindow.Discourse)return {};
  803. let canSave=false;//發現頁碼選擇器在其他頁對不上,還是別保存了
  804. let url=this.curUrl.replace("#!","").replace("index.php?","?");
  805. let pageNum=1,preStr="",afterStr="";
  806. let pageMatch1=url.match(/(.*[a-z\/\-_](?:p|page)?\/?)(\d+)(\.s?html?$|\/?$)/i);
  807. let pageMatch2=url.match(/(.*[\?&]p(?:age)?=)(\d+)($|[#&].*)/i);
  808. if(pageMatch1){
  809. preStr=pageMatch1[1];
  810. pageNum=parseInt(pageMatch1[2]);
  811. afterStr=pageMatch1[3];
  812. }else if(pageMatch2){
  813. preStr=pageMatch2[1];
  814. pageNum=parseInt(pageMatch2[2]);
  815. afterStr=pageMatch2[3];
  816. }
  817. let curPage=doc,i,cur,jsNext;
  818. let next=curPage.querySelector(".page-next>a")||
  819. curPage.querySelector("a.next_page")||
  820. curPage.querySelector("#next_page")||
  821. curPage.querySelector(".nextPage")||
  822. curPage.querySelector("a[data-pagination=next]")||
  823. curPage.querySelector(".pagination a[rel=next]")||
  824. curPage.querySelector(".pagination-nav__item--next>a")||
  825. curPage.querySelector("a.pageright")||
  826. curPage.querySelector("a#rightFix")||
  827. curPage.querySelector("a.next")||
  828. curPage.querySelector("a#next")||
  829. curPage.querySelector(".next>a")||
  830. curPage.querySelector(".next>button")||
  831. curPage.querySelector("a[alt=next]")||
  832. curPage.querySelector("[title=next]");
  833. if(next && (!next.href || /^javascript:/.test(next.href))){
  834. jsNext=next;
  835. next=null;
  836. }
  837. if(!next){
  838. next=curPage.querySelectorAll("[aria-label='Next']");
  839. if(next && next.length==1){
  840. next=next[0];
  841. if(!next.href || /^javascript:/.test(next.href)){
  842. jsNext=next;
  843. next=null;
  844. }
  845. }else{
  846. next=null;
  847. }
  848. }
  849. if(!next){
  850. next=curPage.querySelectorAll("[aria-label='Next page']");
  851. if(next && next.length==1){
  852. next=next[0];
  853. if(!next.href || /^javascript:/.test(next.href)){
  854. jsNext=next;
  855. next=null;
  856. }
  857. }else{
  858. next=null;
  859. }
  860. }
  861. if(!next){
  862. let pageDiv=curPage.querySelector("div.wp-pagenavi");
  863. if(pageDiv){
  864. cur=pageDiv.querySelector("span.current");
  865. if(cur){
  866. next=cur.nextSibling;
  867. }
  868. }else{
  869. cur=curPage.querySelector("div.article-paging>span");
  870. if(cur){
  871. next=cur.nextElementSibling;
  872. }
  873. }
  874. }
  875. if(!next){
  876. let pageDiv=curPage.querySelector("div.pages>ul");
  877. if(pageDiv){
  878. cur=pageDiv.querySelector("li>b");
  879. if(cur)next=cur.parentNode.nextElementSibling;
  880. if(next)next=next.querySelector("a");
  881. }
  882. }
  883. if(!next){
  884. cur=curPage.querySelector(".number>ul>li.active");
  885. if(cur)next=cur.nextElementSibling;
  886. if(next)next=next.querySelector("a");
  887. }
  888. if(!next){
  889. let aTags=curPage.querySelectorAll("a");
  890. let next1,next2,next3,next4,nextJs1,nextJs2,nextJs3;
  891. for(i=aTags.length-1;i>=0;i--){
  892. let aTag=aTags[i];
  893. if(aTag.innerText=="§")continue;
  894. if(aTag.style.display=="none")continue;
  895. if(next1 && next2 && next3 && next4)break;
  896. if(aTag.href && /next$/i.test(aTag.href))continue;
  897. if(!next1){
  898. if(/^[下后後][一1]?[页頁张張]|^next( page)?\s*›?$|次のページ/i.test(aTag.innerText.trim())){
  899. if(aTag.innerText.length>15)continue;
  900. if(!aTag.href || /^javascript:/.test(aTag.href)){
  901. if(!nextJs1)nextJs1=aTag;
  902. }else{
  903. next1=aTag;
  904. }
  905. }
  906. }
  907. if(!next2){
  908. if(/^[下后後][一1]?[章话話]/i.test(aTag.innerText.trim())){
  909. if(!aTag.href || /^javascript:/.test(aTag.href)){
  910. if(!nextJs2)nextJs2=aTag;
  911. }else{
  912. next2=aTag;
  913. }
  914. }
  915. }
  916. if(!next3){
  917. if(aTag.innerText=="&gt;" || aTag.innerText=="▶" || aTag.innerText==">" || aTag.innerText=="›" || /nextpage/i.test(aTag.className)){
  918. if(!aTag.href || /^javascript:/.test(aTag.href)){
  919. if(!nextJs3)nextJs3=aTag;
  920. }else{
  921. next3=aTag;
  922. }
  923. }
  924. }
  925. if(!aTag.href || /^javascript:/.test(aTag.href))continue;
  926. if(!next4){
  927. if(pageNum<999 && aTag.href.replace("?&","?").replace("#!","").replace("index.php?","?").replace(preStr,"").replace(afterStr,"")==pageNum+1){
  928. next4=aTag;
  929. }else if(this.curUrl!=aTag.href && aTag.href.replace("?&","?").replace("index.php?","?").indexOf(url)!=-1 && /^[\/\?&]?[_-]?(p|page)?=?\/?2(\/|\?|&|$)/i.test(aTag.href.replace(url,"").replace(/\.s?html?$/i,""))){
  930. let curHref=aTag.getAttribute("href");
  931. let pageOne=curHref.replace(/\/2(\/|\?|&|$)/,"/1$1");
  932. if(pageOne==curHref)pageOne=null;
  933. else pageOne=curPage.querySelector(`a[href='${pageOne}']`);
  934. if(!pageOne)next4=aTag;
  935. }
  936. }
  937. }
  938. next=next1||next3||next4||next2||nextJs1||nextJs3||nextJs2;
  939. }
  940. if(!next)next=jsNext;
  941. if(next && next.classList.contains("results-more"))next=null;
  942. return {next:next,canSave:canSave};
  943. }
  944.  
  945. canonicalUri(src, base_path) {
  946. if(src.charAt(0)=="#")return location.href+src;
  947. var root_page = /^[^?#]*\//.exec(location.href)[0],
  948. root_domain = /^\w+\:\/\/\/?[^\/]+/.exec(root_page)[0],
  949. absolute_regex = /^\w+\:\/\//;
  950. src=src.replace(/\.\//,"");
  951. if (/^\/\/\/?/.test(src)){
  952. src = location.protocol + src;
  953. }
  954. else if (!absolute_regex.test(src) && src.charAt(0) != "/"){
  955. src = (base_path || "") + src;
  956. }
  957. return (absolute_regex.test(src) ? src : ((src.charAt(0) == "/" ? root_domain : root_page) + src));
  958. }
  959.  
  960. getLinkByPage(url, pageNum) {
  961. if(!url)return;
  962. if(this.curSiteRule.pageNum){
  963. let result=this.curSiteRule.pageNum;
  964. let strMatch=result.match(/\{.*?}/);
  965. if(!strMatch)return null;
  966. let urlReg=new RegExp("("+result.replace(strMatch[0], ")\\d+(")+")");
  967. let code=strMatch[0].replace(/^{/,"").replace(/}$/,"").replace(/\$p/g,pageNum);
  968. if(code==pageNum){
  969. result=url.replace(urlReg,"$1"+code+"$2");
  970. }else{
  971. try{
  972. code=Function('"use strict";return ' + code)();
  973. result=url.replace(urlReg,"$1"+code+"$2");
  974. }catch(e){
  975. debug(e);
  976. }
  977. }
  978. return result==url?url.replace(/([&\/\?](p=|page[=\/]))\d+/i, "$1"+pageNum):result;
  979. }else{
  980. return url.replace(/([&\/\?](p=|page[=\/]))\d+/i, "$1"+pageNum);
  981. }
  982. }
  983.  
  984. getNextLink(doc) {
  985. let nextLink=null,page;
  986. if(this.curSiteRule.pageElementByJs){
  987. this.nextLinkHref="#";
  988. return true;
  989. }else if(this.curSiteRule.nextLinkByJs){
  990. try{
  991. let targetUrl=Function("doc",'"use strict";' + this.curSiteRule.nextLinkByJs)(doc);
  992. if(targetUrl)nextLink={href:targetUrl};
  993. }catch(e){
  994. debug(e);
  995. }
  996. }else if(this.curSiteRule.nextLinkByUrl){
  997. let targetUrl=this.curUrl.replace(new RegExp(this.curSiteRule.nextLinkByUrl[0]), this.curSiteRule.nextLinkByUrl[1]);
  998. if(targetUrl != this.curUrl){
  999. let reps=targetUrl.match(/{.*?}/g);
  1000. if(reps){
  1001. reps.forEach(rep=>{
  1002. let code=rep.replace("{","").replace("}","");
  1003. let result=code.match(/^(\d+)\+1$/);
  1004. if(result){
  1005. result=parseInt(result[1])+1;
  1006. }else{
  1007. try{
  1008. result=Function('"use strict";return ' + code)();
  1009. }catch(e){
  1010. debug(e);
  1011. }
  1012. }
  1013. targetUrl=targetUrl.replace(rep, result);
  1014. });
  1015. }
  1016. }
  1017. nextLink={href:targetUrl};
  1018. }else if(this.curSiteRule.nextLink){
  1019. if(this.curSiteRule.nextLink!="0"){
  1020. nextLink=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.nextLink,doc,doc):doc.querySelector(this.curSiteRule.nextLink);
  1021. }
  1022. }else{
  1023. page=this.getPage(doc);
  1024. nextLink=page.next;
  1025. if(nextLink){
  1026. if(nextLink.tagName=="INPUT" && nextLink.parentNode.tagName=="FORM"){
  1027. let params=[];
  1028. let form=nextLink.parentNode;
  1029. [].forEach.call(form.querySelectorAll("input"), input=>{
  1030. params.push(input.name+'='+input.value);
  1031. });
  1032. nextLink.href=form.action+'?'+params.join('&');
  1033. }
  1034. if(nextLink.classList.contains("noClick")){
  1035. this.nextLinkHref=false;
  1036. return null;
  1037. }else if(doc==document){
  1038. if((!nextLink.href || /^javascript:/.test(nextLink.href)) && !isVisible(nextLink, _unsafeWindow)){
  1039. this.nextLinkHref=false;
  1040. return null;
  1041. }else{
  1042. let nextLinkCs=_unsafeWindow.getComputedStyle(nextLink);
  1043. if(nextLinkCs.cursor=="not-allowed"){
  1044. this.nextLinkHref=false;
  1045. return null;
  1046. }
  1047. }
  1048. }
  1049. }
  1050. }
  1051. if(nextLink){
  1052. if(nextLink.href===""){
  1053. this.nextLinkHref=false;
  1054. }else if(nextLink.href && (nextLink.href==this.curUrl || nextLink.href==this.oldUrl)){
  1055. this.nextLinkHref=false;
  1056. }else if(/^javascript:/.test(nextLink.href) && (this.curSiteRule.action==0 || this.curSiteRule.action==1)){
  1057. this.nextLinkHref=false;
  1058. }else{
  1059. this.nextLinkHref=(nextLink.href && !/^javascript:/.test(nextLink.href))?this.canonicalUri(nextLink.href):"#";
  1060. if(doc==document)debug(nextLink);
  1061. }
  1062. }else{
  1063. this.nextLinkHref=false;
  1064. }
  1065. this.preload();
  1066. return nextLink;
  1067. }
  1068.  
  1069. preload(){
  1070. if(!rulesData.preload)return;
  1071. if(!this.nextLinkHref || this.nextLinkHref=="#")return;
  1072. let self=this;
  1073. if(this.curSiteRule && this.curSiteRule.action==1){
  1074. if(!this.preloadIframe){
  1075. this.preloadIframe = document.createElement('iframe');
  1076. let iframe = this.preloadIframe;
  1077. iframe.name = 'pagetual-iframe';
  1078. iframe.width = '100%';
  1079. iframe.height = '0';
  1080. iframe.frameBorder = '0';
  1081. if(ruleParser.curSiteRule.sandbox!=false){
  1082. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1083. }
  1084. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1085. iframe.addEventListener('load', function (e) {
  1086. try{
  1087. let doc=iframe.contentDocument || iframe.contentWindow.document;
  1088. var body = doc.body;
  1089. if (body && body.firstChild) {
  1090. self.lazyImgAction(body.children);
  1091. }
  1092. }catch(e){
  1093. return;
  1094. }
  1095. }, false);
  1096. document.body.appendChild(iframe);
  1097. }
  1098. this.preloadIframe.src = this.nextLinkHref;
  1099. }else{
  1100. _GM_xmlhttpRequest({
  1101. url: this.nextLinkHref,
  1102. method: 'GET',
  1103. overrideMimeType: 'text/html;charset='+document.charset,
  1104. headers: {
  1105. 'Referer': location.href
  1106. },
  1107. timeout: 5000,
  1108. onload: function(res) {
  1109. var doc=null;
  1110. try {
  1111. doc=document.implementation.createHTMLDocument('');
  1112. doc.documentElement.innerHTML=res.response;
  1113. var body = doc.body;
  1114. if (body && body.firstChild) {
  1115. self.lazyImgAction(body.children);
  1116. }
  1117. if(!self.preloadDiv){
  1118. self.preloadDiv = document.createElement('div');
  1119. self.preloadDiv.id = "pagetual-preload";
  1120. self.preloadDiv.style.cssText = 'display:none!important;';
  1121. document.body.appendChild(self.preloadDiv);
  1122. self.checkedImgs={};
  1123. }
  1124. [].forEach.call(doc.images, i=>{
  1125. let iSrc=i.src;
  1126. if(iSrc && !self.checkedImgs[iSrc]){
  1127. self.checkedImgs[iSrc] = true;
  1128. let img = document.createElement('img');
  1129. img.src = iSrc;
  1130. self.preloadDiv.appendChild(img);
  1131. }
  1132. });
  1133. }
  1134. catch (e) {
  1135. return;
  1136. }
  1137. }
  1138. });
  1139. }
  1140. }
  1141.  
  1142. getInsert(refresh) {
  1143. if(refresh){
  1144. this.insert=null;
  1145. }
  1146. if(this.insert && !refresh){
  1147. let parent=this.insert;
  1148. while(parent && parent.nodeName!="BODY"){
  1149. parent=parent.parentNode;
  1150. }
  1151. if(parent && parent.nodeName=="BODY"){
  1152. return this.insert;
  1153. }
  1154. }
  1155. if(this.curSiteRule.insert){
  1156. this.insert=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.insert,document):document.querySelector(this.curSiteRule.insert);
  1157. }else{
  1158. let pageElement=this.getPageElement(document, _unsafeWindow);
  1159. if(pageElement && pageElement.length>0){
  1160. var pELast = pageElement[pageElement.length - 1];
  1161. this.insert = pELast.nextSibling ? pELast.nextSibling : pELast.parentNode.appendChild(document.createTextNode(' '));
  1162. }
  1163. }
  1164. return this.insert;
  1165. }
  1166.  
  1167. pageInit(doc,eles){
  1168. let code=this.curSiteRule.pageInit;
  1169. if(code){
  1170. try{
  1171. Function("doc","eles",'"use strict";' + code)(doc,eles);
  1172. }catch(e){
  1173. debug(e);
  1174. }
  1175. }
  1176. }
  1177.  
  1178. pageAction(doc,eles){
  1179. let code=this.curSiteRule.pageAction;
  1180. if(code){
  1181. try{
  1182. Function("doc","eles",'"use strict";' + code)(doc,eles);
  1183. }catch(e){
  1184. debug(e);
  1185. }
  1186. }
  1187. this.lazyImgAction(eles);
  1188. }
  1189.  
  1190. lazyImgAction(eles){
  1191. let setLazyImg=img=>{
  1192. let realSrc;
  1193. if(img.getAttribute("_src") && !img.src){
  1194. realSrc=img.getAttribute("_src");
  1195. }else if(img.dataset && img.dataset.original){
  1196. realSrc=img.dataset.original;
  1197. }else if(img.dataset && img.dataset.src){
  1198. realSrc=img.dataset.src;
  1199. }else if(img._lazyrias && img._lazyrias.srcset){
  1200. realSrc=img._lazyrias.srcset[img._lazyrias.srcset.length-1];
  1201. }else if(img.dataset && img.dataset.origFile){
  1202. realSrc=img.dataset.origFile;
  1203. }else if(img.srcset){
  1204. var srcs=img.srcset.split(","),largeSize=0;
  1205. srcs.forEach(srci=>{
  1206. let srcInfo=srci.trim().split(" "),curSize=parseInt(srcInfo[1]);
  1207. if(srcInfo[1] && curSize>largeSize){
  1208. largeSize=curSize;
  1209. realSrc=srcInfo[0];
  1210. }
  1211. });
  1212. }
  1213. if(realSrc){
  1214. img.src=realSrc;
  1215. img.style.display="block";
  1216. }
  1217. };
  1218. [].forEach.call(eles, ele=>{
  1219. if(ele.tagName=="IMG"){
  1220. setLazyImg(ele);
  1221. }else{
  1222. [].forEach.call(ele.querySelectorAll("img"), img=>{
  1223. setLazyImg(img);
  1224. });
  1225. }
  1226. if(ele.tagName=="A" && ele.classList.contains("lazyload")){
  1227. if(ele.dataset.original){
  1228. ele.style.backgroundImage='url("'+ele.dataset.original+'")';
  1229. }
  1230. }else{
  1231. [].forEach.call(ele.querySelectorAll("a.lazyload"), a=>{
  1232. if(a.dataset.original){
  1233. a.style.backgroundImage='url("'+a.dataset.original+'")';
  1234. }
  1235. });
  1236. }
  1237. });
  1238. let lazyImgSrc=this.curSiteRule.lazyImgSrc;
  1239. if(lazyImgSrc){
  1240. [].forEach.call(eles, ele=>{
  1241. [].forEach.call(ele.querySelectorAll("img"), img=>{
  1242. if(img.getAttribute(lazyImgSrc)){
  1243. img.src=img.getAttribute(lazyImgSrc);
  1244. }
  1245. });
  1246. });
  1247. }
  1248. }
  1249.  
  1250. initPage(callback){
  1251. let self=this;
  1252. curPage=1;
  1253. //if(this.curSiteRule.url && !this.curSiteRule.singleUrl)return;
  1254. this.curSiteRule={};
  1255. this.pageDoc=document;
  1256. this.nextLinkHref=null;
  1257. this.curUrl=location.href;
  1258. this.getRule(()=>{
  1259. if(self.curSiteRule.enable==0){
  1260. debug("Stop as rule disable");
  1261. isPause=true;
  1262. return;
  1263. }
  1264. if(self.curSiteRule && !self.curSiteRule.singleUrl){
  1265. self.hpRules=self.hpRules.filter(item=>{return item&&item.url!=self.curSiteRule.url});
  1266. self.hpRules.unshift(self.curSiteRule);
  1267. if(self.hpRules.length>30){
  1268. self.hpRules.pop();
  1269. }
  1270. storage.setItem("hpRules", self.hpRules);
  1271. }
  1272. let css=self.curSiteRule.css;
  1273. if(css){
  1274. _GM_addStyle(css);
  1275. }
  1276. let code=self.curSiteRule.init;
  1277. if(code){
  1278. try{
  1279. Function('doc','win','"use strict";' + code)(null,null);
  1280. }catch(e){
  1281. debug(e);
  1282. }
  1283. }
  1284. self.getNextLink(document);
  1285. callback();
  1286. });
  1287. }
  1288.  
  1289. insertPage(doc, eles, url, callback, tried){
  1290. this.oldUrl=this.curUrl;
  1291. let oldTitle=this.pageDoc.title;
  1292. this.pageDoc=doc;
  1293. this.curUrl=url;
  1294. let nextLink=this.getNextLink(doc);
  1295. if(curPage==1 && !tried && !nextLink && this.curSiteRule.singleUrl && this.curSiteRule.pageElement && this.curSiteRule.pageElement!=allOfBody){
  1296. this.curSiteRule.action=1;
  1297. this.curUrl=location.href;
  1298. return false;
  1299. }
  1300. if(callback)callback(eles);
  1301. this.getInsert();
  1302. var self=this,newEles=[];
  1303. if(!eles || eles.length==0 || !self.insert || !self.insert.parentNode){
  1304. }else{
  1305. this.pageInit(doc, eles);
  1306. [].forEach.call(eles, ele=>{
  1307. let newEle=ele.cloneNode(true);
  1308. let oldCanvass=ele.querySelectorAll("canvas");
  1309. let newCanvass=newEle.querySelectorAll("canvas");
  1310. for(let i=0;i<oldCanvass.length;i++){
  1311. let oldCanvas=oldCanvass[i];
  1312. let newCanvas=newCanvass[i];
  1313. newCanvas.getContext('2d').drawImage(oldCanvas, 0, 0);
  1314. }
  1315. if(self.curSiteRule.insertPos==2){
  1316. self.insert.appendChild(newEle);
  1317. }else{
  1318. self.insert.parentNode.insertBefore(newEle, self.insert);
  1319. }
  1320. newEles.push(newEle);
  1321. });
  1322. }
  1323. this.pageAction(doc, newEles);
  1324. if(this.oldUrl!=location.href){
  1325. let isJs=/^(javascript|#)/.test(this.oldUrl.replace(location.href,""));
  1326. if(rulesData.enableHistory && !isJs){
  1327. _unsafeWindow.history.replaceState(undefined, oldTitle, this.oldUrl);
  1328. document.title=oldTitle;
  1329. }
  1330. }
  1331. return true;
  1332. }
  1333. }
  1334. var ruleParser = new RuleParser();
  1335.  
  1336. function initConfig(){
  1337. _GM_registerMenuCommand(i18n(forceState==1?"enable":"disableSite"), ()=>{
  1338. storage.setItem("forceState_"+location.host, (forceState==1?0:1));
  1339. location.reload();
  1340. });
  1341. _GM_registerMenuCommand(i18n("update"), ()=>{
  1342. updateRules(()=>{
  1343. alert(i18n("updateSucc"));
  1344. location.reload();
  1345. },(rule,err)=>{
  1346. alert("Update "+rule.url+" rules fail!");
  1347. });
  1348. alert(i18n("beginUpdate"));
  1349. });
  1350.  
  1351. var configCon,insertPos;
  1352. if(ruleImportUrlReg.test(location.href)){
  1353. document.addEventListener("click", e=>{
  1354. if(e.target.tagName=="PRE"){
  1355. let nameAttr=e.target.getAttribute("name");
  1356. if(nameAttr=="pagetual" || nameAttr=="user-content-pagetual"){
  1357. let rules=e.target.innerText.trim().split("\n");
  1358. let diff=false;
  1359. for(let c=0;c<rules.length;c++){
  1360. let urlArr=rules[c].split("|"),url,type=1;
  1361. if(urlArr.length==1){
  1362. url=urlArr[0].trim();
  1363. if(!/^http/.test(url)){
  1364. alert("Wrong url, check again!");
  1365. return;
  1366. }
  1367. }else if(urlArr.length==2){
  1368. type=urlArr[0].trim();
  1369. url=urlArr[1].trim();
  1370. if(!/^http/.test(url)){
  1371. alert("Wrong url, check again!");
  1372. return;
  1373. }
  1374. }else{
  1375. break;
  1376. }
  1377. let maxId=0,hasUrl=false;
  1378. if(!rulesData.urls){
  1379. rulesData.urls=[];
  1380. maxId=1;
  1381. }else{
  1382. rulesData.urls.forEach(u=>{
  1383. if(maxId<u.id){
  1384. maxId=u.id;
  1385. }
  1386. if(u.url==url){
  1387. hasUrl=true;
  1388. }
  1389. });
  1390. if(hasUrl)break;
  1391. }
  1392. diff=true;
  1393. if(!rulesData.sort)rulesData.sort=[1];
  1394. rulesData.urls.push({id:maxId+1,url:url,type:type});
  1395. rulesData.sort.unshift(maxId+1);
  1396. }
  1397. if(!diff)return;
  1398. storage.setItem("rulesData", rulesData);
  1399.  
  1400. if(rulesData.urls)ruleUrls=ruleUrls.concat(rulesData.urls);
  1401. if(rulesData.sort){
  1402. let urls=[];
  1403. rulesData.sort.forEach(id=>{
  1404. for(let s=0;s<ruleUrls.length;s++){
  1405. if(id==ruleUrls[s].id){
  1406. urls.push(ruleUrls[s]);
  1407. break;
  1408. }
  1409. }
  1410. });
  1411. ruleUrls=urls;
  1412. }
  1413. alert("OK");
  1414. }
  1415. }
  1416. });
  1417. }
  1418. if(location.href==configPage){
  1419. _GM_addStyle(`
  1420. p>span:nth-child(1),p>span:nth-child(2),p>span:nth-child(3){
  1421. cursor: pointer;
  1422. user-select: none;
  1423. }
  1424. p>span:nth-child(1):hover,p>span:nth-child(2):hover,p>span:nth-child(3):hover{
  1425. color:red;
  1426. }
  1427. .updateDate{
  1428. cursor: pointer;
  1429. user-select: none;
  1430. }
  1431. .updateDate:hover{
  1432. color:red;
  1433. }
  1434. `);
  1435. document.querySelector("[name='user-content-click2import']").innerText=i18n("click2ImportRule")
  1436. configCon=document.querySelector(".markdown-body");
  1437. insertPos=configCon.querySelector("hr");
  1438. }else return false;
  1439. class Rulebar {
  1440. init(ruleUrl){
  1441. this.ruleUrl=ruleUrl;
  1442. this.item=document.createElement("p");
  1443. this.item.title=ruleUrl.type==0?"AutoPagerize Rules":"Pagetual Rules";
  1444. this.item.dataset.id=this.ruleUrl.id;
  1445. let url=document.createElement("span");
  1446. url.innerHTML=ruleUrl.url;
  1447. let up=document.createElement("span");
  1448. up.innerHTML="↑ ";
  1449. up.title=i18n("sortTitle");
  1450. let down=document.createElement("span");
  1451. down.innerHTML="↓ ";
  1452. down.title=i18n("sortTitle");
  1453. let del=document.createElement("span");
  1454. del.innerHTML="× ";
  1455. up.onclick=e=>{
  1456. this.moveUp();
  1457. };
  1458. down.onclick=e=>{
  1459. this.moveDown();
  1460. };
  1461. del.onclick=e=>{
  1462. this.del();
  1463. };
  1464. this.item.appendChild(up);
  1465. this.item.appendChild(down);
  1466. this.item.appendChild(del);
  1467. this.item.appendChild(url);
  1468. configCon.insertBefore(this.item, insertPos);
  1469. }
  1470. saveSort(){
  1471. let sort=[];
  1472. [].forEach.call(this.item.parentNode.querySelectorAll("p[data-id]"), i=>{
  1473. sort.push(i.dataset.id);
  1474. });
  1475. rulesData.sort=sort;
  1476. storage.setItem("rulesData", rulesData);
  1477. }
  1478. moveUp(){
  1479. let preE=this.item.previousElementSibling;
  1480. if(preE.tagName=="P" && preE.children.length>1){
  1481. this.item.parentNode.insertBefore(this.item,preE);
  1482. this.saveSort();
  1483. }
  1484. }
  1485. moveDown(){
  1486. let nextE=this.item.nextElementSibling;
  1487. if(nextE.tagName=="P" && nextE.children.length>1){
  1488. this.item.parentNode.insertBefore(nextE,this.item);
  1489. this.saveSort();
  1490. }
  1491. }
  1492. del(){
  1493. if(this.ruleUrl.id<2){
  1494. alert(i18n("cantDel"));
  1495. }else if(window.confirm(i18n("confirmDel"))){
  1496. for(let u=0;u<rulesData.urls.length;u++){
  1497. if(this.ruleUrl.id==rulesData.urls[u].id){
  1498. rulesData.urls.splice(u,1);
  1499. break;
  1500. }
  1501. }
  1502. for(let u=0;u<rulesData.sort.length;u++){
  1503. if(this.ruleUrl.id==rulesData.sort[u]){
  1504. rulesData.sort.splice(u,1);
  1505. break;
  1506. }
  1507. }
  1508. storage.setItem("rulesData", rulesData);
  1509. ruleParser.rules=ruleParser.rules.filter(item=>{return item.from!=this.ruleUrl.id});
  1510. storage.setItem("rules", ruleParser.rules);
  1511. this.item.parentNode.removeChild(this.item);
  1512. //location.reload();
  1513. }
  1514. }
  1515. }
  1516. let updateP=document.createElement("p"),i=0;
  1517. let now=new Date().getTime(),inUpdate=false;
  1518.  
  1519.  
  1520. let pastDate=(new Date(updateDate)).toString(),passStr;
  1521. let passTime=(now-updateDate)/1000;
  1522. if(isNaN(passTime)){
  1523. passStr=i18n("firstUpdate");
  1524. }else if(passTime<60){
  1525. passStr=i18n("passSec", parseInt(passTime))+" ← "+i18n("click2update");
  1526. }else if(passTime<60*60){
  1527. passStr=i18n("passMin", parseInt(passTime/60))+" ← "+i18n("click2update");
  1528. }else if(passTime<60*60*24){
  1529. passStr=i18n("passHour", parseInt(passTime/3600))+" ← "+i18n("click2update");
  1530. }else{
  1531. passStr=i18n("passDay", parseInt(passTime/86400))+" ← "+i18n("click2update");
  1532. }
  1533.  
  1534.  
  1535. updateP.className="updateDate";
  1536. updateP.innerHTML=passStr;
  1537. updateP.title=i18n("update")+" - "+pastDate;
  1538. updateP.onclick=e=>{
  1539. updateRules(()=>{
  1540. alert(i18n("updateSucc"));
  1541. updateP.innerHTML=i18n("passSec", 0);
  1542. updateP.title=i18n("update");
  1543. },(rule,err)=>{
  1544. alert("Update "+rule.url+" rules fail!");
  1545. });
  1546. alert(i18n("beginUpdate"));
  1547. };
  1548. configCon.insertBefore(updateP, insertPos);
  1549. if(ruleUrls){
  1550. ruleUrls.forEach(ruleUrl=>{
  1551. var rulebar=new Rulebar();
  1552. rulebar.init(ruleUrl);
  1553. });
  1554. }
  1555. let customUrlsTitle=document.createElement("h2");
  1556. customUrlsTitle.innerHTML=i18n("customUrls");
  1557. configCon.insertBefore(customUrlsTitle, insertPos);
  1558. let customUrlsInput=document.createElement("textarea");
  1559. customUrlsInput.style.width="100%";
  1560. customUrlsInput.placeholder="0|http://wedata.net/databases/AutoPagerize/items_all.json";
  1561. configCon.insertBefore(customUrlsInput, insertPos);
  1562.  
  1563. let opacityTitle=document.createElement("h2");
  1564. opacityTitle.innerHTML=i18n("opacity");
  1565. let opacityInput=document.createElement("input");
  1566. opacityInput.value=rulesData.opacity*100;
  1567. opacityInput.type="number";
  1568. opacityInput.style.width="50px";
  1569. opacityInput.style.margin="0 0 0 10px";
  1570. opacityTitle.appendChild(opacityInput);
  1571. configCon.insertBefore(opacityTitle, insertPos);
  1572.  
  1573. function createCheckbox(innerText, val){
  1574. let title=document.createElement("h2");
  1575. title.innerHTML=innerText;
  1576. let input=document.createElement("input");
  1577. input.type="checkbox";
  1578. input.style.width="50px";
  1579. input.style.height="20px";
  1580. input.checked=val;
  1581. title.appendChild(input);
  1582. configCon.insertBefore(title, insertPos);
  1583. return input;
  1584. }
  1585.  
  1586. let hideBarInput=createCheckbox(i18n("hideBar"), rulesData.hideBar);
  1587. let dbClick2StopInput=createCheckbox(i18n("dbClick2Stop"), rulesData.dbClick2Stop);
  1588. let enableWhiteListInput=createCheckbox(i18n("autoRun"), rulesData.enableWhiteList!=true);
  1589. let enableDebugInput=createCheckbox(i18n("enableDebug"), rulesData.enableDebug!=false);
  1590. let enableHistoryInput=createCheckbox(i18n("enableHistory"), rulesData.enableHistory===true);
  1591. let initRunInput=createCheckbox(i18n("initRun"), rulesData.initRun!=false);
  1592. let preloadInput=createCheckbox(i18n("preload"), rulesData.preload);
  1593.  
  1594. let customRulesTitle=document.createElement("h2");
  1595. customRulesTitle.innerHTML=i18n("customRules")
  1596. configCon.insertBefore(customRulesTitle, insertPos);
  1597. let customRulesInput=document.createElement("textarea");
  1598. customRulesInput.style.width="100%";
  1599. customRulesInput.style.height="500px";
  1600. customRulesInput.placeholder=`[\n {\n "name":"yande",\n "action":"0",\n "url":"^https:\/\/yande\\.re\/",\n "pageElement":"ul#post-list-posts>li",\n "nextLink":"a.next_page",\n "css":".javascript-hide {display: inline-block !important;}"\n },\n {\n "name":"tieba",\n "action":"1",\n "url":"^https:\/\/tieba\\.baidu.com\/f\\?kw=",\n "pageElement":"ul#thread_list>li",\n "nextLink":".next.pagination-item "\n }\n]`;
  1601. customRulesInput.value=getFormatJSON(ruleParser.customRules);
  1602. configCon.insertBefore(customRulesInput, insertPos);
  1603. let saveBtn=document.createElement("button");
  1604. saveBtn.innerHTML=i18n("save");
  1605. saveBtn.style.width="100%";
  1606. configCon.insertBefore(saveBtn, insertPos);
  1607. saveBtn.onclick=e=>{
  1608. try{
  1609. storage.setItem("hpRules", []);
  1610. if(customRulesInput.value==""){
  1611. storage.setItem("customRules", "");
  1612. }else{
  1613. let customRules=JSON.parse(customRulesInput.value);
  1614. if(Array && Array.isArray && !Array.isArray(customRules)){
  1615. alert("Rules must be a Array!");
  1616. return;
  1617. }
  1618. debug(customRules);
  1619. storage.setItem("customRules", customRules);
  1620. }
  1621. }catch(e){
  1622. debug(e);
  1623. alert("JSON error, check again!");
  1624. return;
  1625. }
  1626. rulesData.opacity=opacityInput.value/100;
  1627. rulesData.hideBar=hideBarInput.checked;
  1628. rulesData.dbClick2Stop=dbClick2StopInput.checked;
  1629. rulesData.enableWhiteList=!enableWhiteListInput.checked;
  1630. rulesData.enableDebug=enableDebugInput.checked;
  1631. rulesData.enableHistory=enableHistoryInput.checked;
  1632. rulesData.initRun=initRunInput.checked;
  1633. rulesData.preload=preloadInput.checked;
  1634. storage.setItem("rulesData", rulesData);
  1635. let customUrls=customUrlsInput.value.trim();
  1636. if(customUrls){
  1637. customUrls=customUrls.split(/\n/);
  1638. for(let c=0;c<customUrls.length;c++){
  1639. let urlArr=customUrls[c].split("|"),url,type=1;
  1640. if(urlArr.length==1){
  1641. url=urlArr[0].trim();
  1642. if(!/^http/.test(url)){
  1643. alert("Wrong url, check again!");
  1644. return;
  1645. }
  1646. }else if(urlArr.length==2){
  1647. type=urlArr[0].trim();
  1648. url=urlArr[1].trim();
  1649. if(!/^http/.test(url)){
  1650. alert("Wrong url, check again!");
  1651. return;
  1652. }
  1653. }else{
  1654. break;
  1655. }
  1656. let maxId=0,hasUrl=false;
  1657. if(!rulesData.urls){
  1658. rulesData.urls=[];
  1659. maxId=1;
  1660. }else{
  1661. rulesData.urls.forEach(u=>{
  1662. if(maxId<u.id){
  1663. maxId=u.id;
  1664. }
  1665. if(u.url==url){
  1666. hasUrl=true;
  1667. }
  1668. });
  1669. if(hasUrl)break;
  1670. }
  1671. if(!rulesData.sort)rulesData.sort=[1];
  1672. rulesData.urls.push({id:maxId+1,url:url,type:type});
  1673. rulesData.sort.push(maxId+1);
  1674. storage.setItem("rulesData", rulesData);
  1675. }
  1676. }
  1677. alert("The settings are saved");
  1678. location.reload();
  1679. };
  1680. return true;
  1681. }
  1682.  
  1683. var inUpdate=false;
  1684. function updateRules(success,fail){
  1685. if(inUpdate)return;
  1686. inUpdate=true;
  1687. let ruleIndex=ruleUrls.length-1;
  1688. storage.setItem("hpRules", []);
  1689. function addNextRule(){
  1690. if(ruleIndex<0){
  1691. let now=new Date().getTime();
  1692. storage.setItem("ruleLastUpdate", now);
  1693. storage.setItem("rules", ruleParser.rules);
  1694. inUpdate=false;
  1695. success();
  1696. }else{
  1697. let rule=ruleUrls[ruleIndex--];
  1698. ruleParser.addRuleByUrl(rule.url, rule.type, rule.id, (json,err)=>{
  1699. if(!json){
  1700. fail(rule,err);
  1701. }
  1702. addNextRule();
  1703. })
  1704. }
  1705. }
  1706. addNextRule();
  1707. }
  1708.  
  1709. function objIsArr(obj) {
  1710. return obj &&
  1711. typeof obj === 'object' &&
  1712. typeof obj.length === 'number' &&
  1713. !(obj.propertyIsEnumerable('length'));
  1714. }
  1715.  
  1716. function isVisible(el, win) {
  1717. if(!el.offsetParent)return false;
  1718. var loopable = true,
  1719. visible = el.tagName && win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  1720. while(loopable && visible) {
  1721. el = el.parentNode;
  1722.  
  1723. if(el && el.tagName && el.tagName!="BODY") {
  1724. visible = win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  1725. }else {
  1726. loopable = false;
  1727. }
  1728. }
  1729. return visible;
  1730. }
  1731.  
  1732. function getFormatJSON(obj){
  1733. if(!objIsArr(obj))return "";
  1734. let ret="[\n";
  1735. let len=obj.length,i=0,isLast;
  1736. obj.forEach(item=>{
  1737. ret+=" {\n";
  1738. let iLen=Object.keys(item).length,j=0;
  1739. for(let key in item){
  1740. isLast=(++j)==iLen;
  1741. let value=item[key];
  1742. if(objIsArr(value)){
  1743. let vstr="[",v=0,vIsLast=false;
  1744. value.forEach(vi=>{
  1745. vIsLast=(++v)==value.length;
  1746. vstr+="\""+vi.replace(/\\/g,"\\\\")+"\""+(vIsLast?"":",");
  1747. });
  1748. vstr+="]";
  1749. ret+=" \""+key+"\":"+vstr+""+(isLast?"":",")+"\n";
  1750. }else{
  1751. if(typeof value=="string"){
  1752. value=value.replace(/\\/g,"\\\\").replace(/"/g,"\\\"");
  1753. value="\""+value+"\"";
  1754. }
  1755. ret+=" \""+key+"\":"+value+""+(isLast?"":",")+"\n";
  1756. }
  1757. }
  1758. isLast=(++i)==len;
  1759. ret+=" }"+(isLast?"":",")+"\n";
  1760. });
  1761. ret+="]";
  1762. return ret;
  1763. }
  1764.  
  1765. function initRules(callback) {
  1766. /*0 wedata格式,1 pagetual格式*/
  1767. ruleUrls=[
  1768. {
  1769. id:1,
  1770. url:'http://wedata.net/databases/AutoPagerize/items_all.json',
  1771. type:0,
  1772. }
  1773. ];var i=0,j=0;
  1774.  
  1775. ruleParser.initSavedRules(()=>{
  1776. storage.getItem("rulesData", data=>{
  1777. if(data){
  1778. rulesData=data;
  1779. if(data.urls)ruleUrls=ruleUrls.concat(data.urls);
  1780. if(data.sort){
  1781. let urls=[];
  1782. data.sort.forEach(id=>{
  1783. for(let s=0;s<ruleUrls.length;s++){
  1784. if(id==ruleUrls[s].id){
  1785. urls.push(ruleUrls[s]);
  1786. break;
  1787. }
  1788. }
  1789. });
  1790. ruleUrls=urls;
  1791. }
  1792. }
  1793. if(typeof(rulesData.opacity)=="undefined"){
  1794. rulesData.opacity=0.3;
  1795. }
  1796. if(typeof(rulesData.hideBar)=="undefined"){
  1797. rulesData.hideBar=false;
  1798. }
  1799. if(typeof(rulesData.dbClick2Stop)=="undefined"){
  1800. rulesData.dbClick2Stop=true;
  1801. }
  1802. if(typeof(rulesData.enableWhiteList)=="undefined"){
  1803. rulesData.enableWhiteList=false;
  1804. }
  1805. if(typeof(rulesData.enableHistory)=="undefined"){
  1806. rulesData.enableHistory=false;
  1807. }
  1808. if(typeof(rulesData.enableDebug)=="undefined"){
  1809. rulesData.enableDebug=true;
  1810. }
  1811. if(typeof(rulesData.initRun)=="undefined"){
  1812. rulesData.initRun=true;
  1813. }
  1814. if(typeof(rulesData.preload)=="undefined"){
  1815. rulesData.preload=false;
  1816. }
  1817. enableDebug=rulesData.enableDebug;
  1818. storage.getItem("forceState_"+location.host, v=>{
  1819. storage.getItem("ruleLastUpdate", date=>{
  1820. if(typeof(v)=="undefined"){
  1821. v=(rulesData.enableWhiteList?1:0);
  1822. }
  1823. forceState=v;
  1824. updateDate=date;
  1825. if(initConfig())return;
  1826. if(forceState==1)return;
  1827. let now=new Date().getTime();
  1828. if(!date || now-date>2*24*60*60*1000){
  1829. //storage.setItem("ruleLastUpdate", now);
  1830. updateRules(()=>{
  1831. //callback();
  1832. },(rule,err)=>{});
  1833. }
  1834. callback();
  1835. });
  1836. });
  1837. });
  1838. });
  1839. }
  1840.  
  1841. function requestDoc(url, callback){
  1842. _GM_xmlhttpRequest({
  1843. url: url,
  1844. method: 'GET',
  1845. overrideMimeType: 'text/html;charset='+document.charset,
  1846. headers: {
  1847. 'Referer': location.href
  1848. },
  1849. timeout: 5000,
  1850. onload: function(res) {
  1851. var doc=null;
  1852. try {
  1853. doc=document.implementation.createHTMLDocument('');
  1854. doc.documentElement.innerHTML=res.response;
  1855. }
  1856. catch (e) {
  1857. debug('parse error'+e.toString());
  1858. }
  1859. let pageElement=ruleParser.getPageElement(doc);
  1860. //只有1的話怕不是圖片哦
  1861. if(pageElement && (pageElement.length>1 || (pageElement.length==1 && pageElement[0].tagName!="IMG") )){
  1862. let result=ruleParser.insertPage(doc, pageElement, url, callback, false);
  1863. if(!result){
  1864. ruleParser.curSiteRule.action=1;
  1865. requestFromIframe(url, (doc, eles)=>{
  1866. loadPageOver();
  1867. if(eles){
  1868. ruleParser.insertPage(doc, eles, url, callback, true);
  1869. }
  1870. });
  1871. }
  1872. }else if(ruleParser.curSiteRule.singleUrl){
  1873. ruleParser.curSiteRule.action=1;
  1874. requestFromIframe(url, (doc, eles)=>{
  1875. loadPageOver();
  1876. if(eles){
  1877. ruleParser.insertPage(doc, eles, url, callback, true);
  1878. }
  1879. });
  1880. }else{
  1881. isPause=true;
  1882. callback(false);
  1883. }
  1884. },
  1885. onerror: function(e){
  1886. debug(e);
  1887. callback(false);
  1888. },
  1889. ontimeout: function(e){
  1890. debug(e);
  1891. callback(false);
  1892. }
  1893. });
  1894. }
  1895.  
  1896. var failFromIframe=0;
  1897. function requestFromIframe(url, callback){
  1898. let orgPage,curPage;
  1899. let iframe = document.createElement('iframe');
  1900. iframe.name = 'pagetual-iframe';
  1901. iframe.width = '100%';
  1902. iframe.height = '0';
  1903. iframe.frameBorder = '0';
  1904. if(ruleParser.curSiteRule.sandbox!=false){
  1905. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1906. }
  1907. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1908. iframe.addEventListener("load", e=>{
  1909. let waitTime=500,checkEval;
  1910. if(ruleParser.curSiteRule.wait){
  1911. if(isNaN(ruleParser.curSiteRule.wait)){
  1912. try{
  1913. checkEval=Function("doc",'"use strict";' + ruleParser.curSiteRule.wait);
  1914. }catch(e){
  1915. debug(e);
  1916. }
  1917. }else{
  1918. waitTime=ruleParser.curSiteRule.wait;
  1919. }
  1920. }
  1921. setTimeout(()=>{
  1922. let tryTimes=0;
  1923. function checkIframe(){
  1924. try{
  1925. let doc=iframe.contentDocument || iframe.contentWindow.document;
  1926. let eles=ruleParser.getPageElement(doc, iframe.contentWindow);
  1927. if(eles && eles.length>0 && (!checkEval || checkEval(doc))){
  1928. callback(doc, eles);
  1929. }else if(tryTimes++ < 10){
  1930. setTimeout(()=>{
  1931. checkIframe();
  1932. },waitTime);
  1933. return;
  1934. }else{
  1935. if(failFromIframe++ > 2){
  1936. failFromIframe=0;
  1937. debug("Stop as failFromIframe");
  1938. isPause=true;
  1939. callback(false, false);
  1940. }else{
  1941. callback(false, false);
  1942. }
  1943. }
  1944. }catch(e){
  1945. debug("Stop as cors");
  1946. //isPause=true;
  1947. ruleParser.curSiteRule.pageElement=allOfBody;
  1948. ruleParser.curSiteRule.action=0;
  1949. ruleParser.getInsert(true);
  1950. ruleParser.nextLinkHref=url;
  1951. callback(false, false);
  1952. }
  1953. document.body.removeChild(iframe);
  1954. }
  1955. checkIframe();
  1956. },waitTime);
  1957. });
  1958. iframe.src=url;
  1959. document.body.appendChild(iframe);
  1960. }
  1961.  
  1962. function initPage(){
  1963. ruleParser.initPage(()=>{
  1964. if(ruleParser.nextLinkHref){
  1965. initView();
  1966. let isJs=/^(javascript|#)/.test(ruleParser.nextLinkHref.replace(location.href,""));
  1967. if(!isJs){
  1968. _GM_registerMenuCommand(i18n(forceState==2?"cancelForceIframe":"forceIframe"), ()=>{
  1969. storage.setItem("forceState_"+location.host, (forceState==2?"":2));
  1970. location.reload();
  1971. });
  1972. }
  1973. _GM_registerMenuCommand(i18n("loadNow"), ()=>{
  1974. let loadNum=window.prompt(i18n("loadConfirm"), "1");
  1975. if(loadNum==="" || loadNum===null)return;
  1976. autoLoadNum=Math.abs(parseInt(loadNum));
  1977. nextPage();
  1978. });
  1979. }
  1980. initListener();
  1981. if(rulesData.initRun && ruleParser.curSiteRule.initRun!=0)nextPage();
  1982. });
  1983. }
  1984.  
  1985. function initView(){
  1986. _GM_addStyle(`
  1987. .pagetual_pageBar.stop {
  1988. -webkit-filter: invert(100%);
  1989. filter: invert(100%);
  1990. opacity: 1!important;
  1991. }
  1992. .pagetual_pageBar.hide {
  1993. display: none!important;
  1994. }
  1995. .pagetual_pageBar:hover {
  1996. opacity: 1!important;
  1997. }
  1998. .pagetual_pageBar span {
  1999. vertical-align: super;
  2000. }
  2001.  
  2002. .pagetual_pageBar span>svg:hover {
  2003. animation: touhouAni 1s infinite;
  2004. }
  2005. .pagetual_pageBar .pagetual_pageNum{
  2006. color: #55555f;
  2007. }
  2008. .pagetual_pageBar .pagetual_pageNum:hover{
  2009. color: #ff6464;
  2010. }
  2011.  
  2012. @keyframes touhouAni{
  2013. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  2014. to {transform: rotate(360deg);}
  2015. }
  2016. @-webkit-keyframes touhouAni{
  2017. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  2018. to {transform: rotate(360deg);}
  2019. }
  2020. `);
  2021. pageBarStyle=`opacity:${rulesData.opacity};display:${rulesData.opacity==0?"none":"block"};padding:0;box-shadow: 0px 0px 10px 0px #000000aa;border-radius: 20px;background-color: rgb(240 240 240 / 80%);visibility: visible; position: initial; width: auto; height: 30px; float: none; clear: both; margin: 5px auto; text-align: center;`;
  2022. }
  2023. var loadingDiv=document.createElement("div");
  2024. loadingDiv.className="pagetual_loading";
  2025. loadingDiv.style.cssText="cy: initial;d: initial;dominant-baseline: initial;empty-cells: initial;fill: initial;fill-opacity: initial;fill-rule: initial;filter: initial;flex: initial;flex-flow: initial;float: initial;flood-color: initial;flood-opacity: initial;grid: initial;grid-area: initial;height: initial;hyphens: initial;image-orientation: initial;image-rendering: initial;inline-size: initial;inset-block: initial;inset-inline: initial;isolation: initial;letter-spacing: initial;lighting-color: initial;line-break: initial;list-style: initial;margin-block: initial;margin: 0px auto;margin-inline: initial;marker: initial;mask: initial;mask-type: initial;max-block-size: initial;max-height: initial;max-inline-size: initial;max-width: initial;min-block-size: initial;min-height: initial;min-inline-size: initial;min-width: initial;mix-blend-mode: initial;object-fit: initial;object-position: initial;offset: initial;opacity: initial;order: initial;origin-trial-test-property: initial;orphans: initial;outline: initial;outline-offset: initial;overflow-anchor: initial;overflow-clip-margin: initial;overflow-wrap: initial;overflow: initial;overscroll-behavior-block: initial;overscroll-behavior-inline: initial;overscroll-behavior: initial;padding-block: initial;padding: initial;padding-inline: initial;page: initial;page-orientation: initial;paint-order: initial;perspective: initial;perspective-origin: initial;pointer-events: initial;position: initial;quotes: initial;r: initial;resize: initial;ruby-position: initial;rx: initial;ry: initial;scroll-behavior: initial;scroll-margin-block: initial;scroll-margin: initial;scroll-margin-inline: initial;scroll-padding-block: initial;scroll-padding: initial;scroll-padding-inline: initial;scroll-snap-align: initial;scroll-snap-stop: initial;scroll-snap-type: initial;scrollbar-gutter: initial;shape-image-threshold: initial;shape-margin: initial;shape-outside: initial;shape-rendering: initial;size: initial;speak: initial;stop-color: initial;stop-opacity: initial;stroke: initial;stroke-dasharray: initial;stroke-dashoffset: initial;stroke-linecap: initial;stroke-linejoin: initial;stroke-miterlimit: initial;stroke-opacity: initial;stroke-width: initial;tab-size: initial;table-layout: initial;text-align: initial;text-align-last: initial;text-anchor: initial;text-combine-upright: initial;text-decoration: initial;text-decoration-skip-ink: initial;text-indent: initial;text-overflow: initial;text-shadow: initial;text-size-adjust: initial;text-transform: initial;text-underline-offset: initial;text-underline-position: initial;touch-action: initial;transform: initial;transform-box: initial;transform-origin: initial;transform-style: initial;transition: initial;user-select: initial;vector-effect: initial;vertical-align: initial;visibility: initial;border-spacing: initial;-webkit-border-image: initial;-webkit-box-align: initial;-webkit-box-decoration-break: initial;-webkit-box-direction: initial;-webkit-box-flex: initial;-webkit-box-ordinal-group: initial;-webkit-box-orient: initial;-webkit-box-pack: initial;-webkit-box-reflect: initial;-webkit-highlight: initial;-webkit-hyphenate-character: initial;-webkit-line-break: initial;-webkit-line-clamp: initial;-webkit-mask-box-image: initial;-webkit-mask: initial;-webkit-mask-composite: initial;-webkit-perspective-origin-x: initial;-webkit-perspective-origin-y: initial;-webkit-print-color-adjust: initial;-webkit-rtl-ordering: initial;-webkit-ruby-position: initial;-webkit-tap-highlight-color: initial;-webkit-text-combine: initial;-webkit-text-decorations-in-effect: initial;-webkit-text-emphasis: initial;-webkit-text-emphasis-position: initial;-webkit-text-fill-color: initial;-webkit-text-security: initial;-webkit-text-stroke: initial;-webkit-transform-origin-x: initial;-webkit-transform-origin-y: initial;-webkit-transform-origin-z: initial;-webkit-user-drag: initial;-webkit-user-modify: initial;white-space: initial;widows: initial;width: initial;will-change: initial;word-break: initial;word-spacing: initial;x: initial;y: initial;z-index: 2147483647;";
  2026. loadingDiv.innerHTML=`<p style=" display: block; position: initial; margin: auto auto 5px auto; shape-rendering: auto; vertical-align: middle; visibility: visible; width: initial; height: initial; text-align: center; color: #6e6e6e; ">${i18n("loadingText")}</p><svg width="120" height="30" viewBox="0 0 120 30" fill="#000000A0" style="display: block;position: initial;margin: auto;shape-rendering: auto;vertical-align: middle;visibility: visible;width: initial;height: initial;"><circle cx="15" cy="15" r="15"><animate attributeName="r" from="15" to="15" begin="0s" dur="0.8s" values="15;9;15" calcMode="linear" repeatCount="indefinite"></animate><animate attributeName="fill-opacity" from="1" to="1" begin="0s" dur="0.8s" values="1;.5;1" calcMode="linear" repeatCount="indefinite"></animate></circle><circle cx="60" cy="15" r="9" fill-opacity="0.3"><animate attributeName="r" from="9" to="9" begin="0s" dur="0.8s" values="9;15;9" calcMode="linear" repeatCount="indefinite"></animate><animate attributeName="fill-opacity" from="0.5" to="0.5" begin="0s" dur="0.8s" values=".5;1;.5" calcMode="linear" repeatCount="indefinite"></animate></circle><circle cx="105" cy="15" r="15"><animate attributeName="r" from="15" to="15" begin="0s" dur="0.8s" values="15;9;15" calcMode="linear" repeatCount="indefinite"></animate><animate attributeName="fill-opacity" from="1" to="1" begin="0s" dur="0.8s" values="1;.5;1" calcMode="linear" repeatCount="indefinite"></animate></circle></svg>`;
  2027.  
  2028. var upSvg=`<svg width="30" height="30" style="position:absolute;cursor: pointer;margin: 0 -45px;width: 30px;height: 30px;vertical-align: middle;fill: currentColor;overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6364"><path d="M296 440c-44.1 0-80 35.9-80 80s35.9 80 80 80 80-35.9 80-80-35.9-80-80-80z" fill="#604b4a" p-id="6365"></path><path d="M960 512c0-247-201-448-448-448S64 265 64 512c0 1.8 0.1 3.5 0.1 5.3 0 0.9-0.1 1.8-0.1 2.7h0.2C68.5 763.3 267.7 960 512 960c236.2 0 430.1-183.7 446.7-415.7 0.1-0.8 0.1-1.6 0.2-2.3 0.4-4.6 0.5-9.3 0.7-13.9 0.1-2.7 0.4-5.3 0.4-8h-0.2c0-2.8 0.2-5.4 0.2-8.1z m-152 8c0 44.1-35.9 80-80 80s-80-35.9-80-80 35.9-80 80-80 80 35.9 80 80zM512 928C284.4 928 99 744.3 96.1 517.3 97.6 408.3 186.6 320 296 320c110.3 0 200 89.7 200 200 0 127.9 104.1 232 232 232 62.9 0 119.9-25.2 161.7-66-66 142.7-210.4 242-377.7 242z" fill="#604b4a" p-id="6366"></path></svg>`;
  2029. var downSvg=`<svg width="30" height="30" style="position:absolute;cursor: pointer;margin: 0 15px;width: 30px;height: 30px;vertical-align: middle;fill: currentColor;overflow: hidden;transform: rotate(180deg);" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6364"><path d="M296 440c-44.1 0-80 35.9-80 80s35.9 80 80 80 80-35.9 80-80-35.9-80-80-80z" fill="#604b4a" p-id="6365"></path><path d="M960 512c0-247-201-448-448-448S64 265 64 512c0 1.8 0.1 3.5 0.1 5.3 0 0.9-0.1 1.8-0.1 2.7h0.2C68.5 763.3 267.7 960 512 960c236.2 0 430.1-183.7 446.7-415.7 0.1-0.8 0.1-1.6 0.2-2.3 0.4-4.6 0.5-9.3 0.7-13.9 0.1-2.7 0.4-5.3 0.4-8h-0.2c0-2.8 0.2-5.4 0.2-8.1z m-152 8c0 44.1-35.9 80-80 80s-80-35.9-80-80 35.9-80 80-80 80 35.9 80 80zM512 928C284.4 928 99 744.3 96.1 517.3 97.6 408.3 186.6 320 296 320c110.3 0 200 89.7 200 200 0 127.9 104.1 232 232 232 62.9 0 119.9-25.2 161.7-66-66 142.7-210.4 242-377.7 242z" fill="#604b4a" p-id="6366"></path></svg>`;
  2030. var pageBarStyle;
  2031. var initStyle=`display: contents;right: unset;left: unset;top: unset;bottom: unset;inset: unset;clear: both;cy: initial;d: initial;dominant-baseline: initial;empty-cells: initial;fill: initial;fill-opacity: initial;fill-rule: initial;filter: initial;flex: initial;flex-flow: initial;float: initial;flood-color: initial;flood-opacity: initial;grid: initial;grid-area: initial;height: initial;hyphens: initial;image-orientation: initial;image-rendering: initial;inline-size: initial;inset-block: initial;inset-inline: initial;isolation: initial;letter-spacing: initial;lighting-color: initial;line-break: initial;list-style: initial;margin-block: initial;margin: 0px auto;margin-inline: initial;marker: initial;mask: initial;mask-type: initial;max-block-size: initial;max-height: initial;max-inline-size: initial;max-width: initial;min-block-size: initial;min-height: initial;min-inline-size: initial;min-width: initial;mix-blend-mode: initial;object-fit: initial;object-position: initial;offset: initial;opacity: initial;order: initial;orphans: initial;outline: initial;outline-offset: initial;overflow-anchor: initial;overflow-clip-margin: initial;overflow-wrap: initial;overflow: initial;overscroll-behavior-block: initial;overscroll-behavior-inline: initial;overscroll-behavior: initial;padding-block: initial;padding: initial;padding-inline: initial;page: initial;page-orientation: initial;paint-order: initial;perspective: initial;perspective-origin: initial;pointer-events: initial;position: relative;quotes: initial;r: initial;resize: initial;ruby-position: initial;rx: initial;ry: initial;scroll-behavior: initial;scroll-margin-block: initial;scroll-margin: initial;scroll-margin-inline: initial;scroll-padding-block: initial;scroll-padding: initial;scroll-padding-inline: initial;scroll-snap-align: initial;scroll-snap-stop: initial;scroll-snap-type: initial;scrollbar-gutter: initial;shape-image-threshold: initial;shape-margin: initial;shape-outside: initial;shape-rendering: initial;size: initial;speak: initial;stop-color: initial;stop-opacity: initial;stroke: initial;stroke-dasharray: initial;stroke-dashoffset: initial;stroke-linecap: initial;stroke-linejoin: initial;stroke-miterlimit: initial;stroke-opacity: initial;stroke-width: initial;tab-size: initial;table-layout: initial;text-align: initial;text-align-last: initial;text-anchor: initial;text-combine-upright: initial;text-decoration: initial;text-decoration-skip-ink: initial;text-indent: initial;text-overflow: initial;text-shadow: initial;text-size-adjust: initial;text-transform: initial;text-underline-offset: initial;text-underline-position: initial;touch-action: initial;transform: initial;transform-box: initial;transform-origin: initial;transform-style: initial;transition: initial;user-select: initial;vector-effect: initial;vertical-align: initial;visibility: initial;border-spacing: initial;-webkit-border-image: initial;-webkit-box-align: initial;-webkit-box-decoration-break: initial;-webkit-box-direction: initial;-webkit-box-flex: initial;-webkit-box-ordinal-group: initial;-webkit-box-orient: initial;-webkit-box-pack: initial;-webkit-box-reflect: initial;-webkit-highlight: initial;-webkit-hyphenate-character: initial;-webkit-line-break: initial;-webkit-line-clamp: initial;-webkit-mask-box-image: initial;-webkit-mask: initial;-webkit-mask-composite: initial;-webkit-perspective-origin-x: initial;-webkit-perspective-origin-y: initial;-webkit-print-color-adjust: initial;-webkit-rtl-ordering: initial;-webkit-ruby-position: initial;-webkit-tap-highlight-color: initial;-webkit-text-combine: initial;-webkit-text-decorations-in-effect: initial;-webkit-text-emphasis: initial;-webkit-text-emphasis-position: initial;-webkit-text-fill-color: initial;-webkit-text-security: initial;-webkit-text-stroke: initial;-webkit-transform-origin-x: initial;-webkit-transform-origin-y: initial;-webkit-transform-origin-z: initial;-webkit-user-drag: initial;-webkit-user-modify: initial;white-space: initial;widows: initial;width: initial;will-change: initial;word-break: initial;word-spacing: initial;x: initial;y: initial;`;
  2032. var pageTextStyle=`line-height: 30px;text-decoration: none;user-select: none;visibility: visible;position: initial;width: auto;height: auto;float: none;clear: both;margin: 0px auto;text-align: center;display: inline;font-weight: bold;font-style: normal;font-size: 16px;letter-spacing: initial;vertical-align: super;color: rgb(85, 85, 95);`;
  2033.  
  2034. var isPause=false,isLoading=false,curPage=1,forceState=0,bottomGap=1000,autoLoadNum=-1;
  2035.  
  2036. function changeStop(stop, hide){
  2037. isPause=stop;
  2038. [].forEach.call(document.querySelectorAll(".pagetual_pageBar"), bar=>{
  2039. if(isPause){
  2040. bar.classList.add("stop");
  2041. if(hide)bar.classList.add("hide");
  2042. }else{
  2043. bar.classList.remove("stop");
  2044. if(hide)bar.classList.remove("hide");
  2045. }
  2046. });
  2047. }
  2048.  
  2049. function isInViewPort(element) {
  2050. if(!element.parentNode)return false;
  2051. if(_unsafeWindow.getComputedStyle(element).display=="none")return false;
  2052. const viewWidth = window.innerWidth || document.documentElement.clientWidth;
  2053. const viewHeight = window.innerHeight || document.documentElement.clientHeight;
  2054. const {
  2055. top,
  2056. right,
  2057. bottom,
  2058. left,
  2059. } = element.getBoundingClientRect();
  2060.  
  2061. return (
  2062. top >= 0 &&
  2063. left >= 0 &&
  2064. right <= viewWidth &&
  2065. bottom <= viewHeight
  2066. );
  2067. }
  2068.  
  2069. var urlChanged=false;
  2070. var _wr = function(type) {
  2071. var orig = history[type];
  2072. return function() {
  2073. var rv = orig.apply(this, arguments);
  2074. var e = new Event(type);
  2075. e.arguments = arguments;
  2076. window.dispatchEvent(e);
  2077. return rv;
  2078. };
  2079. };
  2080. history.pushState = _wr('pushState');
  2081. window.addEventListener('pushState', function(e) {
  2082. urlChanged=true;
  2083. isPause=true;
  2084. setTimeout(()=>{
  2085. if(location.href==configPage){
  2086. location.reload();
  2087. }
  2088. },1);
  2089. });
  2090.  
  2091. function initListener(){
  2092. let loadmoreBtn,loading=true;
  2093. setTimeout(()=>{
  2094. loadmoreBtn=getLoadMore(document);
  2095. if(loadmoreBtn && isVisible(loadmoreBtn, _unsafeWindow)){
  2096. loading=false;
  2097. }
  2098. },500);
  2099. let checkScrollReach=()=>{
  2100. let scrolly=window.scrollY;
  2101. let windowHeight=window.innerHeight || document.documentElement.clientHeight;
  2102. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  2103. if(scrollH-scrolly-windowHeight<bottomGap){
  2104. nextPage();
  2105. }
  2106. };
  2107. document.addEventListener('scroll', e=>{
  2108. if(urlChanged){
  2109. ruleParser.initPage(()=>{
  2110. if(ruleParser.nextLinkHref)initView();
  2111. });
  2112. urlChanged=false;
  2113. isPause=false;
  2114. }
  2115. if(isPause)return;
  2116. if(!loading){
  2117. loading=true;
  2118. setTimeout(()=>{loading=false},200);
  2119. if(!loadmoreBtn || !loadmoreBtn.parentNode){
  2120. loadmoreBtn=getLoadMore(document);
  2121. }
  2122. if(loadmoreBtn){
  2123. if(isInViewPort(loadmoreBtn)){
  2124. emuClick(loadmoreBtn);
  2125. }
  2126. }
  2127. }
  2128. setTimeout(()=>{
  2129. if(!isLoading){
  2130. checkScrollReach();
  2131. }
  2132. },100);
  2133. }, true);
  2134. document.addEventListener('dblclick', e=>{
  2135. if(rulesData.dbClick2Stop){
  2136. setTimeout(()=>{
  2137. changeStop(!isPause, rulesData.hideBar);
  2138. if(!isPause){
  2139. checkScrollReach();
  2140. }
  2141. },200);
  2142. }
  2143. });
  2144. }
  2145.  
  2146. function getLoadMore(doc){
  2147. if(ruleParser.curSiteRule.loadMore==="")return null;
  2148. let btnSel=ruleParser.curSiteRule.loadMore||".LoadMore,.load-more";
  2149. let loadmoreBtn=doc.querySelector(btnSel);
  2150. if(!loadmoreBtn){
  2151. let buttons=doc.querySelectorAll("input,button,a,div[onclick]"),loadmoreReg=/^\s*(加载更多|加載更多|load\s*more|もっと読み込む)\s*$/i;
  2152. for(let i=0;i<buttons.length;i++){
  2153. let button=buttons[i];
  2154. if(button && loadmoreReg.test(button.innerText)){
  2155. loadmoreBtn=button;
  2156. break;
  2157. }
  2158. }
  2159. }
  2160. return loadmoreBtn;
  2161. }
  2162.  
  2163. var hasPageNum=true;
  2164. function createPageBar(url){
  2165. let insert=ruleParser.getInsert();
  2166. if(!insert || !insert.parentNode)return;
  2167. curPage++;
  2168. if(rulesData.opacity==0)return;
  2169. let example=ruleParser.curSiteRule.insertPos==2?insert.children[0]:(insert.previousElementSibling||insert);
  2170. if(!example || !example.parentNode)example=insert;
  2171. let inTable=example.parentNode.tagName=="TABLE" ||
  2172. example.tagName=="TR" ||
  2173. example.tagName=="TBODY" ||
  2174. (example.previousElementSibling && example.previousElementSibling.tagName=="TR") ||
  2175. (example.previousElementSibling && example.previousElementSibling.tagName=="TBODY");
  2176. let inLi=example.tagName=="LI" || (example.previousElementSibling && example.previousElementSibling.tagName=="LI");
  2177. let pageBar=document.createElement(inTable?"tr":(inLi?"li":"div"));
  2178. let upSpan=document.createElement("span");
  2179. let downSpan=document.createElement("span");
  2180. let pageText=document.createElement("a");
  2181. let pageNum;
  2182. pageBar.className="pagetual_pageBar";
  2183. pageBar.id="pagetual_pageBar";
  2184. if(isPause){
  2185. pageBar.classList.add("stop");
  2186. }
  2187. pageBar.style.cssText=pageBarStyle;
  2188. pageBar.title=i18n(isPause?"enable":"disable");
  2189. upSpan.innerHTML=upSvg;
  2190. upSpan.title=i18n("toTop");
  2191. downSpan.innerHTML=downSvg;
  2192. downSpan.title=i18n("toBottom");
  2193. upSpan.style.cssText=initStyle;
  2194. downSpan.style.cssText=initStyle;
  2195. pageText.href=url;
  2196. pageText.style.cssText=pageTextStyle;
  2197. pageText.title=i18n("current");
  2198. pageBar.appendChild(upSpan);
  2199. pageBar.appendChild(pageText);
  2200. if(ruleParser.curSiteRule.pageNum || (hasPageNum && /[&\/\?](p=|page[=\/])\d+/.test(url))){
  2201. pageText.innerHTML="Page ";
  2202. pageNum=document.createElement("span");
  2203. pageNum.innerText=curPage;
  2204. pageNum.className="pagetual_pageNum";
  2205. pageNum.title=i18n("inputPageNum");
  2206. pageNum.style.cssText=pageTextStyle;
  2207. pageNum.style.cursor="pointer";
  2208. pageNum.style.color="";
  2209. pageNum.addEventListener("click", e=>{
  2210. let pageInput=prompt(i18n("inputPageNum"), "1");
  2211. if(pageInput){
  2212. let pageLink=ruleParser.getLinkByPage(url, pageInput);
  2213. if(pageLink){
  2214. _GM_openInTab(pageLink,{active:true});
  2215. }
  2216. }
  2217. e.preventDefault();
  2218. e.stopPropagation();
  2219. });
  2220. pageBar.appendChild(pageNum);
  2221. }else{
  2222. pageText.innerHTML="Page "+curPage;
  2223. hasPageNum=false;
  2224. }
  2225. pageBar.appendChild(downSpan);
  2226. let parentStyle=_unsafeWindow.getComputedStyle(example.parentNode);
  2227. pageBar.style.width=parseInt(parentStyle.width)-10+"px";
  2228. if(parentStyle.display=="grid" || parentStyle.display=="inline-grid"){
  2229. pageBar.style.gridColumnStart=1;
  2230. pageBar.style.gridColumnEnd=1+parseInt(example.parentNode.offsetWidth/example.offsetWidth);
  2231. }
  2232. if(inTable){
  2233. example=(example.tagName=="TR" || example.tagName=="TBODY")?example:example.previousElementSibling;
  2234. if(example.previousElementSibling)example=example.previousElementSibling;
  2235. let tdNum=0;
  2236. [].forEach.call(example.querySelectorAll("td,th"), td=>{
  2237. tdNum+=td.colSpan||1;
  2238. });
  2239. pageBar.style.display="table-row";
  2240. pageBar.style.backgroundColor="unset";
  2241. let td=document.createElement("td");
  2242. td.style.backgroundColor="rgb(240 240 240 / 80%)";
  2243. td.style.borderRadius="20px";
  2244. td.colSpan=tdNum||1;
  2245. td.style.padding="0 0";
  2246. td.style.textAlign="center";
  2247. td.appendChild(upSpan);
  2248. td.appendChild(pageText);
  2249. if(pageNum)td.appendChild(pageNum);
  2250. td.appendChild(downSpan);
  2251. pageBar.appendChild(td);
  2252. }else if(inLi){
  2253. example=example.tagName=="LI"?example:example.previousElementSibling;
  2254. pageBar.style.display="table-row";
  2255. pageBar.style.backgroundColor="unset";
  2256. let td=document.createElement("td");
  2257. td.style.backgroundColor="rgb(240 240 240 / 80%)";
  2258. td.style.borderRadius="20px";
  2259. td.colSpan=example.children.length;
  2260. td.style.padding="0 0";
  2261. td.style.textAlign="center";
  2262. td.style.minWidth="150px";
  2263. td.appendChild(upSpan);
  2264. td.appendChild(pageText);
  2265. td.style.width=pageBar.style.width;
  2266. if(pageNum)td.appendChild(pageNum);
  2267. td.appendChild(downSpan);
  2268. pageBar.appendChild(td);
  2269. }
  2270.  
  2271. upSpan.addEventListener("click", e=>{
  2272. document.body.scrollTop=0;
  2273. document.documentElement.scrollTop=0;
  2274. e.preventDefault();
  2275. e.stopPropagation();
  2276. });
  2277. downSpan.addEventListener("click", e=>{
  2278. changeStop(true);
  2279. pageBar.title=i18n(isPause?"enable":"disable");
  2280. document.body.scrollTop=9999999;
  2281. document.documentElement.scrollTop=9999999;
  2282. e.preventDefault();
  2283. e.stopPropagation();
  2284. });
  2285. pageBar.addEventListener("click", e=>{
  2286. changeStop(!isPause);
  2287. pageBar.title=i18n(isPause?"enable":"disable");
  2288. });
  2289. pageText.addEventListener("click", e=>{
  2290. e.stopPropagation();
  2291. });
  2292. if(ruleParser.curSiteRule.insertPos==2){
  2293. insert.appendChild(pageBar);
  2294. }else{
  2295. insert.parentNode.insertBefore(pageBar, insert);
  2296. }
  2297. if(ruleParser.curSiteRule.pageBar){
  2298. try{
  2299. Function("pageBar",'"use strict";' + ruleParser.curSiteRule.pageBar)(pageBar);
  2300. }catch(e){
  2301. debug(e);
  2302. }
  2303. }
  2304.  
  2305. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  2306. let posEle=pageBar.nextElementSibling||pageBar;
  2307. while(posEle && !posEle.offsetParent){
  2308. posEle=posEle.previousElementSibling||posEle.parentNode;
  2309. }
  2310. if(posEle){
  2311. let actualTop = posEle.offsetTop;
  2312. let current = posEle.parentNode.offsetParent;
  2313. while (current !== null){
  2314. actualTop += current.offsetTop;
  2315. current = current.offsetParent;
  2316. }
  2317. bottomGap=scrollH-actualTop+(window.innerHeight||document.documentElement.clientHeight)*(ruleParser.curSiteRule.rate||1);
  2318. if(bottomGap<100)bottomGap=100;
  2319. }else{
  2320. bottomGap=1000;
  2321. }
  2322. return pageBar;
  2323. }
  2324.  
  2325. function emuClick(btn){
  2326. if(!PointerEvent)return btn.click();
  2327. let eventParam={
  2328. isTrusted: true,
  2329. altKey: false,
  2330. azimuthAngle: 0,
  2331. bubbles: true,
  2332. button: 0,
  2333. buttons: 0,
  2334. clientX: 1,
  2335. clientY: 1,
  2336. cancelBubble: false,
  2337. cancelable: true,
  2338. composed: true,
  2339. ctrlKey: false,
  2340. defaultPrevented: false,
  2341. detail: 1,
  2342. eventPhase: 2,
  2343. fromElement: null,
  2344. height: 1,
  2345. isPrimary: false,
  2346. metaKey: false,
  2347. pointerId: 1,
  2348. pointerType: "mouse",
  2349. pressure: 0,
  2350. relatedTarget: null,
  2351. returnValue: true,
  2352. shiftKey: false,
  2353. toElement: null,
  2354. twist: 0,
  2355. type: "click",
  2356. which: 1
  2357. };
  2358. var mouseclick = new PointerEvent("click",eventParam);
  2359. btn.dispatchEvent(mouseclick);
  2360. }
  2361.  
  2362. var emuIframe;
  2363. function emuPage(callback){
  2364. let orgPage,curPage,iframeDoc,times=0,loadmoreBtn,loadmoreEnd=false,waitTimes=10;
  2365. function checkPage(){
  2366. if(isPause)return;
  2367. try{
  2368. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  2369. }catch(e){
  2370. debug("Stop as cors");
  2371. isPause=true;
  2372. callback(false, false);
  2373. return;
  2374. }
  2375.  
  2376. let nextLink=ruleParser.getNextLink(iframeDoc);
  2377. let waitTime=500,checkEval;
  2378. if(ruleParser.curSiteRule.wait){
  2379. if(isNaN(ruleParser.curSiteRule.wait)){
  2380. try{
  2381. checkEval=Function("doc",'"use strict";' + ruleParser.curSiteRule.wait);
  2382. }catch(e){
  2383. debug(e);
  2384. }
  2385. }else{
  2386. waitTime=ruleParser.curSiteRule.wait;
  2387. }
  2388. }
  2389.  
  2390. if(!orgPage){
  2391. if(!loadmoreEnd){
  2392. loadmoreBtn=getLoadMore(iframeDoc);
  2393. if(loadmoreBtn && isVisible(loadmoreBtn, iframeDoc.defaultView)){
  2394. emuClick(loadmoreBtn);
  2395. let intv=setInterval(()=>{
  2396. loadmoreBtn=getLoadMore(iframeDoc);
  2397. if(!loadmoreBtn || !loadmoreBtn.parentNode || !isVisible(loadmoreBtn, iframeDoc.defaultView)){
  2398. clearInterval(intv);
  2399. loadmoreEnd=true;
  2400. setTimeout(()=>{
  2401. checkPage();
  2402. },500);
  2403. }else{
  2404. emuClick(loadmoreBtn);
  2405. }
  2406. },200);
  2407. return;
  2408. }else{
  2409. loadmoreEnd=true;
  2410. }
  2411. }
  2412. let pageEle=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true);
  2413. if(!nextLink || !pageEle || (checkEval && !checkEval(iframeDoc))){
  2414. if(ruleParser.curSiteRule.wait && waitTimes-->0){
  2415. setTimeout(()=>{
  2416. checkPage();
  2417. },waitTime);
  2418. return;
  2419. }
  2420. }
  2421. orgPage=pageEle;
  2422. if(!orgPage || orgPage.length==0){
  2423. debug("Stop as no page when emu");
  2424. isPause=true;
  2425. callback(false, false);
  2426. return;
  2427. }
  2428. if(orgPage && orgPage[0].tagName=="UL")orgPage=orgPage[0].children;
  2429. if(orgPage && nextLink){
  2430. orgPage=orgPage[parseInt(orgPage.length/2)];
  2431. if(!isVisible(nextLink, iframeDoc.defaultView)){
  2432. debug("Stop as next hide when emu");
  2433. isPause=true;
  2434. callback(false, false);
  2435. }else{
  2436. emuClick(nextLink);
  2437. setTimeout(()=>{
  2438. checkPage();
  2439. },500);
  2440. }
  2441. }else{
  2442. debug("Stop as no next when emu");
  2443. isPause=true;
  2444. callback(false, false);
  2445. }
  2446. return;
  2447. }
  2448. if(times++ > 20){
  2449. //emuClick(nextLink);
  2450. debug("Stop as timeout when emu");
  2451. isPause=true;
  2452. callback(false, false);
  2453. return;
  2454. }
  2455. let eles=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true),checkItem=eles;
  2456. if(eles && eles.length>0 && eles[0].tagName=="UL")checkItem=eles[0].children;
  2457. if(!eles || eles.length==0 || orgPage == checkItem[parseInt(checkItem.length/2)] || (checkEval && !checkEval(iframeDoc))){
  2458. setTimeout(()=>{
  2459. checkPage();
  2460. },waitTime);
  2461. }else{
  2462. callback(iframeDoc, eles);
  2463. }
  2464. }
  2465. if(!emuIframe){
  2466. emuIframe = document.createElement('iframe');
  2467. emuIframe.name = 'pagetual-iframe';
  2468. if(ruleParser.curSiteRule.sandbox!=false){
  2469. emuIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  2470. }
  2471. emuIframe.width = '100%';
  2472. emuIframe.height = '0';
  2473. emuIframe.frameBorder = '0';
  2474. emuIframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  2475. emuIframe.addEventListener("load", e=>{
  2476. setTimeout(()=>{
  2477. try{
  2478. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  2479. }catch(e){
  2480. debug("Stop as cors");
  2481. isPause=true;
  2482. callback(false, false);
  2483. return;
  2484. }
  2485. let code=ruleParser.curSiteRule.init;
  2486. if(code){
  2487. try{
  2488. Function('doc','win','"use strict";' + code)(iframeDoc, iframeDoc.defaultView);
  2489. }catch(e){
  2490. debug(e);
  2491. }
  2492. }
  2493. checkPage();
  2494. },500);
  2495. });
  2496. emuIframe.src=location.href;
  2497. document.body.appendChild(emuIframe);
  2498. }else{
  2499. checkPage();
  2500. }
  2501. }
  2502.  
  2503. function forceIframe(url, callback){
  2504. let curIframe = document.createElement('iframe'),iframeDoc;
  2505. curIframe.name = 'pagetual-iframe';
  2506. curIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  2507. curIframe.frameBorder = '0';
  2508. curIframe.scrolling="no";
  2509. curIframe.style.cssText = 'display: block; visibility: visible; float: none; clear: both; width: 100%;height:0;background: initial; border: 0px; border-radius: 0px; margin: 0px 0px 2rem; padding: 0px; z-index: 2147483647;';
  2510. curIframe.addEventListener("load", e=>{
  2511. try{
  2512. iframeDoc=curIframe.contentDocument || curIframe.contentWindow.document;
  2513. }catch(e){
  2514. debug("Stop as cors");
  2515. isPause=true;
  2516. callback(false, false);
  2517. return;
  2518. }
  2519. ruleParser.insertPage(iframeDoc, [], url, null, true);
  2520. callback(curIframe, true);
  2521. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  2522. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  2523. });
  2524. let inAction=false;
  2525. let forceRefresh=e=>{
  2526. if(inAction || !iframeDoc)return;
  2527. inAction=true;
  2528. setTimeout(()=>{
  2529. inAction=false;
  2530. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  2531. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  2532. if(!ruleParser.nextLinkHref){
  2533. ruleParser.getNextLink(iframeDoc);
  2534. if(ruleParser.nextLinkHref){
  2535. document.removeEventListener("scroll", forceRefresh);
  2536. }
  2537. }else{
  2538. document.removeEventListener("scroll", forceRefresh);
  2539. }
  2540. },500);
  2541. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  2542. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  2543. };
  2544. document.addEventListener("scroll", forceRefresh);
  2545. curIframe.src=url;
  2546. let insert=ruleParser.getInsert();
  2547. document.body.appendChild(curIframe);
  2548. return curIframe;
  2549. }
  2550.  
  2551. function loadPageOver(){
  2552. isLoading=false;
  2553. if(loadingDiv.parentNode){
  2554. loadingDiv.parentNode.removeChild(loadingDiv);
  2555. }
  2556. setTimeout(()=>{
  2557. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  2558. if(scrollH < (window.innerHeight || document.documentElement.clientHeight)){
  2559. nextPage();
  2560. }
  2561. },1);
  2562. }
  2563.  
  2564. function nextPage(){
  2565. if(isPause || isLoading)return;
  2566. let nextLink=ruleParser.nextLinkHref;
  2567. if(!nextLink)return;
  2568. let pvGallery=document.querySelector("span.pv-gallery-container");
  2569. if(pvGallery && pvGallery.style.display!="none")return;
  2570. let insert=ruleParser.getInsert();
  2571. if(insert){
  2572. let isJs=/^(javascript|#)/.test(nextLink.replace(location.href,""));
  2573. if(location.protocol=="https:" && /^http:/.test(nextLink)){
  2574. nextLink=nextLink.replace(/^http/,"https");
  2575. }
  2576. isLoading=true;
  2577. document.body.appendChild(loadingDiv);
  2578. let sleep=ruleParser.curSiteRule.sleep||0;
  2579. setTimeout(()=>{
  2580. if(ruleParser.curSiteRule.pageElementByJs){
  2581. var over=ele=>{
  2582. loadPageOver();
  2583. if(ele){
  2584. createPageBar(nextLink);
  2585. ruleParser.insertPage(null, ele, nextLink, null, true);
  2586. if(autoLoadNum>=0){
  2587. if(autoLoadNum!=0 && --autoLoadNum==0){
  2588. autoLoadNum=-1;
  2589. }else{
  2590. nextPage();
  2591. }
  2592. }
  2593. }else{
  2594. debug("Stop as no page when get by js");
  2595. isPause=true;
  2596. }
  2597. };
  2598. try{
  2599. Function("over",'"use strict";' + ruleParser.curSiteRule.pageElementByJs)(over);
  2600. }catch(e){
  2601. debug(e);
  2602. }
  2603. }else if(ruleParser.curSiteRule.action==1 && !isJs){
  2604. requestFromIframe(nextLink, (doc, eles)=>{
  2605. loadPageOver();
  2606. if(eles){
  2607. createPageBar(nextLink);
  2608. ruleParser.insertPage(doc, eles, nextLink, null, true);
  2609. if(autoLoadNum>=0){
  2610. if(autoLoadNum!=0 && --autoLoadNum==0){
  2611. autoLoadNum=-1;
  2612. }else{
  2613. nextPage();
  2614. }
  2615. }
  2616. }
  2617. });
  2618. }else if((forceState==2||ruleParser.curSiteRule.action==2) && !isJs){
  2619. forceIframe(nextLink, (iframe, eles)=>{
  2620. loadPageOver();
  2621. let pageBar=createPageBar(nextLink);
  2622. iframe.parentNode.insertBefore(pageBar, iframe);
  2623. if(autoLoadNum>=0){
  2624. if(autoLoadNum!=0 && --autoLoadNum==0){
  2625. autoLoadNum=-1;
  2626. }else{
  2627. nextPage();
  2628. }
  2629. }
  2630. });
  2631. }else{
  2632. if(!isJs){
  2633. requestDoc(nextLink, (eles)=>{
  2634. loadPageOver();
  2635. if(eles){
  2636. createPageBar(nextLink);
  2637. if(autoLoadNum>=0){
  2638. if(autoLoadNum!=0 && --autoLoadNum==0){
  2639. autoLoadNum=-1;
  2640. }else{
  2641. nextPage();
  2642. }
  2643. }
  2644. }
  2645. });
  2646. }else{
  2647. emuPage((doc, eles)=>{
  2648. loadPageOver();
  2649. if(eles){
  2650. createPageBar(nextLink);
  2651. ruleParser.insertPage(doc, eles, "", null, true);
  2652. if(autoLoadNum>=0){
  2653. if(autoLoadNum!=0 && --autoLoadNum==0){
  2654. autoLoadNum=-1;
  2655. }else{
  2656. nextPage();
  2657. }
  2658. }
  2659. }
  2660. });
  2661. }
  2662. }
  2663. },sleep);
  2664. }
  2665. }
  2666.  
  2667. function init(){
  2668. initRules(()=>{
  2669. initPage();
  2670. });
  2671. }
  2672. setTimeout(()=>{
  2673. init();
  2674. },300);
  2675. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址