東方永頁機

自動翻頁脚本 - 自動加載並拼接下一分頁內容,無需規則驅動支持任意網頁

目前為 2022-05-17 提交的版本,檢視 最新版本

  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.6.9.7
  14. // @description Perpetual pages - Most powerful Auto Pager script. Auto loading next paginated web pages and inserting into current page.
  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. // @match *://*/*
  26. // @license MIT
  27. // @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==
  28. // @grant GM_xmlhttpRequest
  29. // @grant GM_registerMenuCommand
  30. // @grant GM_notification
  31. // @grant GM_getValue
  32. // @grant GM_setValue
  33. // @grant GM_addStyle
  34. // @grant GM_openInTab
  35. // @grant GM_deleteValue
  36. // @grant GM.xmlHttpRequest
  37. // @grant GM.registerMenuCommand
  38. // @grant GM.notification
  39. // @grant GM.getValue
  40. // @grant GM.setValue
  41. // @grant GM.addStyle
  42. // @grant GM.openInTab
  43. // @grant GM.deleteValue
  44. // @supportURL https://github.com/hoothin/UserScripts/issues
  45. // @connect wedata.net
  46. // @connect githubusercontent.com
  47. // @run-at document-idle
  48. // @exclude http://www.toodledo.com/tasks/*
  49. // @exclude http*://maps.google.com*/*
  50. // @exclude *://www.google.*/_/chrome/newtab*
  51. // @exclude *://mega.*/*
  52. // @exclude *://*.mega.*/*
  53. // @exclude *://*.youku.com/v_*
  54. // @exclude *://*pan.baidu.com
  55. // @exclude *://*.iqiyi.com/v_*
  56. // @exclude *://*.iqiyi.com/w_*
  57. // @exclude *://*.iqiyi.com/a_*
  58. // @exclude *://*.le.com/ptv/vplay/*
  59. // @exclude *://v.qq.com/x/cover/*
  60. // @exclude *://v.qq.com/x/page/*
  61. // @exclude *://v.qq.com/tv/*
  62. // @exclude *://*.tudou.com/listplay/*
  63. // @exclude *://*.tudou.com/albumplay/*
  64. // @exclude *://*.tudou.com/programs/view/*
  65. // @exclude *://*.mgtv.com/b/*
  66. // @exclude *://film.sohu.com/album/*
  67. // @exclude *://tv.sohu.com/v/*
  68. // @exclude *://*.bilibili.com/video/*
  69. // @exclude *://*.bilibili.com/bangumi/play/*
  70. // @exclude *://*.baofeng.com/play/*
  71. // @exclude *://vip.pptv.com/show/*
  72. // @exclude *://v.pptv.com/show/*
  73. // @exclude *://www.le.com/ptv/vplay/*
  74. // @exclude *://www.wasu.cn/Play/show/*
  75. // @exclude *://m.v.qq.com/*
  76. // @exclude *://m.iqiyi.com/*
  77. // @exclude *://m.youku.com/alipay_video/*
  78. // @exclude *://m.mgtv.com/b/*
  79. // @exclude *://m.tv.sohu.com/v/*
  80. // @exclude *://m.film.sohu.com/album/*
  81. // @exclude *://m.le.com/ptv/vplay/*
  82. // @exclude *://m.pptv.com/show/*
  83. // @exclude *://m.acfun.cn/v/*
  84. // @exclude *://m.bilibili.com/video/*
  85. // @exclude *://m.bilibili.com/anime/*
  86. // @exclude *://m.bilibili.com/bangumi/play/*
  87. // @exclude *://m.wasu.cn/Play/show/*
  88. // @exclude *://www.youtube.com
  89. // @exclude *://www.youtube.com/
  90. // @exclude *://www.youtube.com/watch*
  91. // @exclude *://baike.baidu.com/*
  92. // @exclude *://*.instagram.com/*
  93. // @exclude *://order.jd.com/*
  94. // @exclude *://pagetual.hoothin.com/*
  95. // @exclude *://hoothin.github.io/PagetualGuide/*
  96. // @exclude *://wenku.baidu.com/view/*
  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. forceAllBody:"是否拼接整个页面?",
  172. openInNewTab:"使拼接页面的内容在新页面打开",
  173. importSucc:"导入成功",
  174. editCurrent:"自定义此站规则",
  175. editBlacklist:"编辑黑名单网址,一行一条,支持? *通配符"
  176. };
  177. break;
  178. case "zh-TW":
  179. case "zh-HK":
  180. config={
  181. enableDebug:"調試模式,輸出信息至控制台",
  182. disable:"暫時禁用",
  183. disableSite:"在此站禁用",
  184. enable:"啟用翻頁",
  185. toTop:"回到頂部",
  186. toBottom:"前往頁尾",
  187. current:"當前頁",
  188. forceIframe:"強制拼接",
  189. cancelForceIframe:"取消强制拼接",
  190. configure:"打開配置頁",
  191. firstUpdate:"點擊此處初始化規則",
  192. update:"更新規則",
  193. click2update:"點擊立即更新規則",
  194. loadNow:"立即翻頁",
  195. loadConfirm:"要翻几頁?(0為不間斷)",
  196. noNext:"沒有找到下一頁,請新建規則",
  197. passSec:"更新于 #t# 秒前",
  198. passMin:"更新于 #t# 分鐘前",
  199. passHour:"更新于 #t# 小時前",
  200. passDay:"更新于 #t# 天前",
  201. cantDel:"無法刪除内置規則",
  202. confirmDel:"是否確認要刪除此規則?",
  203. updateSucc:"更新成功",
  204. beginUpdate:"正在更新,請稍候",
  205. customUrls:"導入規則url,一行一條,AutoPagerize 格式規則需要以\"0|\"開頭",
  206. customRules:"輸入【東方永頁機】格式的自定義規則",
  207. save:"存儲設置",
  208. loadingText:"少女祈禱中...",
  209. opacity:"分頁隔條不透明值",
  210. hideBar:"空白處雙擊隱藏分頁隔條",
  211. dbClick2Stop:"空白處雙擊暫停翻頁",
  212. sortTitle:"排序在下次更新規則後生效",
  213. autoRun:"自動啓用,否則為白名單模式",
  214. inputPageNum:"輸入頁碼跳轉",
  215. enableHistory:"翻頁后寫入歷史記錄",
  216. initRun:"打開頁面后立即嘗試翻頁,否則滾動至頁尾再翻頁",
  217. preload:"翻頁前預讀下一頁,加速瀏覽",
  218. click2ImportRule:"點擊下方添加特殊規則庫,添加後再行更新:",
  219. forceAllBody:"是否拼接整個頁面?",
  220. openInNewTab:"使拼接頁面的内容在新頁面打開",
  221. importSucc:"導入成功",
  222. editCurrent:"自定義此站規則",
  223. editBlacklist:"編輯黑名單網址,一行一條,支持? *通配符"
  224. };
  225. break;
  226. case "ja":
  227. config = {
  228. enableDebug:"デバッグモード",
  229. disable: "一時的に無効にする",
  230. disableSite:"このサイト無効",
  231. enable: "ページめくりを有効にする",
  232. toTop: "トップに戻る",
  233. toBottom: "ページの下部に移動",
  234. current: "現在のページ",
  235. forceIframe: "強制ステッチ",
  236. cancelForceIframe: "強制ステッチをキャンセル",
  237. configure: "設定ページを開く",
  238. firstUpdate:"ここをクリックしてルールを初期化します",
  239. update: "更新ルール",
  240. click2update:"今すぐルールを更新してください",
  241. loadNow:"今すぐページをめくる",
  242. loadConfirm:"数ページめくりたいですか?(0は途切れない)",
  243. noNext:"次のページが見つかりません、新しいルールを作成してください",
  244. passSec: "#t#秒前に更新",
  245. passMin: "#t#分前に更新",
  246. passHour: "#t#時間前に更新",
  247. passDay: "#t#日前に更新",
  248. cantDel: "組み込みルールを削除できません",
  249. confirmDel: "このルールを削除してもよろしいですか?",
  250. updateSucc: "更新に成功しました",
  251. beginUpdate: "更新中、お待ちください",
  252. customUrls: "インポートルールのURL、1行に1つ、AutoPagerizeフォーマットルールは\"0|\"で始まる必要があります",
  253. customRules: "【東方永頁機】の形式でカスタムルールを入力してください",
  254. save: "設定を保存",
  255. loadingText: "少女祈祷中...",
  256. opacity:"ページネーションバーの不透明値",
  257. hideBar:"空白部分をダブルクリックして、ページ区切り文字を非表示にします",
  258. dbClick2Stop:"空白部分をダブルクリックしてページめくりを一時停止します",
  259. sortTitle:"並べ替えは、次のルールの更新後に有効になります",
  260. autoRun:"自動的に有効",
  261. inputPageNum:"ジャンプするページ番号を入力",
  262. enableHistory:"ページめくり後の履歴を書く",
  263. initRun:"Webページを開いた直後にページをめくる",
  264. preload:"事前に次のページを読む",
  265. click2ImportRule:"以下をクリックして、ルールベースを追加します:",
  266. forceAllBody:"フルページ埋め込み?",
  267. openInNewTab:"スプライスされたページのコンテンツを新しいページで開きます",
  268. importSucc:"インポート完了",
  269. editCurrent:"現在のルールの編集",
  270. editBlacklist:"ブラックリストのURLを編集し、1行ずつ、サポート? *ワイルドカード"
  271. };
  272. break;
  273. default:
  274. config={
  275. enableDebug:"Enable debug output",
  276. disable:"Disable",
  277. disableSite:"Disable on the site",
  278. enable:"Enable",
  279. toTop:"To Top",
  280. toBottom:"To Bottom",
  281. current:"Current Page",
  282. forceIframe:"Force to join",
  283. cancelForceIframe:"Cancel Force join",
  284. configure:"Configure",
  285. firstUpdate:"Click here to initialize the rules",
  286. update:"Update rules",
  287. click2update:"Click to update rules from url now",
  288. loadNow:"Load next now",
  289. loadConfirm:"How much pages do you want to load? (0 means infinite)",
  290. noNext:"No next link found, please create a new rule",
  291. passSec:"Updated #t# seconds ago",
  292. passMin:"Updated #t# minutes ago",
  293. passHour:"Updated #t# hours ago",
  294. passDay:"Updated #t# days ago",
  295. cantDel:"Can't delete buildin rules",
  296. confirmDel:"Are you sure you want to delete this rule?",
  297. updateSucc:"Update succeeded",
  298. beginUpdate:"Begin update, wait a minute please",
  299. customUrls:"Import rule url, One url per line, rules on AutoPagerize format need to start with \"0|\"",
  300. customRules:"Input custom rules with [Pagetual] format",
  301. save:"Save",
  302. loadingText:"Shojo Now Loading...",
  303. opacity:"Pagination spacer opacity",
  304. hideBar:"Double-click on the blank space to hide the paging spacer",
  305. dbClick2Stop:"Double-click on the blank space to pause",
  306. sortTitle:"Sorting takes effect after the next rule update",
  307. autoRun:"Auto run (black list mode)",
  308. inputPageNum:"Enter page number to jump",
  309. enableHistory:"Write history after page turning",
  310. initRun:"Turn pages immediately after opening",
  311. preload:"Preload next page for speeding up",
  312. click2ImportRule:"Click to import base rules link, then click to update rules:",
  313. forceAllBody:"Join full body of page?",
  314. openInNewTab:"Open urls of additions in new tab",
  315. importSucc:"Import completed",
  316. editCurrent:"Edit rule for current",
  317. editBlacklist:"Edit the blacklist urls, line by line, Support ? * for wildcard"
  318. };
  319. break;
  320. }
  321. return config[name]?config[name].replace("#t#",param):name;
  322. };
  323.  
  324. var noRuleTest=false;
  325. var enableDebug=true;
  326. var debug=str=>{
  327. if(enableDebug){
  328. console.debug(str);
  329. }
  330. };
  331.  
  332. var _GM_xmlhttpRequest,_GM_registerMenuCommand,_GM_notification,_GM_addStyle,_GM_openInTab;
  333. if(typeof GM_xmlhttpRequest!='undefined'){
  334. _GM_xmlhttpRequest=GM_xmlhttpRequest;
  335. }else if(typeof GM!='undefined' && typeof GM.xmlHttpRequest!='undefined'){
  336. _GM_xmlhttpRequest=GM.xmlHttpRequest;
  337. }else{
  338. _GM_xmlhttpRequest=(f)=>{fetch(f.url).then(response=>response.text()).then(data=>{let res={response:data};f.onload(res)}).catch(f.onerror())};
  339. }
  340. if(typeof GM_registerMenuCommand!='undefined'){
  341. _GM_registerMenuCommand=GM_registerMenuCommand;
  342. }else if(typeof GM!='undefined' && typeof GM.registerMenuCommand!='undefined'){
  343. _GM_registerMenuCommand=GM.registerMenuCommand;
  344. }else{
  345. _GM_registerMenuCommand=(s,f)=>{};
  346. }
  347. if(typeof GM_notification!='undefined'){
  348. _GM_notification=GM_notification;
  349. }else if(typeof GM!='undefined' && typeof GM.notification!='undefined'){
  350. _GM_notification=GM.notification;
  351. }else{
  352. _GM_notification=(s)=>{showTips(s)};
  353. }
  354. if(typeof GM_openInTab!='undefined'){
  355. _GM_openInTab=GM_openInTab;
  356. }else if(typeof GM!='undefined' && typeof GM.openInTab!='undefined'){
  357. _GM_openInTab=GM.openInTab;
  358. }else{
  359. _GM_openInTab=(s,t)=>{window.open(s)};
  360. }
  361. if(typeof GM_addStyle!='undefined'){
  362. _GM_addStyle=GM_addStyle;
  363. }else if(typeof GM!='undefined' && typeof GM.addStyle!='undefined'){
  364. _GM_addStyle=GM.addStyle;
  365. }else{
  366. _GM_addStyle=cssStr=>{
  367. let styleEle=document.createElement("style");
  368. styleEle.innerHTML=cssStr;
  369. document.head.appendChild(styleEle);
  370. };
  371. }
  372. var _unsafeWindow=(typeof unsafeWindow=='undefined')?window:unsafeWindow;//兼容 ios userscripts 的寫法
  373. var storage={
  374. supportGM: typeof GM_getValue=='function' && typeof GM_getValue('a','b')!='undefined',
  375. supportGMPromise: typeof GM!='undefined' && typeof GM.getValue=='function' && typeof GM.getValue('a','b')!='undefined',
  376. mxAppStorage:(function(){
  377. try{
  378. return window.external.mxGetRuntime().storage;
  379. }catch(e){
  380. }
  381. })(),
  382. operaUJSStorage:(function(){
  383. try{
  384. return window.opera.scriptStorage;
  385. }catch(e){
  386. }
  387. })(),
  388. setItem:function(key,value){
  389. if(this.operaUJSStorage){
  390. this.operaUJSStorage.setItem(key,value);
  391. }else if(this.mxAppStorage){
  392. this.mxAppStorage.setConfig(key,value);
  393. }else if(this.supportGM){
  394. GM_setValue(key,value);
  395. if(value==="" && typeof GM_deleteValue!='undefined'){
  396. GM_deleteValue(key);
  397. }
  398. }else if(this.supportGMPromise){
  399. GM.setValue(key,value);
  400. if(value==="" && typeof GM!='undefined' && typeof GM.deleteValue!='undefined'){
  401. GM.deleteValue(key);
  402. }
  403. }else if(window.localStorage){
  404. window.localStorage.setItem(key,value);
  405. }
  406. },
  407. getItem:function(key,cb){
  408. var value;
  409. if(this.operaUJSStorage){
  410. value=this.operaUJSStorage.getItem(key);
  411. }else if(this.mxAppStorage){
  412. value=this.mxAppStorage.getConfig(key);
  413. }else if(this.supportGM){
  414. value=GM_getValue(key);
  415. }else if(this.supportGMPromise){
  416. value=GM.getValue(key).then(v=>{cb(v)});
  417. return;
  418. }else if(window.localStorage){
  419. value=window.localStorage.getItem(key);
  420. };
  421. cb(value);
  422. }
  423. };
  424. var rulesData={},ruleUrls,updateDate,configPage="https://github.com/hoothin/UserScripts/tree/master/Pagetual";
  425. var ruleImportUrlReg=/greasyfork\.org\/.*scripts\/438684[^\/]*(\/discussions|\/?$)|github\.com\/hoothin\/UserScripts\/(tree\/master\/Pagetual|issues)/i;
  426. var allOfBody="body>*";
  427. _GM_registerMenuCommand(i18n("configure"), ()=>{
  428. _GM_openInTab(configPage,{active:true});
  429. });
  430. _GM_registerMenuCommand(i18n("editCurrent"), ()=>{
  431. let editTemp;
  432. if(ruleParser.curSiteRule.url && !ruleParser.curSiteRule.singleUrl){
  433. editTemp=ruleParser.curSiteRule;
  434. }else{
  435. editTemp={
  436. name: document.title,
  437. url: "^"+location.origin.replace(/\./g,"\\."),
  438. pageElement: ruleParser.curSiteRule.pageElement||""
  439. };
  440. }
  441. rulesData.editTemp=editTemp;
  442. storage.setItem("rulesData", rulesData);
  443. _GM_openInTab(configPage,{active:true});
  444. });
  445.  
  446. function getElementByXpath(xpath, contextNode, doc){
  447. doc = doc || document;
  448. contextNode = contextNode || doc;
  449. try {
  450. var result = doc.evaluate(xpath, contextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
  451. return result.singleNodeValue && result.singleNodeValue.nodeType === 1 && result.singleNodeValue;
  452. } catch (err) {
  453. throw new Error(`Invalid xpath: ${xpath}`);
  454. }
  455. }
  456.  
  457. function getAllElementsByXpath(xpath, contextNode, doc){
  458. doc = doc || document;
  459. contextNode = contextNode || doc;
  460. var result = [];
  461. try {
  462. var query = doc.evaluate(xpath, contextNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  463. for (var i = 0; i < query.snapshotLength; i++) {
  464. var node = query.snapshotItem(i);
  465. if (node.nodeType === 1) result.push(node);
  466. }
  467. } catch (err) {
  468. throw new Error(`Invalid xpath: ${xpath}`);
  469. }
  470. return result;
  471. }
  472.  
  473. class RuleParser {
  474. constructor() {
  475. this.hpRules=[];
  476. this.customRules=[];
  477. this.rules=[];
  478. this.pageDoc=document;
  479. this.nextLinkHref=null;
  480. this.nextTitle="";
  481. this.oldUrl="";
  482. this.curUrl=location.href;
  483. this.curSiteRule={};
  484. }
  485.  
  486. initSavedRules(callback){
  487. var self=this;
  488. storage.getItem("hpRules", hpRules=>{
  489. if(hpRules)self.hpRules=hpRules;
  490. storage.getItem("customRules", customRules=>{
  491. if(customRules)self.customRules=customRules;
  492. storage.getItem("rules", rules=>{
  493. if(rules)self.rules=rules;
  494. callback();
  495. });
  496. });
  497. });
  498. }
  499.  
  500. saveCurSiteRule(){
  501. if(!this.curSiteRule || !this.curSiteRule.url || this.curSiteRule.singleUrl)return;
  502. this.hpRules=this.hpRules.filter(item=>{return item&&item.url!=this.curSiteRule.url});
  503. this.hpRules.unshift(this.curSiteRule);
  504. if(this.hpRules.length>30){
  505. this.hpRules.pop();
  506. }
  507. storage.setItem("hpRules", this.hpRules);
  508. }
  509.  
  510. requestJSON(url, callback){
  511. _GM_xmlhttpRequest({
  512. url: url,
  513. method: 'GET',
  514. timeout: 20000,
  515. onload: function(res) {
  516. let json=null;
  517. try{
  518. json=JSON.parse(res.response||res.responseText);
  519. }catch(e){
  520. debug(e);
  521. }
  522. callback(json);
  523. },
  524. onerror: function(e) {
  525. callback(null, e);
  526. },
  527. ontimeout: function(e) {
  528. callback(null, e);
  529. }
  530. });
  531. }
  532.  
  533. formatRule(item, type, from){
  534. switch(type){
  535. case 0:
  536. return {
  537. from:from,
  538. type:type,
  539. name:item.name,
  540. action:item.data.forceIframe=="true"?1:0,
  541. url:item.data.url,
  542. pageElement:item.data.pageElement,
  543. nextLink:item.data.nextLink,
  544. insert:item.data.insertBefore,
  545. insertPos:1,
  546. updatedAt:item.data.updated_at,
  547. css:item.data.Stylus+item.data.CSS,
  548. pageAction:item.data.bookmarklet
  549. };
  550. break;
  551. case 1:
  552. default:
  553. item.from=from;
  554. if(typeof(item.type) == "undefined")item.type=type;
  555. return item;
  556. break;
  557. }
  558. return null;
  559. }
  560.  
  561. addRuleByUrl(url, type, from, callback) {
  562. if(url.indexOf("?")==-1){
  563. url=url+"?"+Date.now();
  564. }else{
  565. url=url+"&"+Date.now();
  566. }
  567. this.requestJSON(url, (json,err)=>{
  568. if(!json){
  569. debug("Update "+url+" rules fail!");
  570. debug(err);
  571. }
  572. this.addRules(json, type, from);
  573. callback(json, err);
  574. });
  575. }
  576.  
  577. addRules(rules, type, from) {
  578. if(rules && rules.length>0){
  579. this.rules=this.rules.filter(item=>{return item.from!=from});
  580. rules.forEach(item=>{
  581. let rule=this.formatRule(item, type, from);
  582. if(rule){
  583. this.rules.unshift(rule);
  584. }
  585. });
  586. }
  587. }
  588.  
  589. getRule(callback) {
  590. if(noRuleTest){
  591. this.curSiteRule={};
  592. this.curSiteRule.url=location.origin+location.pathname;
  593. this.curSiteRule.singleUrl=true;
  594. callback();
  595. return;
  596. }
  597. if(this.curSiteRule && this.curSiteRule.url){
  598. return this.curSiteRule;
  599. }
  600. var self=this;
  601.  
  602. function setRule(r){
  603. self.curSiteRule=r;
  604. debug(r);
  605. callback();
  606. }
  607.  
  608. function ruleMatch(r){
  609. let pageElement,nextLink,insert;
  610. if(r.nextLink && r.nextLink!="0" && r.nextLink!=0){
  611. nextLink=r.type==0?getElementByXpath(r.nextLink):document.querySelector(r.nextLink);
  612. if(!nextLink)return false;
  613. }
  614. if(r.pageElement){
  615. pageElement=r.type==0?getElementByXpath(r.pageElement):document.querySelector(r.pageElement);
  616. if(!pageElement)return false;
  617. }
  618. if(r.insert){
  619. insert=r.type==0?getElementByXpath(r.insert):document.querySelector(r.insert);
  620. if(!insert)return false;
  621. }
  622. return true;
  623. }
  624.  
  625. function checkRule(r){
  626. let urlReg=new RegExp(r.url, "i");
  627. if(urlReg.test(location.href)){
  628. if(r.wait){
  629. let waitTime=500,checkEval;
  630. if(isNaN(r.wait)){
  631. try{
  632. checkEval=Function("doc",'"use strict";' + r.wait);
  633. }catch(e){
  634. debug(e);
  635. }
  636. }else{
  637. waitTime=r.wait;
  638. }
  639. let checkReady=()=>{
  640. setTimeout(()=>{
  641. if(!ruleMatch(r) || (checkEval && !checkEval(document))){
  642. checkReady();
  643. }else{
  644. setRule(r);
  645. }
  646. },parseInt(waitTime));
  647. };
  648. checkReady();
  649. return true;
  650. }
  651. if(r.pinUrl){
  652. setRule(r);
  653. return true;
  654. }
  655. if(!ruleMatch(r)){
  656. return false;
  657. }
  658. setRule(r);
  659. return true;
  660. }
  661. return false;
  662. }
  663.  
  664. for(let i in this.hpRules){
  665. let rule=this.hpRules[i];
  666. if(!rule || !rule.url)continue;
  667. if(rule.singleUrl){
  668. if(location.origin+location.pathname==rule.url){
  669. setRule(rule);
  670. return;
  671. }
  672. continue;
  673. }
  674. if(checkRule(rule))return;
  675. }
  676. for(let i in this.customRules){
  677. let rule=this.customRules[i];
  678. if(!rule || !rule.url)continue;
  679. if(checkRule(rule))return;
  680. }
  681. let r=0;
  682. function searchByTime(){
  683. setTimeout(()=>{
  684. let end=r+50;
  685. end=end>self.rules.length?self.rules.length:end;
  686. for(;r<end;r++){
  687. let rule=self.rules[r];
  688. if(checkRule(rule))return;
  689. }
  690. if(end>=self.rules.length){
  691. self.curSiteRule={};
  692. self.curSiteRule.url=location.origin+location.pathname;
  693. self.curSiteRule.singleUrl=true;
  694. callback();
  695. return;
  696. }else{
  697. searchByTime();
  698. }
  699. },10);
  700. }
  701. searchByTime();
  702. }
  703.  
  704. geneSelector(ele){
  705. let selector=ele.tagName;
  706. //Google id class都是隨機。百度更過分,style script順序都是隨機的
  707. //if(ele.id) selector += '#' + ele.id;
  708. //if(ele.classList) selector += [].map.call(ele.classList,d=>'.'+d).join('');
  709. if(ele.tagName!="HTML" && ele.tagName!="BODY"){
  710. if(ele.className) selector += [].map.call(ele.classList,d=>'.'+d).join('');
  711. let parent = ele.parentElement;
  712. if(parent){
  713. selector = this.geneSelector(parent) + ' > ' + selector;
  714. if(!ele.className){
  715. let i,j=0;
  716. for(i=0;i<parent.children.length;i++){
  717. if(parent.children[i].tagName==ele.tagName){
  718. j++;
  719. if(parent.children[i]==ele){
  720. break;
  721. }
  722. }
  723. }
  724. selector += (parent.tagName=="HTML"?"":`:nth-of-type(${j})`);
  725. }
  726. }
  727. }
  728. return selector;
  729. }
  730.  
  731. getPageElement(doc, curWin, dontFind) {
  732. let pageElement=null;
  733. let self=this;
  734. let body=doc.body;
  735. if(this.curSiteRule.pageElement){
  736. pageElement=this.curSiteRule.type==0?getAllElementsByXpath(this.curSiteRule.pageElement,doc,doc):doc.querySelectorAll(this.curSiteRule.pageElement);
  737. }else if(!this.curSiteRule.singleUrl && this.curSiteRule.type==0){
  738. pageElement=[body];
  739. }
  740. if(this.curSiteRule.singleUrl && pageElement && pageElement.length>0 && pageElement[0].tagName=="TR"){
  741. let mainTr=this.insert.previousElementSibling,mainTdNum=0,newTdNum=0;
  742. [].forEach.call(mainTr.children, el=>{
  743. if(el.tagName=="TD" || el.tagName=="TH"){
  744. mainTdNum+=el.colSpan||1;
  745. }
  746. });
  747. [].forEach.call(pageElement[0].children, el=>{
  748. if(el.tagName=="TD" || el.tagName=="TH"){
  749. newTdNum+=el.colSpan||1;
  750. }
  751. });
  752. if(mainTdNum!=newTdNum){
  753. this.curSiteRule.pageElement=allOfBody;
  754. pageElement=[body];
  755. this.getInsert(true);
  756. }
  757. }
  758. if((this.curSiteRule.singleUrl || !this.curSiteRule.pageElement) && (!pageElement || pageElement.length==0) && curWin && !dontFind){
  759. if(!body)return null;
  760. let bodyHeight=parseInt(body.scrollHeight);
  761. let curHeight=bodyHeight;
  762. let windowHeight=window.innerHeight || document.documentElement.clientHeight;
  763. let needCheckNext=(doc==document && this.initNext);
  764. function checkElement(ele){
  765. if(ele.childNodes && ele.childNodes.length==1)ele=ele.childNodes[0];
  766. if(ele.tagName=="PICTURE"){
  767. self.curSiteRule.pageElement=self.geneSelector(ele.parentNode)+">"+ele.tagName;
  768. debug(self.curSiteRule.pageElement);
  769. return [ele];
  770. }
  771. if(curHeight/bodyHeight<=0.25){
  772. self.curSiteRule.pageElement=allOfBody;
  773. debug(self.curSiteRule.pageElement);
  774. return [body];
  775. }
  776. if(ele.tagName=="FORM"){
  777. self.curSiteRule.pageElement=self.geneSelector(ele)+">*";
  778. debug(self.curSiteRule.pageElement);
  779. return ele.children;
  780. }
  781. if(ele.children.length==0 && !self.curSiteRule.pageElement){
  782. if(ele.parentNode.tagName=="P")ele=ele.parentNode;
  783. self.curSiteRule.pageElement=self.geneSelector(ele.parentNode)+">"+ele.tagName;
  784. debug(self.curSiteRule.pageElement);
  785. return [ele];
  786. }
  787. let i,maxHeight=curHeight*0.55,curMaxEle=null,curMaxArea=0,maxWidth=0;
  788. let isHori=true;
  789. let offsetTop=ele.children[0].offsetTop;
  790. for(i=1;i<ele.children.length;i++){
  791. if(ele.children[i].offsetTop!=offsetTop){
  792. isHori=false;
  793. break;
  794. }
  795. }
  796. for(i=0;i<ele.children.length;i++){
  797. let curNode=ele.children[i];
  798. if(curNode.tagName=="CANVAS")continue;
  799. if(curNode.tagName!="IMG" && /^\s*$/.test(curNode.innerText))continue;
  800. if(needCheckNext && !curNode.contains(self.initNext) && getElementTop(curNode)>windowHeight){
  801. continue;
  802. }
  803. let comStyle=curWin.getComputedStyle(curNode);
  804. let h=parseInt(curNode.scrollHeight);
  805. let w=parseInt(curNode.scrollWidth);
  806. if(isNaN(h) || isNaN(w))continue;
  807. if(isHori && h==0)continue;
  808. let a=h*w+h,moreChild=curNode.children[0];
  809. while(moreChild){
  810. comStyle=curWin.getComputedStyle(moreChild);
  811. let ch=parseInt(moreChild.scrollHeight);
  812. let cw=parseInt(moreChild.scrollWidth);
  813. if(h<ch)h=ch;
  814. if(moreChild.innerText!="" && !isNaN(ch) && !isNaN(cw)){
  815. a+=ch*cw;
  816. }
  817. moreChild=moreChild.nextElementSibling;
  818. }
  819. let isMax=false;
  820. if(isHori){
  821. if(maxWidth<w){
  822. isMax=true;
  823. }else if(maxWidth==w && curMaxArea<a){
  824. isMax=true;
  825. }
  826. }else{
  827. isMax=curMaxArea<a;
  828. }
  829. if(curMaxEle==null || isMax){
  830. if(h>0 || !isHori)curHeight=h;
  831. curMaxArea=a;
  832. maxWidth=w;
  833. curMaxEle=curNode;
  834. }
  835. }
  836. if(curMaxEle && (isHori || curHeight>maxHeight || (needCheckNext && curHeight>windowHeight && ele.contains(self.initNext)))){
  837. return checkElement(curMaxEle);
  838. }
  839. if(ele.tagName=="P" || ele.tagName=="BR")ele=ele.parentNode;
  840. if(ele.tagName=="TBODY"){
  841. self.curSiteRule.pageElement=self.geneSelector(ele)+">*";
  842. if(ele.children.length>0 && ele.children[0].querySelector("th")){
  843. self.curSiteRule.pageElement+=":not(:first-child)";
  844. }
  845. debug(self.curSiteRule.pageElement);
  846. return ele.children;
  847. }
  848. self.curSiteRule.pageElement=self.geneSelector(ele);
  849. if(ele.children.length>1){
  850. let middleChild=ele.children[parseInt(ele.children.length/2)];
  851. if((middleChild.style && middleChild.style.position=="absolute" && middleChild.style.left && middleChild.style.top) || ele.tagName=="UL" || curHeight==0){
  852. ele=[ele];
  853. }else{
  854. self.curSiteRule.pageElement+=">*";
  855. ele=ele.children;
  856. }
  857. }else{
  858. ele=[ele];
  859. }
  860. debug(self.curSiteRule.pageElement);
  861. return ele;
  862. }
  863. pageElement=checkElement(body);
  864. if(pageElement)this.saveCurSiteRule();
  865. }
  866. return pageElement;
  867. }
  868.  
  869. getPage(doc){
  870. if(_unsafeWindow.Discourse)return {};
  871. let canSave=false;//發現頁碼選擇器在其他頁對不上,還是別保存了
  872. let url=this.curUrl.replace("#!","").replace("index.php?","?");
  873. let pageNum=1,preStr="",afterStr="";
  874. let pageMatch1=url.match(/(.*[a-z\/\-_](?:p|page)?\/?)(\d+)(\.s?html?$|\/?$)/i);
  875. let pageMatch2=url.match(/(.*[\?&]p(?:age)?=)(\d+)($|[#&].*)/i);
  876. if(pageMatch1){
  877. preStr=pageMatch1[1];
  878. pageNum=parseInt(pageMatch1[2]);
  879. afterStr=pageMatch1[3];
  880. }else if(pageMatch2){
  881. preStr=pageMatch2[1];
  882. pageNum=parseInt(pageMatch2[2]);
  883. afterStr=pageMatch2[3];
  884. }
  885. let curPage=doc,i,cur,jsNext;
  886. let next1,next2,next3,next4,nextJs1,nextJs2,nextJs3;
  887. let next=curPage.querySelector(".page-next>a")||
  888. curPage.querySelector("a.next_page")||
  889. curPage.querySelector("#next_page")||
  890. curPage.querySelector(".nextPage")||
  891. curPage.querySelector("a[data-pagination=next]")||
  892. curPage.querySelector("ul.pagination>li.active+li>a")||
  893. curPage.querySelector(".pagination a[rel=next]")||
  894. curPage.querySelector(".pagination-nav__item--next>a")||
  895. curPage.querySelector("a[title='Next page']")||
  896. curPage.querySelector("a.pageright")||
  897. curPage.querySelector("a#rightFix")||
  898. curPage.querySelector("a#next")||
  899. curPage.querySelector(".next>a")||
  900. curPage.querySelector(".next>button")||
  901. curPage.querySelector("a[alt=next]")||
  902. curPage.querySelector("button.next")||
  903. curPage.querySelector("[title=next]");
  904. if(!next){
  905. let nexts=curPage.querySelectorAll("a.next");
  906. for(i=0;i<nexts.length;i++){
  907. if(!/^([上前首尾][一1]?[页頁张張]|previous(\s*page)?\s*›?$|前のページ)/i.test(nexts[i].innerText.trim())){
  908. next=nexts[i];
  909. break;
  910. }
  911. }
  912. }
  913. if(next && (!next.href || /^javascript:/.test(next.href) || next.getAttribute("href")=="#")){
  914. jsNext=next;
  915. next=null;
  916. }
  917. if(!next){
  918. next=curPage.querySelectorAll("[aria-label='Next page']");
  919. if(next && next.length==1){
  920. next=next[0];
  921. if(!next.href || /^javascript:/.test(next.href) || next.getAttribute("href")=="#"){
  922. if(!jsNext)jsNext=next;
  923. next=null;
  924. }
  925. }else{
  926. next=null;
  927. }
  928. }
  929. if(!next){
  930. next=curPage.querySelectorAll("[aria-label='Next']");
  931. if(next && next.length==1){
  932. next=next[0];
  933. if(!next.href || /^javascript:/.test(next.href) || next.getAttribute("href")=="#"){
  934. if(!jsNext)jsNext=next;
  935. next=null;
  936. }
  937. }else{
  938. next=null;
  939. }
  940. }
  941. if(next && /^[下后後][一1]?[章话話篇]/i.test(next.innerText.trim())){
  942. next2=next;
  943. next=null;
  944. }
  945. if(!next){
  946. next=curPage.querySelector("a.curr");
  947. if(next){
  948. next=next.nextSibling;
  949. }
  950. }
  951. if(!next){
  952. next=curPage.querySelector("div.wp-pagenavi>span.current+a,div.page-nav>span.current+a,div.article-paging>span+a");
  953. }
  954. if(!next){
  955. let pageDiv=curPage.querySelector("div.pages>ul");
  956. if(pageDiv){
  957. cur=pageDiv.querySelector("li>b");
  958. if(cur)next=cur.parentNode.nextElementSibling;
  959. if(next)next=next.querySelector("a");
  960. }
  961. }
  962. if(!next){
  963. cur=curPage.querySelector(".number>ul>li.active");
  964. if(cur)next=cur.nextElementSibling;
  965. if(next)next=next.querySelector("a");
  966. }
  967. if(!next){
  968. let aTags=curPage.querySelectorAll("a,button");
  969. for(i=aTags.length-1;i>=0;i--){
  970. let aTag=aTags[i];
  971. if(aTag.innerText=="§")continue;
  972. if(aTag.innerText.length>50)continue;
  973. if(aTag.style.display=="none")continue;
  974. if(next1 && next2 && next3 && next4)break;
  975. if(aTag.href && /next$/i.test(aTag.href))continue;
  976. if(!next1){
  977. if(aTag.innerText.length>15)continue;
  978. if(/^[下后後][一1]?[页頁张張]|^next([ _-]?page)?\s*[›>→»]?$|次のページ|^次へ?$/i.test(aTag.innerText.trim())){
  979. if(!aTag.href || /^javascript:/.test(aTag.href) || aTag.getAttribute("href")=="#"){
  980. if(!nextJs1)nextJs1=aTag;
  981. }else{
  982. next1=aTag;
  983. }
  984. }
  985. }
  986. if(!next2){
  987. if(aTag.innerText.length>15)continue;
  988. if(/^[下后後][一1]?[章话話篇]/i.test(aTag.innerText.trim()) || /nextpage/i.test(aTag.className)){
  989. if(!aTag.href || /^javascript:/.test(aTag.href) || aTag.getAttribute("href")=="#"){
  990. if(!nextJs2)nextJs2=aTag;
  991. }else{
  992. next2=aTag;
  993. }
  994. }
  995. }
  996. if(!next3){
  997. if(aTag.innerText.length>15)continue;
  998. if(aTag.innerText=="&gt;" || aTag.innerText=="▶" || aTag.innerText==">" || aTag.innerText=="›" || aTag.innerText=="→" || aTag.innerText=="»"){
  999. if(!aTag.href || /^javascript:/.test(aTag.href) || aTag.getAttribute("href")=="#"){
  1000. if(!nextJs3)nextJs3=aTag;
  1001. }else{
  1002. next3=aTag;
  1003. }
  1004. }
  1005. }
  1006. if(!aTag.href || /^javascript:/.test(aTag.href) || aTag.getAttribute("href")=="#")continue;
  1007. if(!next4 && aTag.href.length<250){
  1008. let _aHref=aTag.href.replace("?&","?").replace("#!","").replace("index.php?","?");
  1009. let _aHrefTrim=_aHref;
  1010. if(preStr)_aHrefTrim=_aHrefTrim.replace(preStr,"");
  1011. if(afterStr)_aHrefTrim=_aHrefTrim.replace(afterStr,"");
  1012. if(pageNum<999 && _aHrefTrim==pageNum+1){
  1013. next4=aTag;
  1014. }else if(this.curUrl!=aTag.href){
  1015. let _url=url.replace(/\.s?html?$/i,"");
  1016. _aHref=_aHref.replace(/\.s?html?$/i,"");
  1017. if(_aHref.indexOf(_url)!=-1 && /^[\/\?&]?[_-]?(p|page)?=?\/?2(\/|\?|&|$)/i.test(_aHref.replace(_url,""))){
  1018. let curHref=aTag.getAttribute("href");
  1019. let pageOne=curHref.replace(/\/2(\/|\?|&|$)/,"/1$1");
  1020. if(pageOne==curHref)pageOne=null;
  1021. else pageOne=curPage.querySelector(`a[href='${pageOne}']`);
  1022. if(!pageOne || pageOne.className!=curHref.className)next4=aTag;
  1023. }
  1024. }
  1025. }
  1026. }
  1027. if(next3){
  1028. let eles=getAllElementsByXpath(`//a[text()='${next3.innerText}']`,curPage,curPage);
  1029. if(eles.length>1)next3=null;
  1030. }
  1031. }
  1032. if(!next)next=next1||next4||next3||next2||jsNext||nextJs1||nextJs3||nextJs2;
  1033. if(next && next.classList.contains("results-more"))next=null;
  1034. return {next:next,canSave:canSave};
  1035. }
  1036.  
  1037. canonicalUri(src) {
  1038. if(src.charAt(0)=="#")return location.href+src;
  1039. var root_page = /^[^?#]*\//.exec(location.href)[0],
  1040. base_path = location.pathname.replace(/\/[^\/]+\.[^\/]+$/, "/"),
  1041. root_domain = /^\w+\:\/\/\/?[^\/]+/.exec(root_page)[0],
  1042. absolute_regex = /^\w+\:\/\//;
  1043. src=src.replace(/\.\//,"");
  1044. if (/^\/\/\/?/.test(src)){
  1045. src = location.protocol + src;
  1046. }
  1047. else if (!absolute_regex.test(src) && src.charAt(0) != "/"){
  1048. src = (base_path || "") + src;
  1049. }
  1050. return (absolute_regex.test(src) ? src : ((src.charAt(0) == "/" ? root_domain : root_page) + src));
  1051. }
  1052.  
  1053. getLinkByPage(url, pageNum) {
  1054. if(!url)return;
  1055. if(this.curSiteRule.pageNum){
  1056. let result=this.curSiteRule.pageNum;
  1057. let strMatch=result.match(/\{.*?}/);
  1058. if(!strMatch)return null;
  1059. let urlReg=new RegExp("("+result.replace(strMatch[0], ")\\d+(")+")","i");
  1060. let code=strMatch[0].replace(/^{/,"").replace(/}$/,"").replace(/\$p/g,pageNum);
  1061. if(code==pageNum){
  1062. result=url.replace(urlReg,"$1"+code+"$2");
  1063. }else{
  1064. try{
  1065. code=Function('"use strict";return ' + code)();
  1066. result=url.replace(urlReg,"$1"+code+"$2");
  1067. }catch(e){
  1068. debug(e);
  1069. }
  1070. }
  1071. return result==url?url.replace(/([&\/\?](p=|page[=\/_-]?))\d+/i, "$1"+pageNum).replace(/([_-])\d+\./i, "$1"+pageNum+"."):result;
  1072. }else{
  1073. return url.replace(/([&\/\?](p=|page[=\/_-]?))\d+/i, "$1"+pageNum).replace(/([_-])\d+\./i, "$1"+pageNum+".");
  1074. }
  1075. }
  1076.  
  1077. getNextLink(doc) {
  1078. let nextLink=null,page,href;
  1079. let getNextLinkByForm=(form,n)=>{
  1080. let params=[];
  1081. [].forEach.call(form.querySelectorAll("input"), input=>{
  1082. if(n && /^(p|page)$/i.test(input.name)){
  1083. params.push('p='+n);
  1084. }else{
  1085. params.push(input.name+'='+input.value);
  1086. }
  1087. });
  1088. return form.action+'?'+params.join('&');
  1089. };
  1090. if(this.curSiteRule.pageElementByJs){
  1091. this.nextLinkHref="#";
  1092. return true;
  1093. }else if(this.curSiteRule.nextLinkByJs){
  1094. try{
  1095. let targetUrl=Function("doc",'"use strict";' + this.curSiteRule.nextLinkByJs)(doc);
  1096. if(targetUrl)nextLink={href:targetUrl};
  1097. }catch(e){
  1098. debug(e);
  1099. }
  1100. }else if(this.curSiteRule.nextLinkByUrl){
  1101. let targetUrl=this.curUrl.replace(new RegExp(this.curSiteRule.nextLinkByUrl[0],"i"), this.curSiteRule.nextLinkByUrl[1]);
  1102. if(targetUrl != this.curUrl){
  1103. let reps=targetUrl.match(/{.*?}/g);
  1104. if(reps){
  1105. reps.forEach(rep=>{
  1106. let code=rep.replace("{","").replace("}","");
  1107. let result=code.match(/^(\d+)\+1$/);
  1108. if(result){
  1109. result=parseInt(result[1])+1;
  1110. }else{
  1111. try{
  1112. result=Function('"use strict";return ' + code)();
  1113. }catch(e){
  1114. debug(e);
  1115. }
  1116. }
  1117. targetUrl=targetUrl.replace(rep, result);
  1118. });
  1119. }
  1120. }
  1121. nextLink={href:targetUrl};
  1122. }else if(this.curSiteRule.nextLink){
  1123. if(this.curSiteRule.nextLink!="0" && this.curSiteRule.nextLink!=0){
  1124. nextLink=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.nextLink,doc,doc):doc.querySelector(this.curSiteRule.nextLink);
  1125. }
  1126. }else{
  1127. page=this.getPage(doc);
  1128. nextLink=page.next;
  1129. if(nextLink){
  1130. if(nextLink.tagName=="INPUT" && nextLink.parentNode.tagName=="FORM"){
  1131. let form=nextLink.parentNode;
  1132. nextLink.href=getNextLinkByForm(form);
  1133. }
  1134. if(nextLink.parentNode.style.display=="none" || nextLink.style.display=="none" || nextLink.classList.contains("noClick") || nextLink.hasAttribute("disabled")){
  1135. this.nextLinkHref=false;
  1136. return null;
  1137. }else if(doc==document){
  1138. if((!nextLink.href || /^javascript:/.test(nextLink.href)) && !isVisible(nextLink, _unsafeWindow)){
  1139. this.nextLinkHref=false;
  1140. return null;
  1141. }else{
  1142. let nextLinkCs=_unsafeWindow.getComputedStyle(nextLink);
  1143. if(nextLinkCs.cursor=="not-allowed"){
  1144. this.nextLinkHref=false;
  1145. return null;
  1146. }
  1147. this.initNext=nextLink;
  1148. }
  1149. }
  1150. let form=doc.querySelector('#search-form');
  1151. if(!nextLink.href && nextLink.hasAttribute("onclick") && form){
  1152. if(form && /^\d+$/.test(nextLink.innerText)){
  1153. href=getNextLinkByForm(form, nextLink.innerText);
  1154. }
  1155. }
  1156. }
  1157. }
  1158. if(nextLink){
  1159. let needUrl=(this.curSiteRule.action==0 || this.curSiteRule.action==1);
  1160. if(!href)href=nextLink.href;
  1161. if(href){
  1162. let _href=nextLink.getAttribute?nextLink.getAttribute("href"):"";
  1163. if(!_href || _href.charAt(0)=="#"){
  1164. href=_href;
  1165. }
  1166. }
  1167.  
  1168. if((href===""||href===null) && needUrl){
  1169. this.nextLinkHref=false;
  1170. }else if(/^(javascript:|#)/.test(href) && needUrl){
  1171. this.nextLinkHref=false;
  1172. }else{
  1173. this.nextLinkHref=(href && !/^(javascript:|#)/.test(href))?this.canonicalUri(href):"#";
  1174. if(this.nextLinkHref!="#" && (this.nextLinkHref==this.curUrl || this.nextLinkHref==this.curUrl+"#" || this.nextLinkHref==this.oldUrl || this.nextLinkHref==this.oldUrl+"#")){
  1175. this.nextLinkHref=false;
  1176. }else if(doc==document)debug(nextLink);
  1177. }
  1178. }else{
  1179. this.nextLinkHref=false;
  1180. }
  1181. this.preload();
  1182. return nextLink;
  1183. }
  1184.  
  1185. preload(){
  1186. if(!rulesData.preload)return;
  1187. if(!this.nextLinkHref || this.nextLinkHref=="#")return;
  1188. let self=this;
  1189. if(this.curSiteRule && this.curSiteRule.action==1){
  1190. if(!this.preloadIframe){
  1191. this.preloadIframe = document.createElement('iframe');
  1192. let iframe = this.preloadIframe;
  1193. iframe.name = 'pagetual-iframe';
  1194. iframe.width = '100%';
  1195. iframe.height = '0';
  1196. iframe.frameBorder = '0';
  1197. if(ruleParser.curSiteRule.sandbox!=false){
  1198. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1199. }
  1200. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1201. iframe.addEventListener('load', function (e) {
  1202. try{
  1203. let doc=iframe.contentDocument || iframe.contentWindow.document;
  1204. var body = doc.body;
  1205. if (body && body.firstChild) {
  1206. self.lazyImgAction(body.children);
  1207. }
  1208. }catch(e){
  1209. return;
  1210. }
  1211. }, false);
  1212. document.body.appendChild(iframe);
  1213. }
  1214. this.preloadIframe.src = this.nextLinkHref;
  1215. }else{
  1216. _GM_xmlhttpRequest({
  1217. url: this.nextLinkHref,
  1218. method: 'GET',
  1219. overrideMimeType: 'text/html;charset='+document.charset,
  1220. headers: {
  1221. 'Referer': location.href
  1222. },
  1223. timeout: 5000,
  1224. onload: function(res) {
  1225. var doc=null;
  1226. try {
  1227. doc=document.implementation.createHTMLDocument('');
  1228. doc.documentElement.innerHTML=res.response;
  1229. var body = doc.body;
  1230. if (body && body.firstChild) {
  1231. self.lazyImgAction(body.children);
  1232. }
  1233. if(!self.preloadDiv){
  1234. self.preloadDiv = document.createElement('div');
  1235. self.preloadDiv.id = "pagetual-preload";
  1236. self.preloadDiv.style.cssText = 'display:none!important;';
  1237. document.body.appendChild(self.preloadDiv);
  1238. self.checkedImgs={};
  1239. }
  1240. [].forEach.call(doc.images, i=>{
  1241. let iSrc=i.src;
  1242. if(iSrc && !self.checkedImgs[iSrc]){
  1243. self.checkedImgs[iSrc] = true;
  1244. let img = document.createElement('img');
  1245. img.src = iSrc;
  1246. self.preloadDiv.appendChild(img);
  1247. }
  1248. });
  1249. }
  1250. catch (e) {
  1251. return;
  1252. }
  1253. }
  1254. });
  1255. }
  1256. }
  1257.  
  1258. getInsert(refresh) {
  1259. if(refresh){
  1260. this.insert=null;
  1261. }
  1262. if(this.insert && !refresh){
  1263. let parent=this.insert;
  1264. while(parent && parent.nodeName!="BODY"){
  1265. parent=parent.parentNode;
  1266. }
  1267. if(parent && parent.nodeName=="BODY"){
  1268. return this.insert;
  1269. }
  1270. }
  1271. if(this.curSiteRule.insert){
  1272. this.insert=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.insert,document):document.querySelector(this.curSiteRule.insert);
  1273. }else{
  1274. let pageElement=this.getPageElement(document, _unsafeWindow);
  1275. if(pageElement && pageElement.length>0){
  1276. var pELast = pageElement[pageElement.length - 1];
  1277. this.insert = pELast.nextSibling ? pELast.nextSibling : pELast.parentNode.appendChild(document.createTextNode(' '));
  1278. }
  1279. }
  1280. return this.insert;
  1281. }
  1282.  
  1283. pageInit(doc,eles){
  1284. let code=this.curSiteRule.pageInit;
  1285. if(code){
  1286. try{
  1287. Function("doc","eles",'"use strict";' + code)(doc,eles);
  1288. }catch(e){
  1289. debug(e);
  1290. }
  1291. }
  1292. }
  1293.  
  1294. pageAction(doc,eles){
  1295. let code=this.curSiteRule.pageAction;
  1296. if(code){
  1297. try{
  1298. Function("doc","eles",'"use strict";' + code)(doc,eles);
  1299. }catch(e){
  1300. debug(e);
  1301. }
  1302. }
  1303. this.lazyImgAction(eles);
  1304. this.openInNewTab(eles);
  1305. }
  1306.  
  1307. openInNewTab(eles){
  1308. if(rulesData.openInNewTab){
  1309. [].forEach.call(eles, ele=>{
  1310. if(ele.tagName=="A" && ele.href && !/^(mailto:|javascript:|#)/.test(ele.href)){
  1311. ele.setAttribute('target', '_blank');
  1312. }else{
  1313. [].forEach.call(ele.querySelectorAll('a[href]:not([href^="mailto:"]):not([href^="javascript:"]):not([href^="#"])'), a=>{
  1314. a.setAttribute('target', '_blank');
  1315. if (a.getAttribute('onclick') == 'atarget(this)') {
  1316. a.removeAttribute('onclick');
  1317. }
  1318. });
  1319. }
  1320. });
  1321. }
  1322. }
  1323.  
  1324. lazyImgAction(eles){
  1325. let setLazyImg=img=>{
  1326. let realSrc;
  1327. if(img.getAttribute("_src") && !img.src){
  1328. realSrc=img.getAttribute("_src");
  1329. }else if(img.dataset && img.dataset.original){
  1330. realSrc=img.dataset.original;
  1331. }else if(img.dataset && img.dataset.src){
  1332. realSrc=img.dataset.src;
  1333. }else if(img._lazyrias && img._lazyrias.srcset){
  1334. realSrc=img._lazyrias.srcset[img._lazyrias.srcset.length-1];
  1335. }else if(img.dataset && img.dataset.origFile){
  1336. realSrc=img.dataset.origFile;
  1337. }else if(img.srcset){
  1338. var srcs=img.srcset.split(/[xw],/),largeSize=0;
  1339. srcs.forEach(srci=>{
  1340. let srcInfo=srci.trim().split(" "),curSize=parseInt(srcInfo[1]);
  1341. if(srcInfo[1] && curSize>largeSize){
  1342. largeSize=curSize;
  1343. realSrc=srcInfo[0];
  1344. }
  1345. });
  1346. }
  1347. if(realSrc){
  1348. img.src=realSrc;
  1349. img.style.display="block";
  1350. }
  1351. };
  1352. [].forEach.call(eles, ele=>{
  1353. if(ele.tagName=="IMG"){
  1354. setLazyImg(ele);
  1355. }else{
  1356. [].forEach.call(ele.querySelectorAll("img"), img=>{
  1357. setLazyImg(img);
  1358. });
  1359. }
  1360. if(ele.tagName=="A" && ele.classList.contains("lazyload")){
  1361. if(ele.dataset.original){
  1362. ele.style.backgroundImage='url("'+ele.dataset.original+'")';
  1363. }
  1364. }else{
  1365. [].forEach.call(ele.querySelectorAll("a.lazyload"), a=>{
  1366. if(a.dataset.original){
  1367. a.style.backgroundImage='url("'+a.dataset.original+'")';
  1368. }
  1369. });
  1370. }
  1371. });
  1372. let lazyImgSrc=this.curSiteRule.lazyImgSrc;
  1373. if(lazyImgSrc){
  1374. [].forEach.call(eles, ele=>{
  1375. [].forEach.call(ele.querySelectorAll("img"), img=>{
  1376. if(img.getAttribute(lazyImgSrc)){
  1377. img.src=img.getAttribute(lazyImgSrc);
  1378. }
  1379. });
  1380. });
  1381. }
  1382. }
  1383.  
  1384. initPage(callback){
  1385. let self=this;
  1386. curPage=1;
  1387. //if(this.curSiteRule.url && !this.curSiteRule.singleUrl)return;
  1388. this.curSiteRule={};
  1389. this.pageDoc=document;
  1390. this.nextLinkHref=null;
  1391. this.curUrl=location.href;
  1392. this.getRule(()=>{
  1393. if(self.curSiteRule.enable==0){
  1394. debug("Stop as rule disable");
  1395. isPause=true;
  1396. return;
  1397. }
  1398. if(self.curSiteRule && !self.curSiteRule.singleUrl){
  1399. self.hpRules=self.hpRules.filter(item=>{return item&&item.url!=self.curSiteRule.url});
  1400. self.hpRules.unshift(self.curSiteRule);
  1401. if(self.hpRules.length>30){
  1402. self.hpRules.pop();
  1403. }
  1404. storage.setItem("hpRules", self.hpRules);
  1405. }
  1406. let css=self.curSiteRule.css;
  1407. if(css){
  1408. _GM_addStyle(css);
  1409. }
  1410. let autoClick=self.curSiteRule.autoClick;
  1411. if(autoClick){
  1412. let autoClickBtn;
  1413. try{
  1414. autoClickBtn=document.querySelector(autoClick);
  1415. }catch(e){
  1416. autoClickBtn=getElementByXpath(autoClick);
  1417. }
  1418. if(autoClickBtn){
  1419. emuClick(autoClickBtn);
  1420. }
  1421. }
  1422. let code=self.curSiteRule.init;
  1423. if(code){
  1424. try{
  1425. Function('doc','win','iframe','"use strict";' + code)(null,null,null);
  1426. }catch(e){
  1427. debug(e);
  1428. }
  1429. }
  1430. self.getNextLink(document);
  1431. callback();
  1432. });
  1433. }
  1434.  
  1435. insertPage(doc, eles, url, callback, tried){
  1436. this.oldUrl=this.curUrl;
  1437. let oldTitle=this.pageDoc.title;
  1438. this.pageDoc=doc;
  1439. this.curUrl=url;
  1440. let nextLink=this.getNextLink(doc);
  1441. this.nextTitle="";
  1442. if(this.curSiteRule.pageBarText){
  1443. if(this.curSiteRule.pageBarText==1){
  1444. this.nextTitle=doc.title;
  1445. }else{
  1446. try{
  1447. this.nextTitle=Function("doc",'"use strict";' + this.curSiteRule.pageBarText)(doc);
  1448. }catch(e){
  1449. debug(e);
  1450. }
  1451. }
  1452. }
  1453. if(curPage==1 && !tried && !nextLink && this.curSiteRule.singleUrl && this.curSiteRule.pageElement && this.curSiteRule.action!=0){
  1454. this.curSiteRule.action=1;
  1455. this.curUrl=location.href;
  1456. return false;
  1457. }
  1458. if(callback)callback(eles);
  1459. this.getInsert();
  1460. var self=this,newEles=[];
  1461. if(!eles || eles.length==0 || !self.insert || !self.insert.parentNode){
  1462. }else{
  1463. this.pageInit(doc, eles);
  1464. [].forEach.call(eles, ele=>{
  1465. let newEle=ele.cloneNode(true);
  1466. let oldCanvass=ele.querySelectorAll("canvas");
  1467. let newCanvass=newEle.querySelectorAll("canvas");
  1468. for(let i=0;i<oldCanvass.length;i++){
  1469. let oldCanvas=oldCanvass[i];
  1470. let newCanvas=newCanvass[i];
  1471. newCanvas.getContext('2d').drawImage(oldCanvas, 0, 0);
  1472. }
  1473. if(self.curSiteRule.insertPos==2){
  1474. self.insert.appendChild(newEle);
  1475. }else{
  1476. self.insert.parentNode.insertBefore(newEle, self.insert);
  1477. }
  1478. newEles.push(newEle);
  1479. });
  1480. }
  1481. this.pageAction(doc, newEles);
  1482. if(this.oldUrl!=location.href){
  1483. let isJs=/^(javascript|#)/.test(this.oldUrl.replace(location.href,""));
  1484. if(rulesData.enableHistory && !isJs){
  1485. _unsafeWindow.history.replaceState(undefined, oldTitle, this.oldUrl);
  1486. document.title=oldTitle;
  1487. }
  1488. }
  1489. return true;
  1490. }
  1491. }
  1492. var ruleParser = new RuleParser();
  1493.  
  1494. function initConfig(){
  1495. initView();
  1496. _GM_registerMenuCommand(i18n(forceState==1?"enable":"disableSite"), ()=>{
  1497. storage.setItem("forceState_"+location.host, (forceState==1?0:1));
  1498. location.reload();
  1499. });
  1500. _GM_registerMenuCommand(i18n("update"), ()=>{
  1501. updateRules(()=>{
  1502. showTips(i18n("updateSucc"));
  1503. location.reload();
  1504. },(rule,err)=>{
  1505. showTips("Update "+rule.url+" rules fail!");
  1506. });
  1507. showTips(i18n("beginUpdate"));
  1508. });
  1509.  
  1510. var configCon,insertPos;
  1511. if(ruleImportUrlReg.test(location.href)){
  1512. document.addEventListener("click", e=>{
  1513. if(e.target.tagName=="PRE"){
  1514. let nameAttr=e.target.getAttribute("name");
  1515. if(nameAttr=="pagetual" || nameAttr=="user-content-pagetual" || location.href.indexOf("greasyfork.org") != -1){
  1516. let rules=e.target.innerText.trim();
  1517. let isContent=/['"]name['"]/i.test(rules);
  1518. if(isContent){
  1519. let ruleList=JSON.parse(`[${rules}]`);
  1520. for(let i in ruleList){
  1521. let hasRule = false;
  1522. let r = ruleList[i];
  1523. for(let j in ruleParser.customRules){
  1524. if(ruleParser.customRules[j].name == r.name){
  1525. ruleParser.customRules[j] = r;
  1526. hasRule = true;
  1527. break;
  1528. }
  1529. }
  1530. if(!hasRule)ruleParser.customRules.push(r);
  1531. }
  1532. storage.setItem("customRules", ruleParser.customRules);
  1533. showTips(i18n("importSucc"));
  1534. }else{
  1535. rules=rules.split("\n");
  1536. let diff=false;
  1537. for(let c=0;c<rules.length;c++){
  1538. let urlArr=rules[c].split("|"),url,type=1;
  1539. if(urlArr.length==1){
  1540. url=urlArr[0].trim();
  1541. if(!/^http/.test(url)){
  1542. showTips("Wrong url, check again!");
  1543. return;
  1544. }
  1545. }else if(urlArr.length==2){
  1546. type=urlArr[0].trim();
  1547. url=urlArr[1].trim();
  1548. if(!/^http/.test(url)){
  1549. showTips("Wrong url, check again!");
  1550. return;
  1551. }
  1552. }else{
  1553. break;
  1554. }
  1555. let maxId=0,hasUrl=false;
  1556. if(!rulesData.urls){
  1557. rulesData.urls=[];
  1558. maxId=1;
  1559. }else{
  1560. rulesData.urls.forEach(u=>{
  1561. if(maxId<u.id){
  1562. maxId=u.id;
  1563. }
  1564. if(u.url==url){
  1565. hasUrl=true;
  1566. }
  1567. });
  1568. if(hasUrl)break;
  1569. }
  1570. diff=true;
  1571. if(!rulesData.sort)rulesData.sort=[1];
  1572. rulesData.urls.push({id:maxId+1,url:url,type:type});
  1573. rulesData.sort.unshift(maxId+1);
  1574. }
  1575. if(!diff)return;
  1576. storage.setItem("rulesData", rulesData);
  1577.  
  1578. if(rulesData.urls)ruleUrls=ruleUrls.concat(rulesData.urls);
  1579. if(rulesData.sort){
  1580. let urls=[];
  1581. rulesData.sort.forEach(id=>{
  1582. for(let s=0;s<ruleUrls.length;s++){
  1583. if(id==ruleUrls[s].id){
  1584. urls.push(ruleUrls[s]);
  1585. break;
  1586. }
  1587. }
  1588. });
  1589. ruleUrls=urls;
  1590. }
  1591. updateRules(()=>{
  1592. showTips(i18n("updateSucc"));
  1593. },(rule,err)=>{
  1594. showTips("Update "+rule.url+" rules fail!");
  1595. });
  1596. showTips(i18n("beginUpdate"));
  1597. }
  1598. }
  1599. }
  1600. });
  1601. }
  1602. if(location.href==configPage){
  1603. _GM_addStyle(`
  1604. p>span:nth-child(1),p>span:nth-child(2),p>span:nth-child(3){
  1605. cursor: pointer;
  1606. user-select: none;
  1607. }
  1608. p>span:nth-child(1):hover,p>span:nth-child(2):hover,p>span:nth-child(3):hover{
  1609. color:red;
  1610. }
  1611. .updateDate{
  1612. cursor: pointer;
  1613. user-select: none;
  1614. }
  1615. .updateDate:hover{
  1616. color:red;
  1617. }
  1618. `);
  1619. document.querySelector("[name='user-content-click2import']").innerText=i18n("click2ImportRule")
  1620. configCon=document.querySelector(".markdown-body");
  1621. insertPos=configCon.querySelector("hr");
  1622.  
  1623. if(rulesData.urls && rulesData.urls.length>0){
  1624. document.querySelector("pre[name='user-content-pagetual']").style.display="none";
  1625. document.querySelector("p[name='user-content-click2import']").style.display="none";
  1626. }
  1627. }else return false;
  1628. class Rulebar {
  1629. init(ruleUrl){
  1630. this.ruleUrl=ruleUrl;
  1631. this.item=document.createElement("p");
  1632. this.item.title=ruleUrl.type==0?"AutoPagerize Rules":"Pagetual Rules";
  1633. this.item.dataset.id=this.ruleUrl.id;
  1634. let url=document.createElement("span");
  1635. url.innerHTML=ruleUrl.url;
  1636. let up=document.createElement("span");
  1637. up.innerHTML="↑ ";
  1638. up.title=i18n("sortTitle");
  1639. let down=document.createElement("span");
  1640. down.innerHTML="↓ ";
  1641. down.title=i18n("sortTitle");
  1642. let del=document.createElement("span");
  1643. del.innerHTML="× ";
  1644. up.onclick=e=>{
  1645. this.moveUp();
  1646. };
  1647. down.onclick=e=>{
  1648. this.moveDown();
  1649. };
  1650. del.onclick=e=>{
  1651. this.del();
  1652. };
  1653. this.item.appendChild(up);
  1654. this.item.appendChild(down);
  1655. this.item.appendChild(del);
  1656. this.item.appendChild(url);
  1657. configCon.insertBefore(this.item, insertPos);
  1658. }
  1659. saveSort(){
  1660. let sort=[];
  1661. [].forEach.call(this.item.parentNode.querySelectorAll("p[data-id]"), i=>{
  1662. sort.push(i.dataset.id);
  1663. });
  1664. rulesData.sort=sort;
  1665. storage.setItem("rulesData", rulesData);
  1666. }
  1667. moveUp(){
  1668. let preE=this.item.previousElementSibling;
  1669. if(preE.tagName=="P" && preE.children.length>1){
  1670. this.item.parentNode.insertBefore(this.item,preE);
  1671. this.saveSort();
  1672. }
  1673. }
  1674. moveDown(){
  1675. let nextE=this.item.nextElementSibling;
  1676. if(nextE.tagName=="P" && nextE.children.length>1){
  1677. this.item.parentNode.insertBefore(nextE,this.item);
  1678. this.saveSort();
  1679. }
  1680. }
  1681. del(){
  1682. if(this.ruleUrl.id<2){
  1683. showTips(i18n("cantDel"));
  1684. }else if(window.confirm(i18n("confirmDel"))){
  1685. for(let u=0;u<rulesData.urls.length;u++){
  1686. if(this.ruleUrl.id==rulesData.urls[u].id){
  1687. rulesData.urls.splice(u,1);
  1688. break;
  1689. }
  1690. }
  1691. for(let u=0;u<rulesData.sort.length;u++){
  1692. if(this.ruleUrl.id==rulesData.sort[u]){
  1693. rulesData.sort.splice(u,1);
  1694. break;
  1695. }
  1696. }
  1697. storage.setItem("rulesData", rulesData);
  1698. ruleParser.rules=ruleParser.rules.filter(item=>{return item.from!=this.ruleUrl.id});
  1699. storage.setItem("rules", ruleParser.rules);
  1700. this.item.parentNode.removeChild(this.item);
  1701. //location.reload();
  1702. }
  1703. }
  1704. }
  1705. let updateP=document.createElement("p"),i=0;
  1706. let now=new Date().getTime(),inUpdate=false;
  1707.  
  1708.  
  1709. let pastDate=(new Date(updateDate)).toString(),passStr;
  1710. let passTime=(now-updateDate)/1000;
  1711. if(isNaN(passTime)){
  1712. passStr=i18n("firstUpdate");
  1713. }else if(passTime<60){
  1714. passStr=i18n("passSec", parseInt(passTime))+" ← "+i18n("click2update");
  1715. }else if(passTime<60*60){
  1716. passStr=i18n("passMin", parseInt(passTime/60))+" ← "+i18n("click2update");
  1717. }else if(passTime<60*60*24){
  1718. passStr=i18n("passHour", parseInt(passTime/3600))+" ← "+i18n("click2update");
  1719. }else{
  1720. passStr=i18n("passDay", parseInt(passTime/86400))+" ← "+i18n("click2update");
  1721. }
  1722.  
  1723.  
  1724. updateP.className="updateDate";
  1725. updateP.innerHTML=passStr;
  1726. updateP.title=i18n("update")+" - "+pastDate;
  1727. updateP.onclick=e=>{
  1728. updateRules(()=>{
  1729. showTips(i18n("updateSucc"));
  1730. updateP.innerHTML=i18n("passSec", 0);
  1731. updateP.title=i18n("update");
  1732. },(rule,err)=>{
  1733. showTips("Update "+rule.url+" rules fail!");
  1734. });
  1735. showTips(i18n("beginUpdate"));
  1736. };
  1737. configCon.insertBefore(updateP, insertPos);
  1738. if(ruleUrls){
  1739. ruleUrls.forEach(ruleUrl=>{
  1740. var rulebar=new Rulebar();
  1741. rulebar.init(ruleUrl);
  1742. });
  1743. }
  1744. let customUrlsTitle=document.createElement("h2");
  1745. customUrlsTitle.innerHTML=i18n("customUrls");
  1746. configCon.insertBefore(customUrlsTitle, insertPos);
  1747. let customUrlsInput=document.createElement("textarea");
  1748. customUrlsInput.style.width="100%";
  1749. customUrlsInput.placeholder="0 | http://wedata.net/databases/AutoPagerize/items_all.json";
  1750. configCon.insertBefore(customUrlsInput, insertPos);
  1751.  
  1752. let opacityTitle=document.createElement("h2");
  1753. opacityTitle.innerHTML=i18n("opacity");
  1754. let opacityInput=document.createElement("input");
  1755. opacityInput.value=rulesData.opacity*100;
  1756. opacityInput.type="number";
  1757. opacityInput.style.width="50px";
  1758. opacityInput.style.margin="0 0 0 10px";
  1759. opacityTitle.appendChild(opacityInput);
  1760. configCon.insertBefore(opacityTitle, insertPos);
  1761.  
  1762. let configTable=document.createElement("table");
  1763. configTable.appendChild(document.createElement("tbody"));
  1764. configCon.insertBefore(configTable, insertPos);
  1765. function createCheckbox(innerText, val){
  1766. let title=document.createElement("h3");
  1767. title.innerHTML=innerText;
  1768. let input=document.createElement("input");
  1769. input.type="checkbox";
  1770. input.style.width="50px";
  1771. input.style.height="20px";
  1772. input.checked=val;
  1773. let tr=document.createElement("tr");
  1774. let td=document.createElement("td");
  1775. td.appendChild(input);
  1776. tr.appendChild(td);
  1777. td=document.createElement("td");
  1778. td.appendChild(title);
  1779. tr.appendChild(td);
  1780. configTable.children[0].appendChild(tr);
  1781. return input;
  1782. }
  1783.  
  1784. let hideBarInput=createCheckbox(i18n("hideBar"), rulesData.hideBar);
  1785. let dbClick2StopInput=createCheckbox(i18n("dbClick2Stop"), rulesData.dbClick2Stop);
  1786. let enableWhiteListInput=createCheckbox(i18n("autoRun"), rulesData.enableWhiteList!=true);
  1787. let enableDebugInput=createCheckbox(i18n("enableDebug"), rulesData.enableDebug!=false);
  1788. let enableHistoryInput=createCheckbox(i18n("enableHistory"), rulesData.enableHistory===true);
  1789. let openInNewTabInput=createCheckbox(i18n("openInNewTab"), rulesData.openInNewTab!=false);
  1790. let initRunInput=createCheckbox(i18n("initRun"), rulesData.initRun!=false);
  1791. let preloadInput=createCheckbox(i18n("preload"), rulesData.preload!=false);
  1792.  
  1793. let customRulesTitle=document.createElement("h2");
  1794. customRulesTitle.innerHTML=i18n("customRules");
  1795. configCon.insertBefore(customRulesTitle, insertPos);
  1796. let customRulesInput=document.createElement("textarea");
  1797. configCon.insertBefore(customRulesInput, insertPos);
  1798. if(rulesData.editTemp){
  1799. if(!ruleParser.customRules){
  1800. ruleParser.customRules=[];
  1801. }
  1802. for(let i in ruleParser.customRules){
  1803. if(ruleParser.customRules[i].url==rulesData.editTemp.url){
  1804. ruleParser.customRules.splice(i, 1);
  1805. break;
  1806. }
  1807. }
  1808. ruleParser.customRules.unshift(rulesData.editTemp);
  1809. rulesData.editTemp=null;
  1810. storage.setItem("rulesData", rulesData);
  1811. customRulesInput.scrollIntoView();
  1812. }
  1813. customRulesInput.style.width="100%";
  1814. customRulesInput.style.height="500px";
  1815. 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]`;
  1816. customRulesInput.value=getFormatJSON(ruleParser.customRules);
  1817. let blacklistInput=document.createElement("textarea");
  1818. blacklistInput.style.width="100%";
  1819. blacklistInput.style.height="500px";
  1820. blacklistInput.style.display="none";
  1821. blacklistInput.placeholder="http://*.xxx.com/*/y";
  1822. blacklistInput.value=rulesData.blacklist?rulesData.blacklist.join("\n"):"";
  1823. let blacklistBtn=document.createElement("button");
  1824. blacklistBtn.innerText=i18n("editBlacklist");
  1825. blacklistBtn.style.width="100%";
  1826. blacklistBtn.onclick=e=>{
  1827. blacklistInput.style.display=blacklistInput.style.display=="none"?"":"none";
  1828. };
  1829. configCon.insertBefore(blacklistBtn, insertPos);
  1830. configCon.insertBefore(blacklistInput, insertPos);
  1831. let saveBtn=document.createElement("button");
  1832. saveBtn.innerHTML=i18n("save");
  1833. saveBtn.style.width="100%";
  1834. configCon.insertBefore(saveBtn, insertPos);
  1835. saveBtn.onclick=e=>{
  1836. try{
  1837. storage.setItem("hpRules", []);
  1838. if(customRulesInput.value==""){
  1839. storage.setItem("customRules", "");
  1840. }else{
  1841. let customRules=JSON.parse(customRulesInput.value);
  1842. if(Array && Array.isArray && !Array.isArray(customRules)){
  1843. showTips("Rules must be a Array!");
  1844. return;
  1845. }
  1846. debug(customRules);
  1847. storage.setItem("customRules", customRules);
  1848. }
  1849. }catch(e){
  1850. debug(e);
  1851. showTips("JSON error, check again!");
  1852. return;
  1853. }
  1854. rulesData.opacity=opacityInput.value/100;
  1855. rulesData.blacklist=blacklistInput.value?blacklistInput.value.split("\n"):"";
  1856. rulesData.hideBar=hideBarInput.checked;
  1857. rulesData.dbClick2Stop=dbClick2StopInput.checked;
  1858. rulesData.enableWhiteList=!enableWhiteListInput.checked;
  1859. rulesData.enableDebug=enableDebugInput.checked;
  1860. rulesData.enableHistory=enableHistoryInput.checked;
  1861. rulesData.openInNewTab=openInNewTabInput.checked;
  1862. rulesData.initRun=initRunInput.checked;
  1863. rulesData.preload=preloadInput.checked;
  1864. storage.setItem("rulesData", rulesData);
  1865. let customUrls=customUrlsInput.value.trim();
  1866. if(customUrls){
  1867. customUrls=customUrls.split(/\n/);
  1868. for(let c=0;c<customUrls.length;c++){
  1869. let urlArr=customUrls[c].split("|"),url,type=1;
  1870. if(urlArr.length==1){
  1871. url=urlArr[0].trim();
  1872. if(!/^http/.test(url)){
  1873. showTips("Wrong url, check again!");
  1874. return;
  1875. }
  1876. }else if(urlArr.length==2){
  1877. type=urlArr[0].trim();
  1878. url=urlArr[1].trim();
  1879. if(!/^http/.test(url)){
  1880. showTips("Wrong url, check again!");
  1881. return;
  1882. }
  1883. }else{
  1884. break;
  1885. }
  1886. let maxId=0,hasUrl=false;
  1887. if(!rulesData.urls){
  1888. rulesData.urls=[];
  1889. maxId=1;
  1890. }else{
  1891. rulesData.urls.forEach(u=>{
  1892. if(maxId<u.id){
  1893. maxId=u.id;
  1894. }
  1895. if(u.url==url){
  1896. hasUrl=true;
  1897. }
  1898. });
  1899. if(hasUrl)break;
  1900. }
  1901. if(!rulesData.sort)rulesData.sort=[1];
  1902. rulesData.urls.push({id:maxId+1,url:url,type:type});
  1903. rulesData.sort.push(maxId+1);
  1904. storage.setItem("rulesData", rulesData);
  1905. }
  1906. }
  1907. showTips("The settings are saved");
  1908. location.reload();
  1909. };
  1910. return true;
  1911. }
  1912.  
  1913. var inUpdate=false;
  1914. function updateRules(success,fail){
  1915. if(inUpdate)return;
  1916. inUpdate=true;
  1917. let ruleIndex=ruleUrls.length-1;
  1918. storage.setItem("hpRules", []);
  1919. function addNextRule(){
  1920. if(ruleIndex<0){
  1921. let now=new Date().getTime();
  1922. storage.setItem("ruleLastUpdate", now);
  1923. storage.setItem("rules", ruleParser.rules);
  1924. inUpdate=false;
  1925. success();
  1926. }else{
  1927. let rule=ruleUrls[ruleIndex--];
  1928. ruleParser.addRuleByUrl(rule.url, rule.type, rule.id, (json,err)=>{
  1929. if(!json){
  1930. fail(rule,err);
  1931. }
  1932. addNextRule();
  1933. })
  1934. }
  1935. }
  1936. addNextRule();
  1937. }
  1938.  
  1939. function objIsArr(obj) {
  1940. return obj &&
  1941. typeof obj === 'object' &&
  1942. typeof obj.length === 'number' &&
  1943. !(obj.propertyIsEnumerable('length'));
  1944. }
  1945.  
  1946. function isVisible(el, win) {
  1947. if(!el.offsetParent)return false;
  1948. var loopable = true,
  1949. visible = el.tagName && win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  1950. while(loopable && visible) {
  1951. el = el.parentNode;
  1952.  
  1953. if(el && el.tagName && el.tagName!="BODY") {
  1954. visible = win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  1955. }else {
  1956. loopable = false;
  1957. }
  1958. }
  1959. return visible;
  1960. }
  1961.  
  1962. function getElementTop(ele) {
  1963. var actualTop = ele.offsetTop;
  1964. var current = ele.offsetParent;
  1965. while (current) {
  1966. actualTop += current.offsetTop;
  1967. current = current.offsetParent;
  1968. }
  1969. return actualTop;
  1970. }
  1971.  
  1972. function getFormatJSON(obj){
  1973. if(!objIsArr(obj))return "";
  1974. let ret="[\n";
  1975. let len=obj.length,i=0,isLast;
  1976. obj.forEach(item=>{
  1977. ret+=" {\n";
  1978. let iLen=Object.keys(item).length,j=0;
  1979. for(let key in item){
  1980. isLast=(++j)==iLen;
  1981. let value=item[key];
  1982. if(objIsArr(value)){
  1983. let vstr="[",v=0,vIsLast=false;
  1984. value.forEach(vi=>{
  1985. vIsLast=(++v)==value.length;
  1986. vstr+="\""+vi.replace(/\\/g,"\\\\")+"\""+(vIsLast?"":",");
  1987. });
  1988. vstr+="]";
  1989. ret+=" \""+key+"\":"+vstr+""+(isLast?"":",")+"\n";
  1990. }else{
  1991. if(typeof value=="string"){
  1992. value=value.replace(/\\/g,"\\\\").replace(/"/g,"\\\"");
  1993. value="\""+value+"\"";
  1994. }
  1995. ret+=" \""+key+"\":"+value+""+(isLast?"":",")+"\n";
  1996. }
  1997. }
  1998. isLast=(++i)==len;
  1999. ret+=" }"+(isLast?"":",")+"\n";
  2000. });
  2001. ret+="]";
  2002. return ret;
  2003. }
  2004.  
  2005. function globMatch(first, second) {
  2006. if (first.length == 0 && second.length == 0){
  2007. return true;
  2008. }
  2009.  
  2010. if (first.length > 1 && first[0] == '*' &&
  2011. second.length == 0){
  2012. return false;
  2013. }
  2014.  
  2015. if ((first.length > 1 && first[0] == '?') ||
  2016. (first.length != 0 && second.length != 0 &&
  2017. first[0] == second[0])){
  2018. return globMatch(first.substring(1),
  2019. second.substring(1));
  2020. }
  2021.  
  2022. if (first.length > 0 && first[0] == '*'){
  2023. return globMatch(first.substring(1), second) ||
  2024. globMatch(first, second.substring(1));
  2025. }
  2026.  
  2027. return false;
  2028. }
  2029.  
  2030. function initRules(callback) {
  2031. /*0 wedata格式,1 pagetual格式*/
  2032. ruleUrls=[
  2033. {
  2034. id:1,
  2035. url:'http://wedata.net/databases/AutoPagerize/items_all.json',
  2036. type:0,
  2037. }
  2038. ];var i=0,j=0;
  2039.  
  2040. ruleParser.initSavedRules(()=>{
  2041. storage.getItem("rulesData", data=>{
  2042. if(data){
  2043. rulesData=data;
  2044. if(data.urls)ruleUrls=ruleUrls.concat(data.urls);
  2045. if(data.sort){
  2046. let urls=[];
  2047. data.sort.forEach(id=>{
  2048. for(let s=0;s<ruleUrls.length;s++){
  2049. if(id==ruleUrls[s].id){
  2050. urls.push(ruleUrls[s]);
  2051. break;
  2052. }
  2053. }
  2054. });
  2055. ruleUrls=urls;
  2056. }
  2057. }
  2058. if(typeof(rulesData.opacity)=="undefined"){
  2059. rulesData.opacity=0.3;
  2060. }
  2061. if(typeof(rulesData.hideBar)=="undefined"){
  2062. rulesData.hideBar=false;
  2063. }
  2064. if(typeof(rulesData.dbClick2Stop)=="undefined"){
  2065. rulesData.dbClick2Stop=true;
  2066. }
  2067. if(typeof(rulesData.enableWhiteList)=="undefined"){
  2068. rulesData.enableWhiteList=false;
  2069. }
  2070. if(typeof(rulesData.enableHistory)=="undefined"){
  2071. rulesData.enableHistory=false;
  2072. }
  2073. if(typeof(rulesData.openInNewTab)=="undefined"){
  2074. rulesData.openInNewTab=true;
  2075. }
  2076. if(typeof(rulesData.enableDebug)=="undefined"){
  2077. rulesData.enableDebug=true;
  2078. }
  2079. if(typeof(rulesData.initRun)=="undefined"){
  2080. rulesData.initRun=true;
  2081. }
  2082. if(typeof(rulesData.preload)=="undefined"){
  2083. rulesData.preload=true;
  2084. }
  2085. if(rulesData.blacklist && rulesData.blacklist.length>0){
  2086. for(let b in rulesData.blacklist){
  2087. let curGlob=rulesData.blacklist[b];
  2088. if(globMatch(curGlob, location.href)){
  2089. return;
  2090. }
  2091. }
  2092. }
  2093. enableDebug=rulesData.enableDebug;
  2094. storage.getItem("forceState_"+location.host, v=>{
  2095. storage.getItem("ruleLastUpdate", date=>{
  2096. if(typeof(v)=="undefined"){
  2097. v=(rulesData.enableWhiteList?1:0);
  2098. }
  2099. forceState=v;
  2100. updateDate=date;
  2101. if(initConfig())return;
  2102. if(forceState==1)return;
  2103. let now=new Date().getTime();
  2104. if(!date || now-date>2*24*60*60*1000){
  2105. updateRules(()=>{
  2106. },(rule,err)=>{});
  2107. }
  2108. callback();
  2109. });
  2110. });
  2111. });
  2112. });
  2113. }
  2114.  
  2115. function requestDoc(url, callback){
  2116. _GM_xmlhttpRequest({
  2117. url: url,
  2118. method: 'GET',
  2119. overrideMimeType: 'text/html;charset='+document.charset,
  2120. headers: {
  2121. 'Referer': location.href,
  2122. "Content-Type": "text/html;charset="+document.charset,
  2123. },
  2124. timeout: 5000,
  2125. onload: function(res) {
  2126. var doc=null,response=res.response;
  2127. let preCode=ruleParser.curSiteRule.pageElementPre || ruleParser.curSiteRule.pagePre;
  2128. if(preCode){
  2129. try{
  2130. response=Function("response",'"use strict";' + preCode)(response);
  2131. }catch(e){
  2132. debug(e);
  2133. }
  2134. }
  2135. try {
  2136. doc=document.implementation.createHTMLDocument('');
  2137. doc.documentElement.innerHTML=response;
  2138. }
  2139. catch (e) {
  2140. debug('parse error'+e.toString());
  2141. }
  2142. let pageElement=ruleParser.getPageElement(doc);
  2143. if(inCors && (!pageElement || pageElement.length==0)){
  2144. ruleParser.curSiteRule.pageElement=allOfBody;
  2145. pageElement=ruleParser.getPageElement(doc);
  2146. ruleParser.getInsert(true);
  2147. }
  2148. //只有1的話怕不是圖片哦
  2149. if(pageElement && (pageElement.length>1 || (pageElement.length==1 && pageElement[0].tagName!="IMG") )){
  2150. let result=ruleParser.insertPage(doc, pageElement, url, callback, false);
  2151. ruleParser.curSiteRule.action=0;
  2152. if(!result){
  2153. ruleParser.curSiteRule.action=1;
  2154. requestFromIframe(url, (doc, eles)=>{
  2155. loadPageOver();
  2156. if(eles){
  2157. ruleParser.insertPage(doc, eles, url, callback, true);
  2158. }
  2159. });
  2160. }
  2161. }else if(ruleParser.curSiteRule.singleUrl || curPage==1){
  2162. ruleParser.curSiteRule.action=1;
  2163. requestFromIframe(url, (doc, eles)=>{
  2164. loadPageOver();
  2165. if(eles){
  2166. ruleParser.insertPage(doc, eles, url, callback, true);
  2167. }
  2168. });
  2169. }else{
  2170. isPause=true;
  2171. callback(false);
  2172. }
  2173. },
  2174. onerror: function(e){
  2175. debug(e);
  2176. callback(false);
  2177. },
  2178. ontimeout: function(e){
  2179. debug(e);
  2180. callback(false);
  2181. }
  2182. });
  2183. }
  2184.  
  2185. var failFromIframe=0;
  2186. var inCors=false;
  2187. function requestFromIframe(url, callback){
  2188. let orgPage,curPage;
  2189. let iframe = document.createElement('iframe');
  2190. iframe.name = 'pagetual-iframe';
  2191. iframe.width = '100%';
  2192. iframe.height = '0';
  2193. iframe.frameBorder = '0';
  2194. if(ruleParser.curSiteRule.sandbox!=false){
  2195. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  2196. }
  2197. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  2198. let waitTime=100,checkEval;
  2199. if(ruleParser.curSiteRule.wait){
  2200. if(isNaN(ruleParser.curSiteRule.wait)){
  2201. try{
  2202. checkEval=Function("doc",'"use strict";' + ruleParser.curSiteRule.wait);
  2203. }catch(e){
  2204. debug(e);
  2205. }
  2206. }else{
  2207. waitTime=ruleParser.curSiteRule.wait;
  2208. }
  2209. }
  2210. let loadedHandler=e=>{
  2211. if(e.data != 'pagetual-iframe:DOMLoaded' && e.type != 'load')return;
  2212. window.removeEventListener('message', loadedHandler, false);
  2213. iframe.removeEventListener('load', loadedHandler, false);
  2214. let tryTimes=0;
  2215. function checkIframe(){
  2216. try{
  2217. let doc=iframe.contentDocument || iframe.contentWindow.document;
  2218. let eles=ruleParser.getPageElement(doc, iframe.contentWindow);
  2219. if(eles && eles.length>0 && (!checkEval || checkEval(doc))){
  2220. callback(doc, eles);
  2221. }else if(tryTimes++ < 10){
  2222. setTimeout(()=>{
  2223. checkIframe();
  2224. },waitTime);
  2225. return;
  2226. }else{
  2227. if(failFromIframe++ > 2){
  2228. failFromIframe=0;
  2229. debug("Stop as failFromIframe");
  2230. isPause=true;
  2231. callback(false, false);
  2232. }else{
  2233. callback(false, false);
  2234. }
  2235. }
  2236. }catch(e){
  2237. debug("Stop as cors");
  2238. inCors=true;
  2239. //isPause=true;
  2240. if(!ruleParser.curSiteRule.pageElement){
  2241. ruleParser.curSiteRule.pageElement=allOfBody;
  2242. ruleParser.getInsert(true);
  2243. }
  2244. ruleParser.curSiteRule.action=0;
  2245. ruleParser.nextLinkHref=url;
  2246. callback(false, false);
  2247. nextPage();
  2248. }
  2249. document.body.removeChild(iframe);
  2250. }
  2251. setTimeout(()=>{
  2252. checkIframe();
  2253. },waitTime);
  2254. };
  2255. window.addEventListener('message', loadedHandler, false);
  2256. iframe.addEventListener('load', loadedHandler, false);
  2257. iframe.src=url;
  2258. document.body.appendChild(iframe);
  2259. }
  2260.  
  2261. function initPage(){
  2262. ruleParser.initPage(()=>{
  2263. if(ruleParser.nextLinkHref){
  2264. let isJs=/^(javascript|#)/.test(ruleParser.nextLinkHref.replace(location.href,""));
  2265. if(!isJs){
  2266. let inForce=(forceState == 2 || forceState == 3);
  2267. _GM_registerMenuCommand(i18n(inForce?"cancelForceIframe":"forceIframe"), ()=>{
  2268. if(inForce){
  2269. storage.setItem("forceState_"+location.host, "");
  2270. }else{
  2271. let _state=confirm(i18n("forceAllBody"))?2:3;
  2272. storage.setItem("forceState_"+location.host, _state);
  2273. }
  2274. location.reload();
  2275. });
  2276. }
  2277. _GM_registerMenuCommand(i18n("loadNow"), ()=>{
  2278. let loadNum=window.prompt(i18n("loadConfirm"), "1");
  2279. if(loadNum==="" || loadNum===null)return;
  2280. autoLoadNum=Math.abs(parseInt(loadNum));
  2281. nextPage();
  2282. });
  2283. }
  2284. initListener();
  2285. if(rulesData.initRun && ruleParser.curSiteRule.initRun!=0)nextPage();
  2286. });
  2287. }
  2288.  
  2289. var pageBarStyle;
  2290. function initView(){
  2291. _GM_addStyle(`
  2292. .pagetual_pageBar.stop {
  2293. -webkit-filter: invert(100%);
  2294. filter: invert(100%);
  2295. opacity: 1!important;
  2296. }
  2297. .pagetual_pageBar.hide {
  2298. display: none!important;
  2299. }
  2300. .pagetual_pageBar:hover {
  2301. opacity: 1!important;
  2302. }
  2303. .pagetual_pageBar span {
  2304. vertical-align: super;
  2305. }
  2306.  
  2307. .pagetual_pageBar span>svg:hover {
  2308. animation: touhouAni 1s infinite;
  2309. }
  2310. .pagetual_pageBar .pagetual_pageNum{
  2311. color: #55555f;
  2312. }
  2313. .pagetual_pageBar .pagetual_pageNum:hover{
  2314. color: #ff6464;
  2315. }
  2316. .pagetual_tipsWords{
  2317. font-size: 50px;
  2318. font-weight: bold;
  2319. font-family: "黑体", -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto",
  2320. "Oxygen", "Ubuntu", "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji",
  2321. "Segoe UI Emoji", "Segoe UI Symbol";
  2322. color: #ffffff;
  2323. height: 70px;
  2324. line-height: 70px;
  2325. position: fixed;
  2326. left: 50%;
  2327. top: 10%;
  2328. margin-left: -150px;
  2329. padding: 0 10px;
  2330. z-index: 999999999;
  2331. background-color: #000;
  2332. border: 1px solid black;
  2333. border-radius: 10px;
  2334. opacity: 0;
  2335. filter: alpha(opacity=65);
  2336. box-shadow: 5px 5px 20px 0px #000;
  2337. -moz-transition:opacity 0.3s ease-in-out 0s;
  2338. -webkit-transition:opacity 0.3s ease-in-out 0s;
  2339. transition:opacity 0.3s ease-in-out 0s;
  2340. pointer-events: none;
  2341. }
  2342.  
  2343. @keyframes touhouAni{
  2344. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  2345. to {transform: rotate(360deg);}
  2346. }
  2347. @-webkit-keyframes touhouAni{
  2348. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  2349. to {transform: rotate(360deg);}
  2350. }
  2351. .pagetual_loading {
  2352. width: 50px;
  2353. height: 50px;
  2354. margin: 10px auto;
  2355. border-radius: 100%;
  2356. -webkit-animation: pagetual_loading_scaleout 1.0s infinite ease-in-out;
  2357. animation: pagetual_loading_scaleout 1.0s infinite ease-in-out;
  2358. }
  2359. @-webkit-keyframes pagetual_loading_scaleout {
  2360. 0% { -webkit-transform: scale(0.0) }
  2361. 100% {
  2362. -webkit-transform: scale(1.0);
  2363. opacity: 0;
  2364. }
  2365. }
  2366. @keyframes pagetual_loading_scaleout {
  2367. 0% {
  2368. transform: scale(0.0);
  2369. -webkit-transform: scale(0.0);
  2370. } 100% {
  2371. transform: scale(1.0);
  2372. -webkit-transform: scale(1.0);
  2373. opacity: 0;
  2374. }
  2375. }
  2376. `);
  2377. pageBarStyle=`line-height:1;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%);font-size: 30px;visibility: visible; position: initial; width: auto; height: 30px; float: none; clear: both; margin: 5px auto; text-align: center;`;
  2378. }
  2379. var loadingDiv=document.createElement("div");
  2380. 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;";
  2381. 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><div class="pagetual_loading"><svg width="50" height="50" style="position:relative;cursor: pointer;width: 50px;height: 50px;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="#6e6e6e" 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="#6e6e6e" p-id="6366"></path></svg></div>`;
  2382. var loadingCSS=`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;`;
  2383.  
  2384. var upSvg=`<svg width="30" height="30" style="display:initial;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>`;
  2385. var upSvgCSS=`display:initial;position:absolute;cursor: pointer;margin: 0 -45px;width: 30px;height: 30px;vertical-align: middle;fill: currentColor;overflow: hidden;`;
  2386. var downSvg=`<svg width="30" height="30" style="display:initial;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>`;
  2387. var downSvgCSS=`display:initial;position:absolute;cursor: pointer;margin: 0 15px;width: 30px;height: 30px;vertical-align: middle;fill: currentColor;overflow: hidden;transform: rotate(180deg);`;
  2388.  
  2389. 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;`;
  2390. 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);`;
  2391.  
  2392. var tipsWords=document.createElement("div");
  2393. tipsWords.className="pagetual_tipsWords";
  2394.  
  2395. var isPause=false,isLoading=false,curPage=1,forceState=0,bottomGap=1000,autoLoadNum=-1;
  2396.  
  2397. function changeStop(stop, hide){
  2398. isPause=stop;
  2399. [].forEach.call(document.querySelectorAll(".pagetual_pageBar"), bar=>{
  2400. if(isPause){
  2401. bar.classList.add("stop");
  2402. if(hide)bar.classList.add("hide");
  2403. }else{
  2404. bar.classList.remove("stop");
  2405. if(hide)bar.classList.remove("hide");
  2406. }
  2407. });
  2408. }
  2409.  
  2410. function isInViewPort(element) {
  2411. if(!element.parentNode)return false;
  2412. if(_unsafeWindow.getComputedStyle(element).display=="none")return false;
  2413. const viewWidth = window.innerWidth || document.documentElement.clientWidth;
  2414. const viewHeight = window.innerHeight || document.documentElement.clientHeight;
  2415. const {
  2416. top,
  2417. right,
  2418. bottom,
  2419. left,
  2420. } = element.getBoundingClientRect();
  2421.  
  2422. return (
  2423. top >= 0 &&
  2424. left >= 0 &&
  2425. right <= viewWidth + 1 &&
  2426. bottom <= viewHeight * 2
  2427. );
  2428. }
  2429.  
  2430. var urlChanged=false;
  2431. var _wr = function(type) {
  2432. var orig = history[type];
  2433. return function() {
  2434. var rv = orig.apply(this, arguments);
  2435. var e = new Event(type);
  2436. e.arguments = arguments;
  2437. window.dispatchEvent(e);
  2438. return rv;
  2439. };
  2440. };
  2441. history.pushState = _wr('pushState');
  2442. window.addEventListener('pushState', function(e) {
  2443. urlChanged=true;
  2444. isPause=true;
  2445. setTimeout(()=>{
  2446. if(location.href==configPage){
  2447. location.reload();
  2448. }
  2449. },1);
  2450. });
  2451.  
  2452. function initListener(){
  2453. let loadmoreBtn,loading=true,lastScroll=0,checkLoadMoreTimes=0;
  2454. let checkLoadMore=setInterval(()=>{
  2455. loadmoreBtn=getLoadMore(document);
  2456. if(loadmoreBtn && isVisible(loadmoreBtn, _unsafeWindow)){
  2457. loading=false;
  2458. clearInterval(checkLoadMore);
  2459. }else if(checkLoadMoreTimes>10){
  2460. clearInterval(checkLoadMore);
  2461. }
  2462. },300);
  2463. let checkScrollReach=()=>{
  2464. let scrolly=window.scrollY;
  2465. let windowHeight=window.innerHeight || document.documentElement.clientHeight;
  2466. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  2467. if(scrollH-scrolly-windowHeight<bottomGap){
  2468. nextPage();
  2469. }
  2470. };
  2471. let scrollHandler = e=>{
  2472. if(urlChanged){
  2473. ruleParser.initPage(()=>{
  2474. if(ruleParser.nextLinkHref)initView();
  2475. });
  2476. urlChanged=false;
  2477. isPause=false;
  2478. }
  2479. if(isPause)return;
  2480. if(!loading){
  2481. if(!loadmoreBtn || !loadmoreBtn.parentNode){
  2482. loadmoreBtn=getLoadMore(document);
  2483. }
  2484. if(loadmoreBtn){
  2485. if(isInViewPort(loadmoreBtn)){
  2486. emuClick(loadmoreBtn);
  2487. loading=true;
  2488. setTimeout(()=>{loading=false},200);
  2489. }
  2490. }else{
  2491. loading=true;
  2492. setTimeout(()=>{loading=false},200);
  2493. }
  2494. }
  2495. if(!isLoading){
  2496. checkScrollReach();
  2497. }
  2498. if(ruleParser.curSiteRule.lockScroll){
  2499. let curScroll=document.body.scrollTop||document.documentElement.scrollTop;
  2500. if(lastScroll!=0 && isLoading && Math.abs(lastScroll-curScroll)>100){
  2501. document.body.scrollTop=lastScroll;
  2502. document.documentElement.scrollTop=lastScroll;
  2503. }else{
  2504. lastScroll=curScroll;
  2505. }
  2506. }
  2507. };
  2508. if(!ruleParser.curSiteRule.wheel){
  2509. document.addEventListener('scroll', scrollHandler, true);
  2510. }
  2511. document.addEventListener('wheel', scrollHandler, true);
  2512. document.addEventListener('dblclick', e=>{
  2513. if(e.target.tagName!="BODY"){
  2514. let selStr=document.getSelection().toString().trim();
  2515. if(selStr){
  2516. return;
  2517. }
  2518. }
  2519. if(rulesData.dbClick2Stop && (ruleParser.nextLinkHref || loadmoreBtn)){
  2520. setTimeout(()=>{
  2521. changeStop(!isPause, rulesData.hideBar);
  2522. if(!isPause){
  2523. checkScrollReach();
  2524. }
  2525. showTips(i18n(isPause?"disable":"enable"));
  2526. },10);
  2527. }
  2528. });
  2529. }
  2530.  
  2531. function showTips(content, wordColor, backColor){
  2532. document.body.appendChild(tipsWords);
  2533. tipsWords.style.opacity=0.8;
  2534. tipsWords.innerText=content;
  2535. tipsWords.style.marginLeft=-tipsWords.offsetWidth/2+"px";
  2536. tipsWords.style.color=wordColor||0xFFFFFF;
  2537. tipsWords.style.backgroundColor=backColor||0x000;
  2538. setTimeout(()=>{tipsWords.style.opacity=0},1000);
  2539. }
  2540.  
  2541. function getLoadMore(doc){
  2542. if(ruleParser.curSiteRule.loadMore==="")return null;
  2543. let btnSel=ruleParser.curSiteRule.loadMore||".LoadMore,.load-more,.button-show-more",loadmoreBtn;
  2544. if(btnSel){
  2545. try{
  2546. loadmoreBtn=doc.querySelector(btnSel);
  2547. }catch(e){
  2548. loadmoreBtn=getElementByXpath(btnSel,doc,doc);
  2549. }
  2550. }
  2551. if(!loadmoreBtn){
  2552. let buttons=doc.querySelectorAll("input,button,a,div[onclick]"),loadmoreReg=/^\s*(加载更多|加載更多|load\s*more|もっと読み込む)\s*$/i;
  2553. for(let i=0;i<buttons.length;i++){
  2554. let button=buttons[i];
  2555. if(button && loadmoreReg.test(button.innerText)){
  2556. loadmoreBtn=button;
  2557. break;
  2558. }
  2559. }
  2560. }
  2561. if(loadmoreBtn && !ruleParser.curSiteRule.loadMore && loadmoreBtn.href && !/^(javascript|#)/.test(loadmoreBtn.href))loadmoreBtn=null;
  2562. return loadmoreBtn;
  2563. }
  2564.  
  2565. var hasPageNum=true;
  2566. function createPageBar(url){
  2567. let insert=ruleParser.getInsert();
  2568. if(!insert || !insert.parentNode)return;
  2569. curPage++;
  2570. let example=ruleParser.curSiteRule.insertPos==2?insert.children[0]:(insert.previousElementSibling||insert);
  2571. if(!example || !example.parentNode)example=insert;
  2572. let inTable=example.parentNode.tagName=="TABLE" ||
  2573. example.tagName=="TR" ||
  2574. example.tagName=="TBODY" ||
  2575. (example.previousElementSibling && example.previousElementSibling.tagName=="TR") ||
  2576. (example.previousElementSibling && example.previousElementSibling.tagName=="TBODY");
  2577. let inLi=example.tagName=="LI" || (example.previousElementSibling && example.previousElementSibling.tagName=="LI");
  2578. if(forceState==2){
  2579. inTable=inLi=false;
  2580. }
  2581. let pageBar=document.createElement(inTable?"tr":(inLi?"li":"div"));
  2582. let upSpan=document.createElement("span");
  2583. let downSpan=document.createElement("span");
  2584. let pageText=document.createElement("a");
  2585. let pageNum;
  2586. pageBar.className="pagetual_pageBar";
  2587. pageBar.id="pagetual_pageBar";
  2588. if(isPause){
  2589. pageBar.classList.add("stop");
  2590. }
  2591. pageBar.style.cssText=pageBarStyle;
  2592. pageBar.title=i18n(isPause?"enable":"disable");
  2593. upSpan.innerHTML=upSvg;
  2594. upSpan.children[0].style.cssText=upSvgCSS;
  2595. upSpan.title=i18n("toTop");
  2596. downSpan.innerHTML=downSvg;
  2597. downSpan.children[0].style.cssText=downSvgCSS;
  2598. downSpan.title=i18n("toBottom");
  2599. upSpan.style.cssText=initStyle;
  2600. downSpan.style.cssText=initStyle;
  2601. pageText.href=url;
  2602. pageText.style.cssText=pageTextStyle;
  2603. pageText.title=i18n("current");
  2604. pageBar.appendChild(upSpan);
  2605. pageBar.appendChild(pageText);
  2606. if(ruleParser.nextTitle){
  2607. pageText.innerHTML=ruleParser.nextTitle+" ";
  2608. }
  2609. if(ruleParser.curSiteRule.pageNum || (hasPageNum && /[&\/\?](p=|page[=\/_-]?)\d+|[_-]\d+\./.test(url))){
  2610. pageText.innerHTML+="Page ";
  2611. pageNum=document.createElement("span");
  2612. pageNum.innerText=curPage;
  2613. pageNum.className="pagetual_pageNum";
  2614. pageNum.title=i18n("inputPageNum");
  2615. pageNum.style.cssText=pageTextStyle;
  2616. pageNum.style.cursor="pointer";
  2617. pageNum.style.color="";
  2618. pageNum.addEventListener("click", e=>{
  2619. let pageInput=prompt(i18n("inputPageNum"), "1");
  2620. if(pageInput){
  2621. let pageLink=ruleParser.getLinkByPage(url, pageInput);
  2622. if(pageLink){
  2623. _GM_openInTab(pageLink,{active:true});
  2624. }
  2625. }
  2626. e.preventDefault();
  2627. e.stopPropagation();
  2628. });
  2629. pageBar.appendChild(pageNum);
  2630. }else{
  2631. pageText.innerHTML+="Page "+curPage;
  2632. hasPageNum=false;
  2633. }
  2634. pageBar.appendChild(downSpan);
  2635. let parentStyle=_unsafeWindow.getComputedStyle(example.parentNode);
  2636. let parentWidth=example.parentNode.scrollWidth||parseInt(parentStyle.width);
  2637. pageBar.style.width=parentWidth-parseInt(parentStyle.paddingLeft)-parseInt(parentStyle.paddingRight)-10+"px";
  2638. if(parentStyle.display=="grid" || parentStyle.display=="inline-grid"){
  2639. pageBar.style.gridColumnStart=1;
  2640. pageBar.style.gridColumnEnd=1+parseInt(example.parentNode.offsetWidth/example.offsetWidth);
  2641. }
  2642. if(inTable){
  2643. example=(example.tagName=="TR" || example.tagName=="TBODY")?example:example.previousElementSibling;
  2644. if(example.tagName=="TBODY")example=example.querySelector("tr");
  2645. if(example.previousElementSibling)example=example.previousElementSibling;
  2646. let tdNum=0;
  2647. [].forEach.call(example.children, el=>{
  2648. if(el.tagName=="TD" || el.tagName=="TH"){
  2649. tdNum+=el.colSpan||1;
  2650. }
  2651. });
  2652. pageBar.style.display="table-row";
  2653. pageBar.style.backgroundColor="unset";
  2654. pageBar.style.lineHeight="20px";
  2655. pageBar.style.boxShadow="";
  2656. let td=document.createElement("td");
  2657. td.colSpan=tdNum||1;
  2658. let inTd=document.createElement("div");
  2659. inTd.style.backgroundColor="rgb(240 240 240 / 80%)";
  2660. inTd.style.borderRadius="20px";
  2661. inTd.style.padding="0 0";
  2662. inTd.style.margin="10px";
  2663. inTd.style.lineHeight="20px";
  2664. inTd.style.textAlign="center";
  2665. inTd.style.boxShadow="rgb(0 0 0 / 67%) 0px 0px 10px 0px";
  2666. inTd.appendChild(upSpan);
  2667. inTd.appendChild(pageText);
  2668. if(pageNum)inTd.appendChild(pageNum);
  2669. inTd.appendChild(downSpan);
  2670. td.appendChild(inTd);
  2671. pageBar.appendChild(td);
  2672. }else if(inLi){
  2673. example=example.tagName=="LI"?example:example.previousElementSibling;
  2674. pageBar.style.display="table-row";
  2675. pageBar.style.backgroundColor="unset";
  2676. pageBar.style.lineHeight="20px";
  2677. pageBar.style.boxShadow="";
  2678. let td=document.createElement("td");
  2679. td.colSpan=example.children.length;
  2680. let inTd=document.createElement("div");
  2681. inTd.style.backgroundColor="rgb(240 240 240 / 80%)";
  2682. inTd.style.borderRadius="20px";
  2683. inTd.style.margin="10px"
  2684. inTd.style.padding="0 0";
  2685. inTd.style.textAlign="center";
  2686. inTd.style.minWidth="150px";
  2687. inTd.appendChild(upSpan);
  2688. inTd.appendChild(pageText);
  2689. inTd.style.width=parseInt(pageBar.style.width)-20+"px";
  2690. inTd.style.boxShadow="rgb(0 0 0 / 67%) 0px 0px 10px 0px";
  2691. if(pageNum)inTd.appendChild(pageNum);
  2692. inTd.appendChild(downSpan);
  2693. td.appendChild(inTd);
  2694. pageBar.appendChild(td);
  2695. }
  2696.  
  2697. upSpan.addEventListener("click", e=>{
  2698. document.body.scrollTop=0;
  2699. document.documentElement.scrollTop=0;
  2700. e.preventDefault();
  2701. e.stopPropagation();
  2702. });
  2703. downSpan.addEventListener("click", e=>{
  2704. changeStop(true);
  2705. pageBar.title=i18n(isPause?"enable":"disable");
  2706. document.body.scrollTop=9999999;
  2707. document.documentElement.scrollTop=9999999;
  2708. e.preventDefault();
  2709. e.stopPropagation();
  2710. });
  2711. pageBar.addEventListener("click", e=>{
  2712. changeStop(!isPause);
  2713. pageBar.title=i18n(isPause?"enable":"disable");
  2714. });
  2715. pageText.addEventListener("click", e=>{
  2716. e.stopPropagation();
  2717. });
  2718. if(ruleParser.curSiteRule.insertPos==2){
  2719. insert.appendChild(pageBar);
  2720. }else{
  2721. insert.parentNode.insertBefore(pageBar, insert);
  2722. }
  2723. if(ruleParser.curSiteRule.pageBar){
  2724. try{
  2725. Function("pageBar",'"use strict";' + ruleParser.curSiteRule.pageBar)(pageBar);
  2726. }catch(e){
  2727. debug(e);
  2728. }
  2729. }
  2730.  
  2731. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  2732. let posEle=pageBar.nextElementSibling||pageBar;
  2733. while(posEle && !posEle.offsetParent){
  2734. posEle=posEle.previousElementSibling||posEle.parentNode;
  2735. }
  2736. if(posEle){
  2737. let actualTop = getElementTop(posEle);
  2738. bottomGap=scrollH-actualTop+(window.innerHeight||document.documentElement.clientHeight)*(ruleParser.curSiteRule.rate||1);
  2739. if(bottomGap<100)bottomGap=100;
  2740. }else{
  2741. bottomGap=1000;
  2742. }
  2743. if(rulesData.opacity==0)pageBar.style.display="none";
  2744. return pageBar;
  2745. }
  2746.  
  2747. function emuClick(btn){
  2748. if(!PointerEvent)return btn.click();
  2749. let eventParam={
  2750. isTrusted: true,
  2751. altKey: false,
  2752. azimuthAngle: 0,
  2753. bubbles: true,
  2754. button: 0,
  2755. buttons: 0,
  2756. clientX: 1,
  2757. clientY: 1,
  2758. cancelBubble: false,
  2759. cancelable: true,
  2760. composed: true,
  2761. ctrlKey: false,
  2762. defaultPrevented: false,
  2763. detail: 1,
  2764. eventPhase: 2,
  2765. fromElement: null,
  2766. height: 1,
  2767. isPrimary: false,
  2768. metaKey: false,
  2769. pointerId: 1,
  2770. pointerType: "mouse",
  2771. pressure: 0,
  2772. relatedTarget: null,
  2773. returnValue: true,
  2774. shiftKey: false,
  2775. toElement: null,
  2776. twist: 0,
  2777. which: 1
  2778. };
  2779. var mouseEvent = new PointerEvent("mousedown",eventParam);
  2780. btn.dispatchEvent(mouseEvent);
  2781. mouseEvent = new PointerEvent("mouseup",eventParam);
  2782. btn.dispatchEvent(mouseEvent);
  2783. mouseEvent = new PointerEvent("click",eventParam);
  2784. btn.dispatchEvent(mouseEvent);
  2785. btn.click();
  2786. }
  2787.  
  2788. var emuIframe;
  2789. function emuPage(callback){
  2790. let orgPage=null,curPage,iframeDoc,times=0,loadmoreBtn,loadmoreEnd=false,waitTimes=10;
  2791. function checkPage(){
  2792. if(isPause)return;
  2793. try{
  2794. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  2795. }catch(e){
  2796. debug("Stop as cors");
  2797. isPause=true;
  2798. callback(false, false);
  2799. return;
  2800. }
  2801.  
  2802. let nextLink=ruleParser.getNextLink(iframeDoc);
  2803. let waitTime=500,checkEval;
  2804. if(ruleParser.curSiteRule.wait){
  2805. if(isNaN(ruleParser.curSiteRule.wait)){
  2806. try{
  2807. checkEval=Function("doc",'"use strict";' + ruleParser.curSiteRule.wait);
  2808. }catch(e){
  2809. debug(e);
  2810. }
  2811. }else{
  2812. waitTime=ruleParser.curSiteRule.wait;
  2813. }
  2814. }
  2815.  
  2816. if(!orgPage){
  2817. if(!loadmoreEnd){
  2818. loadmoreBtn=getLoadMore(iframeDoc);
  2819. if(loadmoreBtn && isVisible(loadmoreBtn, iframeDoc.defaultView)){
  2820. emuClick(loadmoreBtn);
  2821. let intv=setInterval(()=>{
  2822. loadmoreBtn=getLoadMore(iframeDoc);
  2823. if(!loadmoreBtn || !loadmoreBtn.parentNode || !isVisible(loadmoreBtn, iframeDoc.defaultView)){
  2824. clearInterval(intv);
  2825. loadmoreEnd=true;
  2826. setTimeout(()=>{
  2827. checkPage();
  2828. },500);
  2829. }else{
  2830. emuClick(loadmoreBtn);
  2831. }
  2832. },200);
  2833. return;
  2834. }else{
  2835. loadmoreEnd=true;
  2836. }
  2837. }
  2838. let pageEle=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true);
  2839. if(!nextLink || !pageEle || pageEle.length==0 || (checkEval && !checkEval(iframeDoc))){
  2840. if(waitTimes-->0){
  2841. setTimeout(()=>{
  2842. checkPage();
  2843. },waitTime);
  2844. return;
  2845. }
  2846. }
  2847. orgPage=pageEle;
  2848. if(!orgPage || orgPage.length==0){
  2849. debug("Stop as no page when emu");
  2850. isPause=true;
  2851. callback(false, false);
  2852. return;
  2853. }
  2854. if(orgPage && orgPage[0].tagName=="UL")orgPage=orgPage[0].children;
  2855. if(orgPage && nextLink){
  2856. orgPage=orgPage[parseInt(orgPage.length/2)];
  2857. if(!isVisible(nextLink, iframeDoc.defaultView)){
  2858. debug("Stop as next hide when emu");
  2859. isPause=true;
  2860. callback(false, false);
  2861. }else{
  2862. emuClick(nextLink);
  2863. setTimeout(()=>{
  2864. checkPage();
  2865. },500);
  2866. }
  2867. }else{
  2868. debug("Stop as no next when emu");
  2869. isPause=true;
  2870. callback(false, false);
  2871. }
  2872. return;
  2873. }
  2874. if(times++ > 20){
  2875. debug("Stop as timeout when emu");
  2876. isPause=true;
  2877. callback(false, false);
  2878. return;
  2879. }
  2880. let eles=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true),checkItem;
  2881. if(eles && eles.length>0){
  2882. checkItem=eles;
  2883. if(eles[0].tagName=="UL"){
  2884. checkItem=eles[0].children;
  2885. }
  2886. checkItem=checkItem[parseInt(checkItem.length/2)];
  2887. }
  2888. if(!checkItem || orgPage == checkItem || (checkEval && !checkEval(iframeDoc))){
  2889. setTimeout(()=>{
  2890. checkPage();
  2891. },waitTime);
  2892. }else{
  2893. callback(iframeDoc, eles);
  2894. }
  2895. }
  2896. if(!emuIframe){
  2897. let loaded=false;
  2898. emuIframe = document.createElement('iframe');
  2899. emuIframe.name = 'pagetual-iframe';
  2900. if(ruleParser.curSiteRule.sandbox!=false){
  2901. emuIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  2902. }
  2903. emuIframe.width = '100%';
  2904. emuIframe.height = '0';
  2905. emuIframe.frameBorder = '0';
  2906. emuIframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  2907. emuIframe.addEventListener("load", e=>{
  2908. setTimeout(()=>{
  2909. try{
  2910. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  2911. }catch(e){
  2912. debug("Stop as cors");
  2913. isPause=true;
  2914. callback(false, false);
  2915. return;
  2916. }
  2917. let code=ruleParser.curSiteRule.init;
  2918. if(code){
  2919. try{
  2920. Function('doc','win','iframe','"use strict";' + code)(iframeDoc, iframeDoc.defaultView, emuIframe);
  2921. }catch(e){
  2922. debug(e);
  2923. }
  2924. }
  2925. if(loaded)return;
  2926. loaded=true;
  2927. checkPage();
  2928. },500);
  2929. });
  2930. emuIframe.src=location.href;
  2931. document.body.appendChild(emuIframe);
  2932. }else{
  2933. checkPage();
  2934. }
  2935. }
  2936.  
  2937. function forceIframe(url, callback){
  2938. let curIframe = document.createElement('iframe'),iframeDoc;
  2939. let setPosition = ()=>{
  2940. if(ruleParser.curSiteRule.singleUrl){
  2941. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  2942. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  2943. }else{
  2944. let pageElement = ruleParser.getPageElement(iframeDoc,iframeDoc.defaultView);
  2945. if(pageElement){
  2946. let targetElement = pageElement[0];
  2947. if(pageElement.length > 1){
  2948. targetElement = targetElement.parentNode;
  2949. }
  2950. curIframe.style.height=targetElement.scrollHeight+"px";
  2951. curIframe.style.width=targetElement.scrollWidth+"px";
  2952. //pageElement[0].scrollIntoView();
  2953. iframeDoc.documentElement.scrollTop = 0;
  2954. iframeDoc.documentElement.scrollLeft = 0;
  2955. while(targetElement && targetElement.offsetParent){
  2956. targetElement.offsetParent.scrollTop = targetElement.offsetTop;
  2957. if(targetElement.offsetParent.scrollTop == 0){
  2958. iframeDoc.documentElement.scrollTop += targetElement.offsetTop;
  2959. }
  2960. targetElement.offsetParent.scrollLeft = targetElement.offsetLeft;
  2961. if(targetElement.offsetParent.scrollLeft == 0){
  2962. iframeDoc.documentElement.scrollLeft += targetElement.offsetLeft;
  2963. }
  2964. targetElement = targetElement.offsetParent;
  2965. }
  2966. }
  2967. }
  2968. };
  2969. curIframe.name = 'pagetual-iframe';
  2970. curIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  2971. curIframe.frameBorder = '0';
  2972. curIframe.scrolling="no";
  2973. 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;';
  2974. curIframe.addEventListener("load", e=>{
  2975. try{
  2976. iframeDoc=curIframe.contentDocument || curIframe.contentWindow.document;
  2977. }catch(e){
  2978. debug("Stop as cors");
  2979. isPause=true;
  2980. callback(false, false);
  2981. return;
  2982. }
  2983. ruleParser.insertPage(iframeDoc, [], url, null, true);
  2984. callback(curIframe, true);
  2985. let css=ruleParser.curSiteRule.css;
  2986. if(css){
  2987. let styleEle=iframeDoc.createElement("style");
  2988. styleEle.innerHTML=css;
  2989. iframeDoc.head.appendChild(styleEle);
  2990. }
  2991. setPosition();
  2992. let code=ruleParser.curSiteRule.init;
  2993. if(code){
  2994. try{
  2995. Function('doc','win','iframe','"use strict";' + code)(iframeDoc,iframeDoc.defaultView,curIframe);
  2996. }catch(e){
  2997. debug(e);
  2998. }
  2999. }
  3000. });
  3001. let inAction=false,checkTimes=0;
  3002. let forceRefresh=e=>{
  3003. if(inAction || !iframeDoc)return;
  3004. inAction=true;
  3005. let foundNext=()=>{
  3006. document.removeEventListener("scroll", forceRefresh);
  3007. setPosition();
  3008. }
  3009. setTimeout(()=>{
  3010. inAction=false;
  3011. if(!ruleParser.nextLinkHref){
  3012. checkTimes++;
  3013. ruleParser.getNextLink(iframeDoc);
  3014. if(ruleParser.nextLinkHref){
  3015. foundNext();
  3016. }else if(checkTimes>=10){
  3017. foundNext();
  3018. }
  3019. }else{
  3020. foundNext();
  3021. }
  3022. },50);
  3023. };
  3024. document.addEventListener("scroll", forceRefresh);
  3025. curIframe.src=url;
  3026. let insert=ruleParser.getInsert();
  3027. if(ruleParser.curSiteRule.singleUrl){
  3028. document.body.appendChild(curIframe);
  3029. }else if(ruleParser.curSiteRule.insertPos==2){
  3030. ruleParser.insert.appendChild(curIframe);
  3031. }else{
  3032. ruleParser.insert.parentNode.insertBefore(curIframe, ruleParser.insert);
  3033. }
  3034. return curIframe;
  3035. }
  3036.  
  3037. function loadPageOver(){
  3038. isLoading=false;
  3039. if(loadingDiv.parentNode){
  3040. loadingDiv.parentNode.removeChild(loadingDiv);
  3041. }
  3042. /*setTimeout(()=>{
  3043. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  3044. if(scrollH <= (window.innerHeight || document.documentElement.clientHeight)){
  3045. nextPage();
  3046. }
  3047. },1);*/
  3048. }
  3049.  
  3050. function nextPage(){
  3051. if(isPause || isLoading)return;
  3052. if(ruleParser.curSiteRule.delay){
  3053. try{
  3054. let checkDelay=Function('"use strict";' + ruleParser.curSiteRule.delay)();
  3055. if(!checkDelay)return;
  3056. }catch(e){
  3057. debug(e);
  3058. }
  3059. }
  3060. let nextLink=ruleParser.nextLinkHref;
  3061. if(!nextLink){
  3062. if(ruleParser.curSiteRule.pinUrl && curPage==1){
  3063. ruleParser.getNextLink(document);
  3064. nextLink=ruleParser.nextLinkHref;
  3065. if(!nextLink){
  3066. isPause=true;
  3067. setTimeout(()=>{isPause=false;},500);
  3068. return;
  3069. }
  3070. }else return;
  3071. }
  3072. let pvGallery=document.querySelector("span.pv-gallery-container");
  3073. if(pvGallery && pvGallery.style.display!="none")return;
  3074. let insert=ruleParser.getInsert();
  3075. if(insert){
  3076. let isJs=/^(javascript|#)/.test(nextLink.replace(location.href,""));
  3077. if(location.protocol=="https:" && /^http:/.test(nextLink)){
  3078. nextLink=nextLink.replace(/^http/,"https");
  3079. }
  3080. isLoading=true;
  3081. document.body.appendChild(loadingDiv);
  3082. loadingDiv.style.cssText=loadingCSS;
  3083. let sleep=ruleParser.curSiteRule.sleep||0;
  3084. setTimeout(()=>{
  3085. if(ruleParser.curSiteRule.pageElementByJs){
  3086. var over=ele=>{
  3087. loadPageOver();
  3088. if(ele){
  3089. createPageBar(nextLink);
  3090. ruleParser.insertPage(null, ele, nextLink, null, true);
  3091. if(autoLoadNum>=0){
  3092. if(autoLoadNum!=0 && --autoLoadNum==0){
  3093. autoLoadNum=-1;
  3094. }else{
  3095. nextPage();
  3096. }
  3097. }
  3098. }else{
  3099. debug("Stop as no page when get by js");
  3100. isPause=true;
  3101. }
  3102. };
  3103. try{
  3104. Function("over",'"use strict";' + ruleParser.curSiteRule.pageElementByJs)(over);
  3105. }catch(e){
  3106. debug(e);
  3107. }
  3108. }else if((forceState==3||ruleParser.curSiteRule.action==1) && !isJs){
  3109. requestFromIframe(nextLink, (doc, eles)=>{
  3110. loadPageOver();
  3111. if(eles){
  3112. createPageBar(nextLink);
  3113. ruleParser.insertPage(doc, eles, nextLink, null, true);
  3114. if(autoLoadNum>=0){
  3115. if(autoLoadNum!=0 && --autoLoadNum==0){
  3116. autoLoadNum=-1;
  3117. }else{
  3118. nextPage();
  3119. }
  3120. }
  3121. }
  3122. });
  3123. }else if((forceState==2||ruleParser.curSiteRule.action==2) && !isJs){
  3124. forceIframe(nextLink, (iframe, eles)=>{
  3125. loadPageOver();
  3126. let pageBar=createPageBar(nextLink);
  3127. if(pageBar)iframe.parentNode.insertBefore(pageBar, iframe);
  3128. if(autoLoadNum>=0){
  3129. if(autoLoadNum!=0 && --autoLoadNum==0){
  3130. autoLoadNum=-1;
  3131. }else{
  3132. nextPage();
  3133. }
  3134. }
  3135. });
  3136. }else{
  3137. if(!isJs){
  3138. requestDoc(nextLink, (eles)=>{
  3139. loadPageOver();
  3140. if(eles){
  3141. createPageBar(nextLink);
  3142. if(autoLoadNum>=0){
  3143. if(autoLoadNum!=0 && --autoLoadNum==0){
  3144. autoLoadNum=-1;
  3145. }else{
  3146. nextPage();
  3147. }
  3148. }
  3149. }
  3150. });
  3151. }else{
  3152. emuPage((doc, eles)=>{
  3153. loadPageOver();
  3154. if(eles){
  3155. createPageBar(nextLink);
  3156. ruleParser.insertPage(doc, eles, "", null, true);
  3157. if(autoLoadNum>=0){
  3158. if(autoLoadNum!=0 && --autoLoadNum==0){
  3159. autoLoadNum=-1;
  3160. }else{
  3161. nextPage();
  3162. }
  3163. }
  3164. }
  3165. });
  3166. }
  3167. }
  3168. },sleep);
  3169. }
  3170. }
  3171.  
  3172. function init(){
  3173. initRules(()=>{
  3174. initPage();
  3175. });
  3176. }
  3177. setTimeout(()=>{
  3178. init();
  3179. },100);
  3180. })();