东方永页机

自动翻页脚本 - 自动加载并拼接下一分页内容,无需规则驱动支持任意网页

目前为 2022-05-21 提交的版本,查看 最新版本

  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.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. let config={};
  128. switch (lang){
  129. case "zh-CN":
  130. case "zh-SG":
  131. config={
  132. enableDebug:"调试模式,输出信息至控制台",
  133. disable:"暂时禁用",
  134. disableSite:"在此站禁用",
  135. enable:"启用翻页",
  136. toTop:"回到顶部",
  137. toBottom:"前往页尾",
  138. current:"当前页",
  139. forceIframe:"强制拼接",
  140. cancelForceIframe:"取消强制拼接",
  141. configure:"打开配置页",
  142. firstUpdate:"点击此处初始化规则",
  143. update:"更新规则",
  144. click2update:"点击立即更新规则",
  145. loadNow:"立即翻页",
  146. loadConfirm:"要翻几页?(0为不间断)",
  147. noNext:"没有找到下一页,请新建规则",
  148. passSec:"更新于 #t# 秒前",
  149. passMin:"更新于 #t# 分钟前",
  150. passHour:"更新于 #t# 小时前",
  151. passDay:"更新于 #t# 天前",
  152. cantDel:"无法删除内置规则",
  153. confirmDel:"是否确认要删除此规则?",
  154. updateSucc:"更新成功",
  155. beginUpdate:"正在更新,请稍候",
  156. customUrls:"导入规则url,一行一条,AutoPagerize 格式规则需要以\"0|\"开头",
  157. customRules:"输入【东方永页机】格式的自定义规则",
  158. save:"保存设置",
  159. loadingText:"少女祈祷中...",
  160. opacity:"分页隔条不透明值",
  161. hideBar:"空白处双击隐藏分页隔条",
  162. dbClick2Stop:"空白处双击暂停翻页",
  163. sortTitle:"排序在下次更新规则后生效",
  164. autoRun:"自动启用,否则为白名单模式",
  165. inputPageNum:"输入页码跳转",
  166. enableHistory:"翻页后写入历史记录",
  167. initRun:"打开页面后立即尝试翻页,否则滚动至页尾再翻页",
  168. preload:"翻页前预读下一页,加速浏览",
  169. click2ImportRule:"点击下方添加特殊规则库,添加后再行更新:",
  170. forceAllBody:"是否拼接整个页面?",
  171. openInNewTab:"使拼接页面的内容在新页面打开",
  172. importSucc:"导入成功",
  173. editCurrent:"自定义此站规则",
  174. editBlacklist:"编辑黑名单网址,一行一条,支持? *通配符"
  175. };
  176. break;
  177. case "zh-TW":
  178. case "zh-HK":
  179. config={
  180. enableDebug:"調試模式,輸出信息至控制台",
  181. disable:"暫時禁用",
  182. disableSite:"在此站禁用",
  183. enable:"啟用翻頁",
  184. toTop:"回到頂部",
  185. toBottom:"前往頁尾",
  186. current:"當前頁",
  187. forceIframe:"強制拼接",
  188. cancelForceIframe:"取消强制拼接",
  189. configure:"打開配置頁",
  190. firstUpdate:"點擊此處初始化規則",
  191. update:"更新規則",
  192. click2update:"點擊立即更新規則",
  193. loadNow:"立即翻頁",
  194. loadConfirm:"要翻几頁?(0為不間斷)",
  195. noNext:"沒有找到下一頁,請新建規則",
  196. passSec:"更新于 #t# 秒前",
  197. passMin:"更新于 #t# 分鐘前",
  198. passHour:"更新于 #t# 小時前",
  199. passDay:"更新于 #t# 天前",
  200. cantDel:"無法刪除内置規則",
  201. confirmDel:"是否確認要刪除此規則?",
  202. updateSucc:"更新成功",
  203. beginUpdate:"正在更新,請稍候",
  204. customUrls:"導入規則url,一行一條,AutoPagerize 格式規則需要以\"0|\"開頭",
  205. customRules:"輸入【東方永頁機】格式的自定義規則",
  206. save:"存儲設置",
  207. loadingText:"少女祈禱中...",
  208. opacity:"分頁隔條不透明值",
  209. hideBar:"空白處雙擊隱藏分頁隔條",
  210. dbClick2Stop:"空白處雙擊暫停翻頁",
  211. sortTitle:"排序在下次更新規則後生效",
  212. autoRun:"自動啓用,否則為白名單模式",
  213. inputPageNum:"輸入頁碼跳轉",
  214. enableHistory:"翻頁后寫入歷史記錄",
  215. initRun:"打開頁面后立即嘗試翻頁,否則滾動至頁尾再翻頁",
  216. preload:"翻頁前預讀下一頁,加速瀏覽",
  217. click2ImportRule:"點擊下方添加特殊規則庫,添加後再行更新:",
  218. forceAllBody:"是否拼接整個頁面?",
  219. openInNewTab:"使拼接頁面的内容在新頁面打開",
  220. importSucc:"導入成功",
  221. editCurrent:"自定義此站規則",
  222. editBlacklist:"編輯黑名單網址,一行一條,支持? *通配符"
  223. };
  224. break;
  225. case "ja":
  226. config = {
  227. enableDebug:"デバッグモード",
  228. disable: "一時的に無効にする",
  229. disableSite:"このサイト無効",
  230. enable: "ページめくりを有効にする",
  231. toTop: "トップに戻る",
  232. toBottom: "ページの下部に移動",
  233. current: "現在のページ",
  234. forceIframe: "強制ステッチ",
  235. cancelForceIframe: "強制ステッチをキャンセル",
  236. configure: "設定ページを開く",
  237. firstUpdate:"ここをクリックしてルールを初期化します",
  238. update: "更新ルール",
  239. click2update:"今すぐルールを更新してください",
  240. loadNow:"今すぐページをめくる",
  241. loadConfirm:"数ページめくりたいですか?(0は途切れない)",
  242. noNext:"次のページが見つかりません、新しいルールを作成してください",
  243. passSec: "#t#秒前に更新",
  244. passMin: "#t#分前に更新",
  245. passHour: "#t#時間前に更新",
  246. passDay: "#t#日前に更新",
  247. cantDel: "組み込みルールを削除できません",
  248. confirmDel: "このルールを削除してもよろしいですか?",
  249. updateSucc: "更新に成功しました",
  250. beginUpdate: "更新中、お待ちください",
  251. customUrls: "インポートルールのURL、1行に1つ、AutoPagerizeフォーマットルールは\"0|\"で始まる必要があります",
  252. customRules: "【東方永頁機】の形式でカスタムルールを入力してください",
  253. save: "設定を保存",
  254. loadingText: "少女祈祷中...",
  255. opacity:"ページネーションバーの不透明値",
  256. hideBar:"空白部分をダブルクリックして、ページ区切り文字を非表示にします",
  257. dbClick2Stop:"空白部分をダブルクリックしてページめくりを一時停止します",
  258. sortTitle:"並べ替えは、次のルールの更新後に有効になります",
  259. autoRun:"自動的に有効",
  260. inputPageNum:"ジャンプするページ番号を入力",
  261. enableHistory:"ページめくり後の履歴を書く",
  262. initRun:"Webページを開いた直後にページをめくる",
  263. preload:"事前に次のページを読む",
  264. click2ImportRule:"以下をクリックして、ルールベースを追加します:",
  265. forceAllBody:"フルページ埋め込み?",
  266. openInNewTab:"スプライスされたページのコンテンツを新しいページで開きます",
  267. importSucc:"インポート完了",
  268. editCurrent:"現在のルールの編集",
  269. editBlacklist:"ブラックリストのURLを編集し、1行ずつ、サポート? *ワイルドカード"
  270. };
  271. break;
  272. default:
  273. config={
  274. enableDebug:"Enable debug output",
  275. disable:"Disable",
  276. disableSite:"Disable on the site",
  277. enable:"Enable",
  278. toTop:"To Top",
  279. toBottom:"To Bottom",
  280. current:"Current Page",
  281. forceIframe:"Force to join",
  282. cancelForceIframe:"Cancel Force join",
  283. configure:"Configure",
  284. firstUpdate:"Click here to initialize the rules",
  285. update:"Update rules",
  286. click2update:"Click to update rules from url now",
  287. loadNow:"Load next now",
  288. loadConfirm:"How much pages do you want to load? (0 means infinite)",
  289. noNext:"No next link found, please create a new rule",
  290. passSec:"Updated #t# seconds ago",
  291. passMin:"Updated #t# minutes ago",
  292. passHour:"Updated #t# hours ago",
  293. passDay:"Updated #t# days ago",
  294. cantDel:"Can't delete buildin rules",
  295. confirmDel:"Are you sure you want to delete this rule?",
  296. updateSucc:"Update succeeded",
  297. beginUpdate:"Begin update, wait a minute please",
  298. customUrls:"Import rule url, One url per line, rules on AutoPagerize format need to start with \"0|\"",
  299. customRules:"Input custom rules with [Pagetual] format",
  300. save:"Save",
  301. loadingText:"Shojo Now Loading...",
  302. opacity:"Pagination spacer opacity",
  303. hideBar:"Double-click on the blank space to hide the paging spacer",
  304. dbClick2Stop:"Double-click on the blank space to pause",
  305. sortTitle:"Sorting takes effect after the next rule update",
  306. autoRun:"Auto run (black list mode)",
  307. inputPageNum:"Enter page number to jump",
  308. enableHistory:"Write history after page turning",
  309. initRun:"Turn pages immediately after opening",
  310. preload:"Preload next page for speeding up",
  311. click2ImportRule:"Click to import base rules link, then click to update rules:",
  312. forceAllBody:"Join full body of page?",
  313. openInNewTab:"Open urls of additions in new tab",
  314. importSucc:"Import completed",
  315. editCurrent:"Edit rule for current",
  316. editBlacklist:"Edit the blacklist urls, line by line, Support ? * for wildcard"
  317. };
  318. break;
  319. }
  320. var i18n=(name, param)=>{
  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. nexts[i].style.display!=="none" &&
  909. nexts[i].parentNode.style.display!=="none"){
  910. next=nexts[i];
  911. break;
  912. }
  913. }
  914. }
  915. if(next && (!next.href || /^javascript:/.test(next.href) || next.getAttribute("href")=="#")){
  916. jsNext=next;
  917. next=null;
  918. }
  919. if(!next){
  920. next=curPage.querySelectorAll("[aria-label='Next page']");
  921. if(next && next.length==1){
  922. next=next[0];
  923. if(!next.href || /^javascript:/.test(next.href) || next.getAttribute("href")=="#"){
  924. if(!jsNext)jsNext=next;
  925. next=null;
  926. }
  927. }else{
  928. next=null;
  929. }
  930. }
  931. if(!next){
  932. next=curPage.querySelectorAll("[aria-label='Next']");
  933. if(next && next.length==1){
  934. next=next[0];
  935. if(!next.href || /^javascript:/.test(next.href) || next.getAttribute("href")=="#"){
  936. if(!jsNext)jsNext=next;
  937. next=null;
  938. }
  939. }else{
  940. next=null;
  941. }
  942. }
  943. if(next && /^[下后後][一1]?[章话話篇]/i.test(next.innerText.trim())){
  944. next2=next;
  945. next=null;
  946. }
  947. if(!next){
  948. next=curPage.querySelector("a.curr");
  949. if(next){
  950. next=next.nextSibling;
  951. }
  952. }
  953. if(!next){
  954. next=curPage.querySelector("div.wp-pagenavi>span.current+a,div.page-nav>span.current+a,div.article-paging>span+a");
  955. }
  956. if(!next){
  957. let pageDiv=curPage.querySelector("div.pages>ul");
  958. if(pageDiv){
  959. cur=pageDiv.querySelector("li>b");
  960. if(cur)next=cur.parentNode.nextElementSibling;
  961. if(next)next=next.querySelector("a");
  962. }
  963. }
  964. if(!next){
  965. cur=curPage.querySelector(".number>ul>li.active");
  966. if(cur)next=cur.nextElementSibling;
  967. if(next)next=next.querySelector("a");
  968. }
  969. if(!next){
  970. let aTags=curPage.querySelectorAll("a,button");
  971. for(i=aTags.length-1;i>=0;i--){
  972. let aTag=aTags[i];
  973. if(aTag.innerText=="§")continue;
  974. if(aTag.innerText.length>50)continue;
  975. if(aTag.style.display=="none")continue;
  976. if(next1 && next2 && next3 && next4)break;
  977. if(aTag.href && /next$/i.test(aTag.href))continue;
  978. if(!next1){
  979. if(aTag.innerText.length>15)continue;
  980. if(/^[下后後][一1]?[页頁张張]|^next([ _-]?page)?\s*[›>→»]?$|次のページ|^次へ?$/i.test(aTag.innerText.trim())){
  981. if(!aTag.href || /^javascript:/.test(aTag.href) || aTag.getAttribute("href")=="#"){
  982. if(!nextJs1)nextJs1=aTag;
  983. }else{
  984. next1=aTag;
  985. }
  986. }
  987. }
  988. if(!next2){
  989. if(aTag.innerText.length>15)continue;
  990. if(/^[下后後][一1]?[章话話篇]/i.test(aTag.innerText.trim()) || /nextpage/i.test(aTag.className)){
  991. if(!aTag.href || /^javascript:/.test(aTag.href) || aTag.getAttribute("href")=="#"){
  992. if(!nextJs2)nextJs2=aTag;
  993. }else{
  994. next2=aTag;
  995. }
  996. }
  997. }
  998. if(!next3){
  999. if(aTag.innerText.length>15)continue;
  1000. if(aTag.innerText=="&gt;" || aTag.innerText=="▶" || aTag.innerText==">" || aTag.innerText=="›" || aTag.innerText=="→" || aTag.innerText=="»"){
  1001. if(!aTag.href || /^javascript:/.test(aTag.href) || aTag.getAttribute("href")=="#"){
  1002. if(!nextJs3)nextJs3=aTag;
  1003. }else{
  1004. next3=aTag;
  1005. }
  1006. }
  1007. }
  1008. if(!aTag.href || /^javascript:/.test(aTag.href) || aTag.getAttribute("href")=="#")continue;
  1009. if(!next4 && aTag.href.length<250){
  1010. let _aHref=aTag.href.replace("?&","?").replace("#!","").replace("index.php?","?");
  1011. let _aHrefTrim=_aHref;
  1012. if(preStr)_aHrefTrim=_aHrefTrim.replace(preStr,"");
  1013. if(afterStr)_aHrefTrim=_aHrefTrim.replace(afterStr,"");
  1014. if(pageNum<999 && _aHrefTrim==pageNum+1){
  1015. next4=aTag;
  1016. }else if(this.curUrl!=aTag.href){
  1017. let _url=url.replace(/\.s?html?$/i,"");
  1018. _aHref=_aHref.replace(/\.s?html?$/i,"");
  1019. if(_aHref.indexOf(_url)!=-1 && /^[\/\?&]?[_-]?(p|page)?=?\/?2(\/|\?|&|$)/i.test(_aHref.replace(_url,""))){
  1020. let curHref=aTag.getAttribute("href");
  1021. let pageOne=curHref.replace(/\/2(\/|\?|&|$)/,"/1$1");
  1022. if(pageOne==curHref)pageOne=null;
  1023. else pageOne=curPage.querySelector(`a[href='${pageOne}']`);
  1024. if(!pageOne || pageOne.className!=curHref.className)next4=aTag;
  1025. }
  1026. }
  1027. }
  1028. }
  1029. if(next3){
  1030. let eles=getAllElementsByXpath(`//a[text()='${next3.innerText}']`,curPage,curPage);
  1031. if(eles.length>1)next3=null;
  1032. }
  1033. }
  1034. if(!next)next=next1||next4||next3||next2||jsNext||nextJs1||nextJs3||nextJs2;
  1035. if(next && next.classList.contains("results-more"))next=null;
  1036. return {next:next,canSave:canSave};
  1037. }
  1038.  
  1039. canonicalUri(src) {
  1040. if(src.charAt(0)=="#")return location.href+src;
  1041. var root_page = /^[^?#]*\//.exec(location.href)[0],
  1042. base_path = location.pathname.replace(/\/[^\/]+\.[^\/]+$/, "/"),
  1043. root_domain = /^\w+\:\/\/\/?[^\/]+/.exec(root_page)[0],
  1044. absolute_regex = /^\w+\:\/\//;
  1045. src=src.replace(/\.\//,"");
  1046. if (/^\/\/\/?/.test(src)){
  1047. src = location.protocol + src;
  1048. }
  1049. else if (!absolute_regex.test(src) && src.charAt(0) != "/"){
  1050. src = (base_path || "") + src;
  1051. }
  1052. return (absolute_regex.test(src) ? src : ((src.charAt(0) == "/" ? root_domain : root_page) + src));
  1053. }
  1054.  
  1055. getLinkByPage(url, pageNum) {
  1056. if(!url)return;
  1057. if(this.curSiteRule.pageNum){
  1058. let result=this.curSiteRule.pageNum;
  1059. let strMatch=result.match(/\{.*?}/);
  1060. if(!strMatch)return null;
  1061. let urlReg=new RegExp("("+result.replace(strMatch[0], ")\\d+(")+")","i");
  1062. let code=strMatch[0].replace(/^{/,"").replace(/}$/,"").replace(/\$p/g,pageNum);
  1063. if(code==pageNum){
  1064. result=url.replace(urlReg,"$1"+code+"$2");
  1065. }else{
  1066. try{
  1067. code=Function('"use strict";return ' + code)();
  1068. result=url.replace(urlReg,"$1"+code+"$2");
  1069. }catch(e){
  1070. debug(e);
  1071. }
  1072. }
  1073. return result==url?url.replace(/([&\/\?](p=|page[=\/_-]?))\d+/i, "$1"+pageNum).replace(/([_-])\d+\./i, "$1"+pageNum+"."):result;
  1074. }else{
  1075. return url.replace(/([&\/\?](p=|page[=\/_-]?))\d+/i, "$1"+pageNum).replace(/([_-])\d+\./i, "$1"+pageNum+".");
  1076. }
  1077. }
  1078.  
  1079. getNextLink(doc) {
  1080. let nextLink=null,page,href;
  1081. let getNextLinkByForm=(form,n)=>{
  1082. let params=[];
  1083. [].forEach.call(form.querySelectorAll("input"), input=>{
  1084. if(n && /^(p|page)$/i.test(input.name)){
  1085. params.push('p='+n);
  1086. }else{
  1087. params.push(input.name+'='+input.value);
  1088. }
  1089. });
  1090. return form.action+'?'+params.join('&');
  1091. };
  1092. if(this.curSiteRule.pageElementByJs){
  1093. this.nextLinkHref="#";
  1094. return true;
  1095. }else if(this.curSiteRule.nextLinkByJs){
  1096. try{
  1097. let targetUrl=Function("doc",'"use strict";' + this.curSiteRule.nextLinkByJs)(doc);
  1098. if(targetUrl)nextLink={href:targetUrl};
  1099. }catch(e){
  1100. debug(e);
  1101. }
  1102. }else if(this.curSiteRule.nextLinkByUrl){
  1103. let targetUrl=this.curUrl.replace(new RegExp(this.curSiteRule.nextLinkByUrl[0],"i"), this.curSiteRule.nextLinkByUrl[1]);
  1104. if(targetUrl != this.curUrl){
  1105. let reps=targetUrl.match(/{.*?}/g);
  1106. if(reps){
  1107. reps.forEach(rep=>{
  1108. let code=rep.replace("{","").replace("}","");
  1109. let result=code.match(/^(\d+)\+1$/);
  1110. if(result){
  1111. result=parseInt(result[1])+1;
  1112. }else{
  1113. try{
  1114. result=Function('"use strict";return ' + code)();
  1115. }catch(e){
  1116. debug(e);
  1117. }
  1118. }
  1119. targetUrl=targetUrl.replace(rep, result);
  1120. });
  1121. }
  1122. }
  1123. nextLink={href:targetUrl};
  1124. }else if(this.curSiteRule.nextLink){
  1125. if(this.curSiteRule.nextLink!="0" && this.curSiteRule.nextLink!=0){
  1126. nextLink=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.nextLink,doc,doc):doc.querySelector(this.curSiteRule.nextLink);
  1127. }
  1128. }else{
  1129. page=this.getPage(doc);
  1130. nextLink=page.next;
  1131. if(nextLink){
  1132. if(nextLink.tagName=="INPUT" && nextLink.parentNode.tagName=="FORM"){
  1133. let form=nextLink.parentNode;
  1134. nextLink.href=getNextLinkByForm(form);
  1135. }
  1136. if(nextLink.parentNode.style.display=="none" || nextLink.style.display=="none" || nextLink.classList.contains("noClick") || nextLink.hasAttribute("disabled")){
  1137. this.nextLinkHref=false;
  1138. return null;
  1139. }else if(doc==document){
  1140. if((!nextLink.href || /^javascript:/.test(nextLink.href)) && !isVisible(nextLink, _unsafeWindow)){
  1141. this.nextLinkHref=false;
  1142. return null;
  1143. }else{
  1144. let nextLinkCs=_unsafeWindow.getComputedStyle(nextLink);
  1145. if(nextLinkCs.cursor=="not-allowed"){
  1146. this.nextLinkHref=false;
  1147. return null;
  1148. }
  1149. this.initNext=nextLink;
  1150. }
  1151. }
  1152. let form=doc.querySelector('#search-form');
  1153. if(!nextLink.href && nextLink.hasAttribute("onclick") && form){
  1154. if(form && /^\d+$/.test(nextLink.innerText)){
  1155. href=getNextLinkByForm(form, nextLink.innerText);
  1156. }
  1157. }
  1158. }
  1159. }
  1160. if(nextLink){
  1161. let needUrl=(this.curSiteRule.action==0 || this.curSiteRule.action==1);
  1162. if(!href)href=nextLink.href;
  1163. if(href){
  1164. let _href=nextLink.getAttribute?nextLink.getAttribute("href"):"";
  1165. if(!_href || _href.charAt(0)=="#"){
  1166. href=_href;
  1167. }
  1168. }
  1169.  
  1170. if((href===""||href===null) && needUrl){
  1171. this.nextLinkHref=false;
  1172. }else if(/^(javascript:|#)/.test(href) && needUrl){
  1173. this.nextLinkHref=false;
  1174. }else{
  1175. this.nextLinkHref=(href && !/^(javascript:|#)/.test(href))?this.canonicalUri(href):"#";
  1176. if(this.nextLinkHref!="#" && (this.nextLinkHref==this.curUrl || this.nextLinkHref==this.curUrl+"#" || this.nextLinkHref==this.oldUrl || this.nextLinkHref==this.oldUrl+"#")){
  1177. this.nextLinkHref=false;
  1178. }else if(doc==document)debug(nextLink);
  1179. }
  1180. }else{
  1181. this.nextLinkHref=false;
  1182. }
  1183. this.preload();
  1184. return nextLink;
  1185. }
  1186.  
  1187. preload(){
  1188. if(!rulesData.preload)return;
  1189. if(!this.nextLinkHref || this.nextLinkHref=="#")return;
  1190. let self=this;
  1191. if(this.curSiteRule && this.curSiteRule.action==1){
  1192. if(!this.preloadIframe){
  1193. this.preloadIframe = document.createElement('iframe');
  1194. let iframe = this.preloadIframe;
  1195. iframe.name = 'pagetual-iframe';
  1196. iframe.width = '100%';
  1197. iframe.height = '0';
  1198. iframe.frameBorder = '0';
  1199. if(ruleParser.curSiteRule.sandbox!=false){
  1200. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1201. }
  1202. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1203. iframe.addEventListener('load', function (e) {
  1204. try{
  1205. let doc=iframe.contentDocument || iframe.contentWindow.document;
  1206. var body = doc.body;
  1207. if (body && body.firstChild) {
  1208. self.lazyImgAction(body.children);
  1209. }
  1210. }catch(e){
  1211. return;
  1212. }
  1213. }, false);
  1214. document.body.appendChild(iframe);
  1215. }
  1216. this.preloadIframe.src = this.nextLinkHref;
  1217. }else{
  1218. _GM_xmlhttpRequest({
  1219. url: this.nextLinkHref,
  1220. method: 'GET',
  1221. overrideMimeType: 'text/html;charset='+document.charset,
  1222. headers: {
  1223. 'Referer': location.href
  1224. },
  1225. timeout: 5000,
  1226. onload: function(res) {
  1227. var doc=null;
  1228. try {
  1229. doc=document.implementation.createHTMLDocument('');
  1230. doc.documentElement.innerHTML=res.response;
  1231. var body = doc.body;
  1232. if (body && body.firstChild) {
  1233. self.lazyImgAction(body.children);
  1234. }
  1235. if(!self.preloadDiv){
  1236. self.preloadDiv = document.createElement('div');
  1237. self.preloadDiv.id = "pagetual-preload";
  1238. self.preloadDiv.style.cssText = 'display:none!important;';
  1239. document.body.appendChild(self.preloadDiv);
  1240. self.checkedImgs={};
  1241. }
  1242. [].forEach.call(doc.images, i=>{
  1243. let iSrc=i.src;
  1244. if(iSrc && !self.checkedImgs[iSrc]){
  1245. self.checkedImgs[iSrc] = true;
  1246. let img = document.createElement('img');
  1247. img.src = iSrc;
  1248. self.preloadDiv.appendChild(img);
  1249. }
  1250. });
  1251. }
  1252. catch (e) {
  1253. return;
  1254. }
  1255. }
  1256. });
  1257. }
  1258. }
  1259.  
  1260. getInsert(refresh) {
  1261. if(refresh){
  1262. this.insert=null;
  1263. }
  1264. if(this.insert && !refresh){
  1265. let parent=this.insert;
  1266. while(parent && parent.nodeName!="BODY"){
  1267. parent=parent.parentNode;
  1268. }
  1269. if(parent && parent.nodeName=="BODY"){
  1270. return this.insert;
  1271. }
  1272. }
  1273. if(this.curSiteRule.insert){
  1274. this.insert=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.insert,document):document.querySelector(this.curSiteRule.insert);
  1275. }else{
  1276. let pageElement=this.getPageElement(document, _unsafeWindow);
  1277. if(pageElement && pageElement.length>0){
  1278. var pELast = pageElement[pageElement.length - 1];
  1279. this.insert = pELast.nextSibling ? pELast.nextSibling : pELast.parentNode.appendChild(document.createTextNode(' '));
  1280. }
  1281. }
  1282. return this.insert;
  1283. }
  1284.  
  1285. pageInit(doc,eles){
  1286. let code=this.curSiteRule.pageInit;
  1287. if(code){
  1288. try{
  1289. Function("doc","eles",'"use strict";' + code)(doc,eles);
  1290. }catch(e){
  1291. debug(e);
  1292. }
  1293. }
  1294. }
  1295.  
  1296. pageAction(doc,eles){
  1297. let code=this.curSiteRule.pageAction;
  1298. if(code){
  1299. try{
  1300. Function("doc","eles",'"use strict";' + code)(doc,eles);
  1301. }catch(e){
  1302. debug(e);
  1303. }
  1304. }
  1305. this.lazyImgAction(eles);
  1306. this.openInNewTab(eles);
  1307. }
  1308.  
  1309. openInNewTab(eles){
  1310. if(rulesData.openInNewTab){
  1311. [].forEach.call(eles, ele=>{
  1312. if(ele.tagName=="A" && ele.href && !/^(mailto:|javascript:|#)/.test(ele.href)){
  1313. ele.setAttribute('target', '_blank');
  1314. }else{
  1315. [].forEach.call(ele.querySelectorAll('a[href]:not([href^="mailto:"]):not([href^="javascript:"]):not([href^="#"])'), a=>{
  1316. a.setAttribute('target', '_blank');
  1317. if (a.getAttribute('onclick') == 'atarget(this)') {
  1318. a.removeAttribute('onclick');
  1319. }
  1320. });
  1321. }
  1322. });
  1323. }
  1324. }
  1325.  
  1326. lazyImgAction(eles){
  1327. let setLazyImg=img=>{
  1328. let realSrc;
  1329. if(img.getAttribute("_src") && !img.src){
  1330. realSrc=img.getAttribute("_src");
  1331. }else if(img.dataset && img.dataset.original){
  1332. realSrc=img.dataset.original;
  1333. }else if(img.dataset && img.dataset.src){
  1334. realSrc=img.dataset.src;
  1335. }else if(img._lazyrias && img._lazyrias.srcset){
  1336. realSrc=img._lazyrias.srcset[img._lazyrias.srcset.length-1];
  1337. }else if(img.dataset && img.dataset.origFile){
  1338. realSrc=img.dataset.origFile;
  1339. }else if(img.srcset){
  1340. var srcs=img.srcset.split(/[xw],/),largeSize=0;
  1341. srcs.forEach(srci=>{
  1342. let srcInfo=srci.trim().split(" "),curSize=parseInt(srcInfo[1]);
  1343. if(srcInfo[1] && curSize>largeSize){
  1344. largeSize=curSize;
  1345. realSrc=srcInfo[0];
  1346. }
  1347. });
  1348. }
  1349. if(realSrc){
  1350. img.src=realSrc;
  1351. img.style.display="block";
  1352. }
  1353. };
  1354. [].forEach.call(eles, ele=>{
  1355. if(ele.tagName=="IMG"){
  1356. setLazyImg(ele);
  1357. }else{
  1358. [].forEach.call(ele.querySelectorAll("img"), img=>{
  1359. setLazyImg(img);
  1360. });
  1361. }
  1362. if(ele.tagName=="A" && ele.classList.contains("lazyload")){
  1363. if(ele.dataset.original){
  1364. ele.style.backgroundImage='url("'+ele.dataset.original+'")';
  1365. }
  1366. }else{
  1367. [].forEach.call(ele.querySelectorAll("a.lazyload"), a=>{
  1368. if(a.dataset.original){
  1369. a.style.backgroundImage='url("'+a.dataset.original+'")';
  1370. }
  1371. });
  1372. }
  1373. });
  1374. let lazyImgSrc=this.curSiteRule.lazyImgSrc;
  1375. if(lazyImgSrc){
  1376. [].forEach.call(eles, ele=>{
  1377. [].forEach.call(ele.querySelectorAll("img"), img=>{
  1378. if(img.getAttribute(lazyImgSrc)){
  1379. img.src=img.getAttribute(lazyImgSrc);
  1380. }
  1381. });
  1382. });
  1383. }
  1384. }
  1385.  
  1386. initPage(callback){
  1387. let self=this;
  1388. curPage=1;
  1389. //if(this.curSiteRule.url && !this.curSiteRule.singleUrl)return;
  1390. this.curSiteRule={};
  1391. this.pageDoc=document;
  1392. this.nextLinkHref=null;
  1393. this.curUrl=location.href;
  1394. this.getRule(()=>{
  1395. if(self.curSiteRule.enable==0){
  1396. debug("Stop as rule disable");
  1397. isPause=true;
  1398. return;
  1399. }
  1400. if(self.curSiteRule && !self.curSiteRule.singleUrl){
  1401. self.hpRules=self.hpRules.filter(item=>{return item&&item.url!=self.curSiteRule.url});
  1402. self.hpRules.unshift(self.curSiteRule);
  1403. if(self.hpRules.length>30){
  1404. self.hpRules.pop();
  1405. }
  1406. storage.setItem("hpRules", self.hpRules);
  1407. }
  1408. let css=self.curSiteRule.css;
  1409. if(css){
  1410. _GM_addStyle(css);
  1411. }
  1412. let autoClick=self.curSiteRule.autoClick;
  1413. if(autoClick){
  1414. let autoClickBtn;
  1415. try{
  1416. autoClickBtn=document.querySelector(autoClick);
  1417. }catch(e){
  1418. autoClickBtn=getElementByXpath(autoClick);
  1419. }
  1420. if(autoClickBtn){
  1421. emuClick(autoClickBtn);
  1422. }
  1423. }
  1424. let code=self.curSiteRule.init;
  1425. if(code){
  1426. try{
  1427. Function('doc','win','iframe','"use strict";' + code)(null,null,null);
  1428. }catch(e){
  1429. debug(e);
  1430. }
  1431. }
  1432. self.getNextLink(document);
  1433. callback();
  1434. });
  1435. }
  1436.  
  1437. insertPage(doc, eles, url, callback, tried){
  1438. this.oldUrl=this.curUrl;
  1439. let oldTitle=this.pageDoc.title;
  1440. this.pageDoc=doc;
  1441. this.curUrl=url;
  1442. let nextLink=this.getNextLink(doc);
  1443. this.nextTitle="";
  1444. if(this.curSiteRule.pageBarText){
  1445. if(this.curSiteRule.pageBarText==1){
  1446. this.nextTitle=doc.title;
  1447. }else{
  1448. try{
  1449. this.nextTitle=Function("doc",'"use strict";' + this.curSiteRule.pageBarText)(doc);
  1450. }catch(e){
  1451. debug(e);
  1452. }
  1453. }
  1454. }
  1455. if(curPage==1 && !tried && !nextLink && this.curSiteRule.singleUrl && this.curSiteRule.pageElement && this.curSiteRule.action!=0){
  1456. this.curSiteRule.action=1;
  1457. this.curUrl=location.href;
  1458. return false;
  1459. }
  1460. if(callback)callback(eles);
  1461. this.getInsert();
  1462. var self=this,newEles=[];
  1463. if(!eles || eles.length==0 || !self.insert || !self.insert.parentNode){
  1464. }else{
  1465. this.pageInit(doc, eles);
  1466. [].forEach.call(eles, ele=>{
  1467. let newEle=ele.cloneNode(true);
  1468. let oldCanvass=ele.querySelectorAll("canvas");
  1469. let newCanvass=newEle.querySelectorAll("canvas");
  1470. for(let i=0;i<oldCanvass.length;i++){
  1471. let oldCanvas=oldCanvass[i];
  1472. let newCanvas=newCanvass[i];
  1473. newCanvas.getContext('2d').drawImage(oldCanvas, 0, 0);
  1474. }
  1475. if(self.curSiteRule.insertPos==2){
  1476. self.insert.appendChild(newEle);
  1477. }else{
  1478. self.insert.parentNode.insertBefore(newEle, self.insert);
  1479. }
  1480. newEles.push(newEle);
  1481. });
  1482. }
  1483. this.pageAction(doc, newEles);
  1484. if(this.oldUrl!=location.href){
  1485. let isJs=/^(javascript|#)/.test(this.oldUrl.replace(location.href,""));
  1486. if(rulesData.enableHistory && !isJs){
  1487. _unsafeWindow.history.replaceState(undefined, oldTitle, this.oldUrl);
  1488. document.title=oldTitle;
  1489. }
  1490. }
  1491. return true;
  1492. }
  1493. }
  1494. var ruleParser = new RuleParser();
  1495.  
  1496. function initConfig(){
  1497. initView();
  1498. _GM_registerMenuCommand(i18n(forceState==1?"enable":"disableSite"), ()=>{
  1499. storage.setItem("forceState_"+location.host, (forceState==1?0:1));
  1500. location.reload();
  1501. });
  1502. _GM_registerMenuCommand(i18n("update"), ()=>{
  1503. updateRules(()=>{
  1504. showTips(i18n("updateSucc"));
  1505. location.reload();
  1506. },(rule,err)=>{
  1507. showTips("Update "+rule.url+" rules fail!");
  1508. });
  1509. showTips(i18n("beginUpdate"));
  1510. });
  1511.  
  1512. var configCon,insertPos;
  1513. if(ruleImportUrlReg.test(location.href)){
  1514. document.addEventListener("click", e=>{
  1515. if(e.target.tagName=="PRE"){
  1516. let nameAttr=e.target.getAttribute("name");
  1517. if(nameAttr=="pagetual" || nameAttr=="user-content-pagetual" || location.href.indexOf("greasyfork.org") != -1){
  1518. let rules=e.target.innerText.trim();
  1519. let isContent=/['"]name['"]/i.test(rules);
  1520. if(isContent){
  1521. let ruleList=JSON.parse(`[${rules}]`);
  1522. for(let i in ruleList){
  1523. let hasRule = false;
  1524. let r = ruleList[i];
  1525. for(let j in ruleParser.customRules){
  1526. if(ruleParser.customRules[j].name == r.name){
  1527. ruleParser.customRules[j] = r;
  1528. hasRule = true;
  1529. break;
  1530. }
  1531. }
  1532. if(!hasRule)ruleParser.customRules.push(r);
  1533. }
  1534. storage.setItem("customRules", ruleParser.customRules);
  1535. showTips(i18n("importSucc"));
  1536. }else{
  1537. rules=rules.split("\n");
  1538. let diff=false;
  1539. for(let c=0;c<rules.length;c++){
  1540. let urlArr=rules[c].split("|"),url,type=1;
  1541. if(urlArr.length==1){
  1542. url=urlArr[0].trim();
  1543. if(!/^http/.test(url)){
  1544. showTips("Wrong url, check again!");
  1545. return;
  1546. }
  1547. }else if(urlArr.length==2){
  1548. type=urlArr[0].trim();
  1549. url=urlArr[1].trim();
  1550. if(!/^http/.test(url)){
  1551. showTips("Wrong url, check again!");
  1552. return;
  1553. }
  1554. }else{
  1555. break;
  1556. }
  1557. let maxId=0,hasUrl=false;
  1558. if(!rulesData.urls){
  1559. rulesData.urls=[];
  1560. maxId=1;
  1561. }else{
  1562. rulesData.urls.forEach(u=>{
  1563. if(maxId<u.id){
  1564. maxId=u.id;
  1565. }
  1566. if(u.url==url){
  1567. hasUrl=true;
  1568. }
  1569. });
  1570. if(hasUrl)break;
  1571. }
  1572. diff=true;
  1573. if(!rulesData.sort)rulesData.sort=[1];
  1574. rulesData.urls.push({id:maxId+1,url:url,type:type});
  1575. rulesData.sort.unshift(maxId+1);
  1576. }
  1577. if(!diff)return;
  1578. storage.setItem("rulesData", rulesData);
  1579.  
  1580. if(rulesData.urls)ruleUrls=ruleUrls.concat(rulesData.urls);
  1581. if(rulesData.sort){
  1582. let urls=[];
  1583. rulesData.sort.forEach(id=>{
  1584. for(let s=0;s<ruleUrls.length;s++){
  1585. if(id==ruleUrls[s].id){
  1586. urls.push(ruleUrls[s]);
  1587. break;
  1588. }
  1589. }
  1590. });
  1591. ruleUrls=urls;
  1592. }
  1593. updateRules(()=>{
  1594. showTips(i18n("updateSucc"));
  1595. },(rule,err)=>{
  1596. showTips("Update "+rule.url+" rules fail!");
  1597. });
  1598. showTips(i18n("beginUpdate"));
  1599. }
  1600. }
  1601. }
  1602. });
  1603. }
  1604. if(location.href==configPage){
  1605. _GM_addStyle(`
  1606. p>span:nth-child(1),p>span:nth-child(2),p>span:nth-child(3){
  1607. cursor: pointer;
  1608. user-select: none;
  1609. }
  1610. p>span:nth-child(1):hover,p>span:nth-child(2):hover,p>span:nth-child(3):hover{
  1611. color:red;
  1612. }
  1613. .updateDate{
  1614. cursor: pointer;
  1615. user-select: none;
  1616. }
  1617. .updateDate:hover{
  1618. color:red;
  1619. }
  1620. `);
  1621. document.querySelector("[name='user-content-click2import']").innerText=i18n("click2ImportRule")
  1622. configCon=document.querySelector(".markdown-body");
  1623. insertPos=configCon.querySelector("hr");
  1624.  
  1625. if(rulesData.urls && rulesData.urls.length>0){
  1626. document.querySelector("pre[name='user-content-pagetual']").style.display="none";
  1627. document.querySelector("p[name='user-content-click2import']").style.display="none";
  1628. }
  1629. }else return false;
  1630. class Rulebar {
  1631. init(ruleUrl){
  1632. this.ruleUrl=ruleUrl;
  1633. this.item=document.createElement("p");
  1634. this.item.title=ruleUrl.type==0?"AutoPagerize Rules":"Pagetual Rules";
  1635. this.item.dataset.id=this.ruleUrl.id;
  1636. let url=document.createElement("span");
  1637. url.innerHTML=ruleUrl.url;
  1638. let up=document.createElement("span");
  1639. up.innerHTML="↑ ";
  1640. up.title=i18n("sortTitle");
  1641. let down=document.createElement("span");
  1642. down.innerHTML="↓ ";
  1643. down.title=i18n("sortTitle");
  1644. let del=document.createElement("span");
  1645. del.innerHTML="× ";
  1646. up.onclick=e=>{
  1647. this.moveUp();
  1648. };
  1649. down.onclick=e=>{
  1650. this.moveDown();
  1651. };
  1652. del.onclick=e=>{
  1653. this.del();
  1654. };
  1655. this.item.appendChild(up);
  1656. this.item.appendChild(down);
  1657. this.item.appendChild(del);
  1658. this.item.appendChild(url);
  1659. configCon.insertBefore(this.item, insertPos);
  1660. }
  1661. saveSort(){
  1662. let sort=[];
  1663. [].forEach.call(this.item.parentNode.querySelectorAll("p[data-id]"), i=>{
  1664. sort.push(i.dataset.id);
  1665. });
  1666. rulesData.sort=sort;
  1667. storage.setItem("rulesData", rulesData);
  1668. }
  1669. moveUp(){
  1670. let preE=this.item.previousElementSibling;
  1671. if(preE.tagName=="P" && preE.children.length>1){
  1672. this.item.parentNode.insertBefore(this.item,preE);
  1673. this.saveSort();
  1674. }
  1675. }
  1676. moveDown(){
  1677. let nextE=this.item.nextElementSibling;
  1678. if(nextE.tagName=="P" && nextE.children.length>1){
  1679. this.item.parentNode.insertBefore(nextE,this.item);
  1680. this.saveSort();
  1681. }
  1682. }
  1683. del(){
  1684. if(this.ruleUrl.id<2){
  1685. showTips(i18n("cantDel"));
  1686. }else if(window.confirm(i18n("confirmDel"))){
  1687. for(let u=0;u<rulesData.urls.length;u++){
  1688. if(this.ruleUrl.id==rulesData.urls[u].id){
  1689. rulesData.urls.splice(u,1);
  1690. break;
  1691. }
  1692. }
  1693. for(let u=0;u<rulesData.sort.length;u++){
  1694. if(this.ruleUrl.id==rulesData.sort[u]){
  1695. rulesData.sort.splice(u,1);
  1696. break;
  1697. }
  1698. }
  1699. storage.setItem("rulesData", rulesData);
  1700. ruleParser.rules=ruleParser.rules.filter(item=>{return item.from!=this.ruleUrl.id});
  1701. storage.setItem("rules", ruleParser.rules);
  1702. this.item.parentNode.removeChild(this.item);
  1703. //location.reload();
  1704. }
  1705. }
  1706. }
  1707. let updateP=document.createElement("p"),i=0;
  1708. let now=new Date().getTime(),inUpdate=false;
  1709.  
  1710.  
  1711. let pastDate=(new Date(updateDate)).toString(),passStr;
  1712. let passTime=(now-updateDate)/1000;
  1713. if(isNaN(passTime)){
  1714. passStr=i18n("firstUpdate");
  1715. }else if(passTime<60){
  1716. passStr=i18n("passSec", parseInt(passTime))+" ← "+i18n("click2update");
  1717. }else if(passTime<60*60){
  1718. passStr=i18n("passMin", parseInt(passTime/60))+" ← "+i18n("click2update");
  1719. }else if(passTime<60*60*24){
  1720. passStr=i18n("passHour", parseInt(passTime/3600))+" ← "+i18n("click2update");
  1721. }else{
  1722. passStr=i18n("passDay", parseInt(passTime/86400))+" ← "+i18n("click2update");
  1723. }
  1724.  
  1725.  
  1726. updateP.className="updateDate";
  1727. updateP.innerHTML=passStr;
  1728. updateP.title=i18n("update")+" - "+pastDate;
  1729. updateP.onclick=e=>{
  1730. updateRules(()=>{
  1731. showTips(i18n("updateSucc"));
  1732. updateP.innerHTML=i18n("passSec", 0);
  1733. updateP.title=i18n("update");
  1734. },(rule,err)=>{
  1735. showTips("Update "+rule.url+" rules fail!");
  1736. });
  1737. showTips(i18n("beginUpdate"));
  1738. };
  1739. configCon.insertBefore(updateP, insertPos);
  1740. if(ruleUrls){
  1741. ruleUrls.forEach(ruleUrl=>{
  1742. var rulebar=new Rulebar();
  1743. rulebar.init(ruleUrl);
  1744. });
  1745. }
  1746. let customUrlsTitle=document.createElement("h2");
  1747. customUrlsTitle.innerHTML=i18n("customUrls");
  1748. configCon.insertBefore(customUrlsTitle, insertPos);
  1749. let customUrlsInput=document.createElement("textarea");
  1750. customUrlsInput.style.width="100%";
  1751. customUrlsInput.placeholder="0 | http://wedata.net/databases/AutoPagerize/items_all.json";
  1752. configCon.insertBefore(customUrlsInput, insertPos);
  1753.  
  1754. let opacityTitle=document.createElement("h2");
  1755. opacityTitle.innerHTML=i18n("opacity");
  1756. let opacityInput=document.createElement("input");
  1757. opacityInput.value=rulesData.opacity*100;
  1758. opacityInput.type="number";
  1759. opacityInput.style.width="50px";
  1760. opacityInput.style.margin="0 0 0 10px";
  1761. opacityTitle.appendChild(opacityInput);
  1762. configCon.insertBefore(opacityTitle, insertPos);
  1763.  
  1764. let configTable=document.createElement("table");
  1765. configTable.appendChild(document.createElement("tbody"));
  1766. configCon.insertBefore(configTable, insertPos);
  1767. function createCheckbox(innerText, val){
  1768. let title=document.createElement("h3");
  1769. title.innerHTML=innerText;
  1770. let input=document.createElement("input");
  1771. input.type="checkbox";
  1772. input.style.width="50px";
  1773. input.style.height="20px";
  1774. input.checked=val;
  1775. let tr=document.createElement("tr");
  1776. let td=document.createElement("td");
  1777. td.appendChild(input);
  1778. tr.appendChild(td);
  1779. td=document.createElement("td");
  1780. td.appendChild(title);
  1781. tr.appendChild(td);
  1782. configTable.children[0].appendChild(tr);
  1783. return input;
  1784. }
  1785.  
  1786. let hideBarInput=createCheckbox(i18n("hideBar"), rulesData.hideBar);
  1787. let dbClick2StopInput=createCheckbox(i18n("dbClick2Stop"), rulesData.dbClick2Stop);
  1788. let enableWhiteListInput=createCheckbox(i18n("autoRun"), rulesData.enableWhiteList!=true);
  1789. let enableDebugInput=createCheckbox(i18n("enableDebug"), rulesData.enableDebug!=false);
  1790. let enableHistoryInput=createCheckbox(i18n("enableHistory"), rulesData.enableHistory===true);
  1791. let openInNewTabInput=createCheckbox(i18n("openInNewTab"), rulesData.openInNewTab!=false);
  1792. let initRunInput=createCheckbox(i18n("initRun"), rulesData.initRun!=false);
  1793. let preloadInput=createCheckbox(i18n("preload"), rulesData.preload!=false);
  1794.  
  1795. let customRulesTitle=document.createElement("h2");
  1796. customRulesTitle.innerHTML=i18n("customRules");
  1797. configCon.insertBefore(customRulesTitle, insertPos);
  1798. let customRulesInput=document.createElement("textarea");
  1799. configCon.insertBefore(customRulesInput, insertPos);
  1800. if(rulesData.editTemp){
  1801. if(!ruleParser.customRules){
  1802. ruleParser.customRules=[];
  1803. }
  1804. for(let i in ruleParser.customRules){
  1805. if(ruleParser.customRules[i].url==rulesData.editTemp.url){
  1806. ruleParser.customRules.splice(i, 1);
  1807. break;
  1808. }
  1809. }
  1810. ruleParser.customRules.unshift(rulesData.editTemp);
  1811. rulesData.editTemp=null;
  1812. storage.setItem("rulesData", rulesData);
  1813. customRulesInput.scrollIntoView();
  1814. }
  1815. customRulesInput.style.width="100%";
  1816. customRulesInput.style.height="500px";
  1817. 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]`;
  1818. customRulesInput.value=getFormatJSON(ruleParser.customRules);
  1819. let blacklistInput=document.createElement("textarea");
  1820. blacklistInput.style.width="100%";
  1821. blacklistInput.style.height="500px";
  1822. blacklistInput.style.display="none";
  1823. blacklistInput.placeholder="http://*.xxx.com/*/y";
  1824. blacklistInput.value=rulesData.blacklist?rulesData.blacklist.join("\n"):"";
  1825. let blacklistBtn=document.createElement("button");
  1826. blacklistBtn.innerText=i18n("editBlacklist");
  1827. blacklistBtn.style.width="100%";
  1828. blacklistBtn.onclick=e=>{
  1829. blacklistInput.style.display=blacklistInput.style.display=="none"?"":"none";
  1830. };
  1831. configCon.insertBefore(blacklistBtn, insertPos);
  1832. configCon.insertBefore(blacklistInput, insertPos);
  1833. let saveBtn=document.createElement("button");
  1834. saveBtn.innerHTML=i18n("save");
  1835. saveBtn.style.width="100%";
  1836. configCon.insertBefore(saveBtn, insertPos);
  1837. saveBtn.onclick=e=>{
  1838. try{
  1839. storage.setItem("hpRules", []);
  1840. if(customRulesInput.value==""){
  1841. storage.setItem("customRules", "");
  1842. }else{
  1843. let customRules=JSON.parse(customRulesInput.value);
  1844. if(Array && Array.isArray && !Array.isArray(customRules)){
  1845. showTips("Rules must be a Array!");
  1846. return;
  1847. }
  1848. debug(customRules);
  1849. storage.setItem("customRules", customRules);
  1850. }
  1851. }catch(e){
  1852. debug(e);
  1853. showTips("JSON error, check again!");
  1854. return;
  1855. }
  1856. rulesData.opacity=opacityInput.value/100;
  1857. rulesData.blacklist=blacklistInput.value?blacklistInput.value.split("\n"):"";
  1858. rulesData.hideBar=hideBarInput.checked;
  1859. rulesData.dbClick2Stop=dbClick2StopInput.checked;
  1860. rulesData.enableWhiteList=!enableWhiteListInput.checked;
  1861. rulesData.enableDebug=enableDebugInput.checked;
  1862. rulesData.enableHistory=enableHistoryInput.checked;
  1863. rulesData.openInNewTab=openInNewTabInput.checked;
  1864. rulesData.initRun=initRunInput.checked;
  1865. rulesData.preload=preloadInput.checked;
  1866. storage.setItem("rulesData", rulesData);
  1867. let customUrls=customUrlsInput.value.trim();
  1868. if(customUrls){
  1869. customUrls=customUrls.split(/\n/);
  1870. for(let c=0;c<customUrls.length;c++){
  1871. let urlArr=customUrls[c].split("|"),url,type=1;
  1872. if(urlArr.length==1){
  1873. url=urlArr[0].trim();
  1874. if(!/^http/.test(url)){
  1875. showTips("Wrong url, check again!");
  1876. return;
  1877. }
  1878. }else if(urlArr.length==2){
  1879. type=urlArr[0].trim();
  1880. url=urlArr[1].trim();
  1881. if(!/^http/.test(url)){
  1882. showTips("Wrong url, check again!");
  1883. return;
  1884. }
  1885. }else{
  1886. break;
  1887. }
  1888. let maxId=0,hasUrl=false;
  1889. if(!rulesData.urls){
  1890. rulesData.urls=[];
  1891. maxId=1;
  1892. }else{
  1893. rulesData.urls.forEach(u=>{
  1894. if(maxId<u.id){
  1895. maxId=u.id;
  1896. }
  1897. if(u.url==url){
  1898. hasUrl=true;
  1899. }
  1900. });
  1901. if(hasUrl)break;
  1902. }
  1903. if(!rulesData.sort)rulesData.sort=[1];
  1904. rulesData.urls.push({id:maxId+1,url:url,type:type});
  1905. rulesData.sort.push(maxId+1);
  1906. storage.setItem("rulesData", rulesData);
  1907. }
  1908. }
  1909. showTips("The settings are saved");
  1910. location.reload();
  1911. };
  1912. return true;
  1913. }
  1914.  
  1915. var inUpdate=false;
  1916. function updateRules(success,fail){
  1917. if(inUpdate)return;
  1918. inUpdate=true;
  1919. let ruleIndex=ruleUrls.length-1;
  1920. storage.setItem("hpRules", []);
  1921. function addNextRule(){
  1922. if(ruleIndex<0){
  1923. let now=new Date().getTime();
  1924. storage.setItem("ruleLastUpdate", now);
  1925. storage.setItem("rules", ruleParser.rules);
  1926. inUpdate=false;
  1927. success();
  1928. }else{
  1929. let rule=ruleUrls[ruleIndex--];
  1930. ruleParser.addRuleByUrl(rule.url, rule.type, rule.id, (json,err)=>{
  1931. if(!json){
  1932. fail(rule,err);
  1933. }
  1934. addNextRule();
  1935. })
  1936. }
  1937. }
  1938. addNextRule();
  1939. }
  1940.  
  1941. function objIsArr(obj) {
  1942. return obj &&
  1943. typeof obj === 'object' &&
  1944. typeof obj.length === 'number' &&
  1945. !(obj.propertyIsEnumerable('length'));
  1946. }
  1947.  
  1948. function isVisible(el, win) {
  1949. if(!el.offsetParent)return false;
  1950. var loopable = true,
  1951. visible = el.tagName && win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  1952. while(loopable && visible) {
  1953. el = el.parentNode;
  1954.  
  1955. if(el && el.tagName && el.tagName!="BODY") {
  1956. visible = win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  1957. }else {
  1958. loopable = false;
  1959. }
  1960. }
  1961. return visible;
  1962. }
  1963.  
  1964. function getElementTop(ele) {
  1965. var actualTop = ele.offsetTop;
  1966. var current = ele.offsetParent;
  1967. while (current) {
  1968. actualTop += current.offsetTop;
  1969. current = current.offsetParent;
  1970. }
  1971. return actualTop;
  1972. }
  1973.  
  1974. function getFormatJSON(obj){
  1975. if(!objIsArr(obj))return "";
  1976. let ret="[\n";
  1977. let len=obj.length,i=0,isLast;
  1978. obj.forEach(item=>{
  1979. ret+=" {\n";
  1980. let iLen=Object.keys(item).length,j=0;
  1981. for(let key in item){
  1982. isLast=(++j)==iLen;
  1983. let value=item[key];
  1984. if(objIsArr(value)){
  1985. let vstr="[",v=0,vIsLast=false;
  1986. value.forEach(vi=>{
  1987. vIsLast=(++v)==value.length;
  1988. vstr+="\""+vi.replace(/\\/g,"\\\\")+"\""+(vIsLast?"":",");
  1989. });
  1990. vstr+="]";
  1991. ret+=" \""+key+"\":"+vstr+""+(isLast?"":",")+"\n";
  1992. }else{
  1993. if(typeof value=="string"){
  1994. value=value.replace(/\\/g,"\\\\").replace(/"/g,"\\\"");
  1995. value="\""+value+"\"";
  1996. }
  1997. ret+=" \""+key+"\":"+value+""+(isLast?"":",")+"\n";
  1998. }
  1999. }
  2000. isLast=(++i)==len;
  2001. ret+=" }"+(isLast?"":",")+"\n";
  2002. });
  2003. ret+="]";
  2004. return ret;
  2005. }
  2006.  
  2007. function globMatch(first, second) {
  2008. if (first.length == 0 && second.length == 0){
  2009. return true;
  2010. }
  2011.  
  2012. if (first.length > 1 && first[0] == '*' &&
  2013. second.length == 0){
  2014. return false;
  2015. }
  2016.  
  2017. if ((first.length > 1 && first[0] == '?') ||
  2018. (first.length != 0 && second.length != 0 &&
  2019. first[0] == second[0])){
  2020. return globMatch(first.substring(1),
  2021. second.substring(1));
  2022. }
  2023.  
  2024. if (first.length > 0 && first[0] == '*'){
  2025. return globMatch(first.substring(1), second) ||
  2026. globMatch(first, second.substring(1));
  2027. }
  2028.  
  2029. return false;
  2030. }
  2031.  
  2032. function initRules(callback) {
  2033. /*0 wedata格式,1 pagetual格式*/
  2034. ruleUrls=[
  2035. {
  2036. id:1,
  2037. url:'http://wedata.net/databases/AutoPagerize/items_all.json',
  2038. type:0,
  2039. }
  2040. ];var i=0,j=0;
  2041.  
  2042. ruleParser.initSavedRules(()=>{
  2043. storage.getItem("rulesData", data=>{
  2044. if(data){
  2045. rulesData=data;
  2046. if(data.urls)ruleUrls=ruleUrls.concat(data.urls);
  2047. if(data.sort){
  2048. let urls=[];
  2049. data.sort.forEach(id=>{
  2050. for(let s=0;s<ruleUrls.length;s++){
  2051. if(id==ruleUrls[s].id){
  2052. urls.push(ruleUrls[s]);
  2053. break;
  2054. }
  2055. }
  2056. });
  2057. ruleUrls=urls;
  2058. }
  2059. }
  2060. if(typeof(rulesData.opacity)=="undefined"){
  2061. rulesData.opacity=0.3;
  2062. }
  2063. if(typeof(rulesData.hideBar)=="undefined"){
  2064. rulesData.hideBar=false;
  2065. }
  2066. if(typeof(rulesData.dbClick2Stop)=="undefined"){
  2067. rulesData.dbClick2Stop=true;
  2068. }
  2069. if(typeof(rulesData.enableWhiteList)=="undefined"){
  2070. rulesData.enableWhiteList=false;
  2071. }
  2072. if(typeof(rulesData.enableHistory)=="undefined"){
  2073. rulesData.enableHistory=false;
  2074. }
  2075. if(typeof(rulesData.openInNewTab)=="undefined"){
  2076. rulesData.openInNewTab=true;
  2077. }
  2078. if(typeof(rulesData.enableDebug)=="undefined"){
  2079. rulesData.enableDebug=true;
  2080. }
  2081. if(typeof(rulesData.initRun)=="undefined"){
  2082. rulesData.initRun=true;
  2083. }
  2084. if(typeof(rulesData.preload)=="undefined"){
  2085. rulesData.preload=true;
  2086. }
  2087. if(rulesData.blacklist && rulesData.blacklist.length>0){
  2088. for(let b in rulesData.blacklist){
  2089. let curGlob=rulesData.blacklist[b];
  2090. if(globMatch(curGlob, location.href)){
  2091. return;
  2092. }
  2093. }
  2094. }
  2095. enableDebug=rulesData.enableDebug;
  2096. storage.getItem("forceState_"+location.host, v=>{
  2097. storage.getItem("ruleLastUpdate", date=>{
  2098. if(typeof(v)=="undefined"){
  2099. v=(rulesData.enableWhiteList?1:0);
  2100. }
  2101. forceState=v;
  2102. updateDate=date;
  2103. if(initConfig())return;
  2104. if(forceState==1)return;
  2105. let now=new Date().getTime();
  2106. if(!date || now-date>2*24*60*60*1000){
  2107. updateRules(()=>{
  2108. },(rule,err)=>{});
  2109. }
  2110. callback();
  2111. });
  2112. });
  2113. });
  2114. });
  2115. }
  2116.  
  2117. function requestDoc(url, callback){
  2118. _GM_xmlhttpRequest({
  2119. url: url,
  2120. method: 'GET',
  2121. overrideMimeType: 'text/html;charset='+document.charset,
  2122. headers: {
  2123. 'Referer': location.href,
  2124. "Content-Type": "text/html;charset="+document.charset,
  2125. },
  2126. timeout: 5000,
  2127. onload: function(res) {
  2128. var doc=null,response=res.response;
  2129. let preCode=ruleParser.curSiteRule.pageElementPre || ruleParser.curSiteRule.pagePre;
  2130. if(preCode){
  2131. try{
  2132. response=Function("response",'"use strict";' + preCode)(response);
  2133. }catch(e){
  2134. debug(e);
  2135. }
  2136. }
  2137. try {
  2138. doc=document.implementation.createHTMLDocument('');
  2139. doc.documentElement.innerHTML=response;
  2140. }
  2141. catch (e) {
  2142. debug('parse error'+e.toString());
  2143. }
  2144. let pageElement=ruleParser.getPageElement(doc);
  2145. if(inCors && (!pageElement || pageElement.length==0)){
  2146. ruleParser.curSiteRule.pageElement=allOfBody;
  2147. pageElement=ruleParser.getPageElement(doc);
  2148. ruleParser.getInsert(true);
  2149. }
  2150. //只有1的話怕不是圖片哦
  2151. if(pageElement && (pageElement.length>1 || (pageElement.length==1 && pageElement[0].tagName!="IMG") )){
  2152. let result=ruleParser.insertPage(doc, pageElement, url, callback, false);
  2153. ruleParser.curSiteRule.action=0;
  2154. if(!result){
  2155. ruleParser.curSiteRule.action=1;
  2156. requestFromIframe(url, (doc, eles)=>{
  2157. loadPageOver();
  2158. if(eles){
  2159. ruleParser.insertPage(doc, eles, url, callback, true);
  2160. }
  2161. });
  2162. }
  2163. }else if(ruleParser.curSiteRule.singleUrl || curPage==1){
  2164. ruleParser.curSiteRule.action=1;
  2165. requestFromIframe(url, (doc, eles)=>{
  2166. loadPageOver();
  2167. if(eles){
  2168. ruleParser.insertPage(doc, eles, url, callback, true);
  2169. }
  2170. });
  2171. }else{
  2172. isPause=true;
  2173. callback(false);
  2174. }
  2175. },
  2176. onerror: function(e){
  2177. debug(e);
  2178. callback(false);
  2179. },
  2180. ontimeout: function(e){
  2181. debug(e);
  2182. callback(false);
  2183. }
  2184. });
  2185. }
  2186.  
  2187. var failFromIframe=0;
  2188. var inCors=false;
  2189. function requestFromIframe(url, callback){
  2190. let orgPage,curPage;
  2191. let iframe = document.createElement('iframe');
  2192. iframe.name = 'pagetual-iframe';
  2193. iframe.width = '100%';
  2194. iframe.height = '0';
  2195. iframe.frameBorder = '0';
  2196. if(ruleParser.curSiteRule.sandbox!=false){
  2197. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  2198. }
  2199. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  2200. let waitTime=100,checkEval;
  2201. if(ruleParser.curSiteRule.wait){
  2202. if(isNaN(ruleParser.curSiteRule.wait)){
  2203. try{
  2204. checkEval=Function("doc",'"use strict";' + ruleParser.curSiteRule.wait);
  2205. }catch(e){
  2206. debug(e);
  2207. }
  2208. }else{
  2209. waitTime=ruleParser.curSiteRule.wait;
  2210. }
  2211. }
  2212. let loadedHandler=e=>{
  2213. if(e.data != 'pagetual-iframe:DOMLoaded' && e.type != 'load')return;
  2214. window.removeEventListener('message', loadedHandler, false);
  2215. iframe.removeEventListener('load', loadedHandler, false);
  2216. let tryTimes=0;
  2217. function checkIframe(){
  2218. try{
  2219. let doc=iframe.contentDocument || iframe.contentWindow.document;
  2220. let eles=ruleParser.getPageElement(doc, iframe.contentWindow);
  2221. if(eles && eles.length>0 && (!checkEval || checkEval(doc))){
  2222. callback(doc, eles);
  2223. }else if(tryTimes++ < 10){
  2224. setTimeout(()=>{
  2225. checkIframe();
  2226. },waitTime);
  2227. return;
  2228. }else{
  2229. if(failFromIframe++ > 2){
  2230. failFromIframe=0;
  2231. debug("Stop as failFromIframe");
  2232. isPause=true;
  2233. callback(false, false);
  2234. }else{
  2235. callback(false, false);
  2236. }
  2237. }
  2238. }catch(e){
  2239. debug("Stop as cors");
  2240. inCors=true;
  2241. //isPause=true;
  2242. if(!ruleParser.curSiteRule.pageElement){
  2243. ruleParser.curSiteRule.pageElement=allOfBody;
  2244. ruleParser.getInsert(true);
  2245. }
  2246. ruleParser.curSiteRule.action=0;
  2247. ruleParser.nextLinkHref=url;
  2248. callback(false, false);
  2249. nextPage();
  2250. }
  2251. document.body.removeChild(iframe);
  2252. }
  2253. setTimeout(()=>{
  2254. checkIframe();
  2255. },waitTime);
  2256. };
  2257. window.addEventListener('message', loadedHandler, false);
  2258. iframe.addEventListener('load', loadedHandler, false);
  2259. iframe.src=url;
  2260. document.body.appendChild(iframe);
  2261. }
  2262.  
  2263. function initPage(){
  2264. ruleParser.initPage(()=>{
  2265. if(ruleParser.nextLinkHref){
  2266. let isJs=/^(javascript|#)/.test(ruleParser.nextLinkHref.replace(location.href,""));
  2267. if(!isJs){
  2268. let inForce=(forceState == 2 || forceState == 3);
  2269. _GM_registerMenuCommand(i18n(inForce?"cancelForceIframe":"forceIframe"), ()=>{
  2270. if(inForce){
  2271. storage.setItem("forceState_"+location.host, "");
  2272. }else{
  2273. let _state=ruleParser.curSiteRule.action>0 || confirm(i18n("forceAllBody"))?2:3;
  2274. storage.setItem("forceState_"+location.host, _state);
  2275. }
  2276. location.reload();
  2277. });
  2278. }
  2279. _GM_registerMenuCommand(i18n("loadNow"), ()=>{
  2280. let loadNum=window.prompt(i18n("loadConfirm"), "1");
  2281. if(loadNum==="" || loadNum===null)return;
  2282. autoLoadNum=Math.abs(parseInt(loadNum));
  2283. nextPage();
  2284. });
  2285. }
  2286. initListener();
  2287. if(rulesData.initRun && ruleParser.curSiteRule.initRun!=0)nextPage();
  2288. });
  2289. }
  2290.  
  2291. var pageBarStyle;
  2292. function initView(){
  2293. _GM_addStyle(`
  2294. .pagetual_pageBar.stop {
  2295. -webkit-filter: invert(100%);
  2296. filter: invert(100%);
  2297. opacity: 1!important;
  2298. }
  2299. .pagetual_pageBar.hide {
  2300. display: none!important;
  2301. }
  2302. .pagetual_pageBar:hover {
  2303. opacity: 1!important;
  2304. }
  2305. .pagetual_pageBar span {
  2306. vertical-align: super;
  2307. }
  2308.  
  2309. .pagetual_pageBar span>svg:hover {
  2310. animation: touhouAni 1s infinite;
  2311. }
  2312. .pagetual_pageBar .pagetual_pageNum{
  2313. color: #55555f;
  2314. }
  2315. .pagetual_pageBar .pagetual_pageNum:hover{
  2316. color: #ff6464;
  2317. }
  2318. .pagetual_tipsWords{
  2319. font-size: 50px;
  2320. font-weight: bold;
  2321. font-family: "黑体", -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto",
  2322. "Oxygen", "Ubuntu", "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji",
  2323. "Segoe UI Emoji", "Segoe UI Symbol";
  2324. color: #ffffff;
  2325. height: 70px;
  2326. line-height: 70px;
  2327. position: fixed;
  2328. left: 50%;
  2329. top: 10%;
  2330. margin-left: -150px;
  2331. padding: 0 10px;
  2332. z-index: 999999999;
  2333. background-color: #000;
  2334. border: 1px solid black;
  2335. border-radius: 10px;
  2336. opacity: 0;
  2337. filter: alpha(opacity=65);
  2338. box-shadow: 5px 5px 20px 0px #000;
  2339. -moz-transition:opacity 0.3s ease-in-out 0s;
  2340. -webkit-transition:opacity 0.3s ease-in-out 0s;
  2341. transition:opacity 0.3s ease-in-out 0s;
  2342. pointer-events: none;
  2343. }
  2344.  
  2345. @keyframes touhouAni{
  2346. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  2347. to {transform: rotate(360deg);}
  2348. }
  2349. @-webkit-keyframes touhouAni{
  2350. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  2351. to {transform: rotate(360deg);}
  2352. }
  2353. .pagetual_loading {
  2354. width: 50px;
  2355. height: 50px;
  2356. margin: 10px auto;
  2357. border-radius: 100%;
  2358. -webkit-animation: pagetual_loading_scaleout 1.0s infinite ease-in-out;
  2359. animation: pagetual_loading_scaleout 1.0s infinite ease-in-out;
  2360. }
  2361. @-webkit-keyframes pagetual_loading_scaleout {
  2362. 0% { -webkit-transform: scale(0.0) }
  2363. 100% {
  2364. -webkit-transform: scale(1.0);
  2365. opacity: 0;
  2366. }
  2367. }
  2368. @keyframes pagetual_loading_scaleout {
  2369. 0% {
  2370. transform: scale(0.0);
  2371. -webkit-transform: scale(0.0);
  2372. } 100% {
  2373. transform: scale(1.0);
  2374. -webkit-transform: scale(1.0);
  2375. opacity: 0;
  2376. }
  2377. }
  2378. `);
  2379. 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;`;
  2380. }
  2381. var loadingDiv=document.createElement("div");
  2382. 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;";
  2383. 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>`;
  2384. 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;`;
  2385.  
  2386. 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>`;
  2387. var upSvgCSS=`display:initial;position:absolute;cursor: pointer;margin: 0 -45px;width: 30px;height: 30px;vertical-align: middle;fill: currentColor;overflow: hidden;`;
  2388. 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>`;
  2389. 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);`;
  2390.  
  2391. 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;`;
  2392. 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);`;
  2393.  
  2394. var tipsWords=document.createElement("div");
  2395. tipsWords.className="pagetual_tipsWords";
  2396.  
  2397. var isPause=false,isLoading=false,curPage=1,forceState=0,bottomGap=1000,autoLoadNum=-1;
  2398.  
  2399. function changeStop(stop, hide){
  2400. isPause=stop;
  2401. [].forEach.call(document.querySelectorAll(".pagetual_pageBar"), bar=>{
  2402. if(isPause){
  2403. bar.classList.add("stop");
  2404. if(hide)bar.classList.add("hide");
  2405. }else{
  2406. bar.classList.remove("stop");
  2407. if(hide)bar.classList.remove("hide");
  2408. }
  2409. });
  2410. }
  2411.  
  2412. function isInViewPort(element) {
  2413. if(!element.parentNode)return false;
  2414. if(_unsafeWindow.getComputedStyle(element).display=="none")return false;
  2415. const viewWidth = window.innerWidth || document.documentElement.clientWidth;
  2416. const viewHeight = window.innerHeight || document.documentElement.clientHeight;
  2417. const {
  2418. top,
  2419. right,
  2420. bottom,
  2421. left,
  2422. } = element.getBoundingClientRect();
  2423.  
  2424. return (
  2425. top >= 0 &&
  2426. left >= 0 &&
  2427. right <= viewWidth + 1 &&
  2428. bottom <= viewHeight * 2
  2429. );
  2430. }
  2431.  
  2432. var urlChanged=false;
  2433. var _wr = function(type) {
  2434. var orig = history[type];
  2435. return function() {
  2436. var rv = orig.apply(this, arguments);
  2437. var e = new Event(type);
  2438. e.arguments = arguments;
  2439. window.dispatchEvent(e);
  2440. return rv;
  2441. };
  2442. };
  2443. history.pushState = _wr('pushState');
  2444. window.addEventListener('pushState', function(e) {
  2445. urlChanged=true;
  2446. isPause=true;
  2447. setTimeout(()=>{
  2448. if(location.href==configPage){
  2449. location.reload();
  2450. }
  2451. },1);
  2452. });
  2453.  
  2454. function initListener(){
  2455. let loadmoreBtn,loading=true,lastScroll=0,checkLoadMoreTimes=0;
  2456. let checkLoadMore=setInterval(()=>{
  2457. loadmoreBtn=getLoadMore(document);
  2458. if(loadmoreBtn && isVisible(loadmoreBtn, _unsafeWindow)){
  2459. loading=false;
  2460. clearInterval(checkLoadMore);
  2461. }else if(checkLoadMoreTimes>10){
  2462. clearInterval(checkLoadMore);
  2463. }
  2464. },300);
  2465. let checkScrollReach=()=>{
  2466. let scrolly=window.scrollY;
  2467. let windowHeight=window.innerHeight || document.documentElement.clientHeight;
  2468. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  2469. if(scrollH-scrolly-windowHeight<bottomGap){
  2470. nextPage();
  2471. }
  2472. };
  2473. let scrollHandler = e=>{
  2474. if(urlChanged){
  2475. ruleParser.initPage(()=>{
  2476. if(ruleParser.nextLinkHref)initView();
  2477. });
  2478. urlChanged=false;
  2479. isPause=false;
  2480. }
  2481. if(isPause)return;
  2482. if(!loading){
  2483. if(!loadmoreBtn || !loadmoreBtn.parentNode){
  2484. loadmoreBtn=getLoadMore(document);
  2485. }
  2486. if(loadmoreBtn){
  2487. if(isInViewPort(loadmoreBtn)){
  2488. emuClick(loadmoreBtn);
  2489. loading=true;
  2490. setTimeout(()=>{loading=false},200);
  2491. }
  2492. }else{
  2493. loading=true;
  2494. setTimeout(()=>{loading=false},200);
  2495. }
  2496. }
  2497. if(!isLoading){
  2498. checkScrollReach();
  2499. }
  2500. if(ruleParser.curSiteRule.lockScroll){
  2501. let curScroll=document.body.scrollTop||document.documentElement.scrollTop;
  2502. if(lastScroll!=0 && isLoading && Math.abs(lastScroll-curScroll)>100){
  2503. document.body.scrollTop=lastScroll;
  2504. document.documentElement.scrollTop=lastScroll;
  2505. }else{
  2506. lastScroll=curScroll;
  2507. }
  2508. }
  2509. };
  2510. if(!ruleParser.curSiteRule.wheel){
  2511. document.addEventListener('scroll', scrollHandler, true);
  2512. }
  2513. document.addEventListener('wheel', scrollHandler, true);
  2514. document.addEventListener('dblclick', e=>{
  2515. if(e.target.tagName!="BODY"){
  2516. let selStr=document.getSelection().toString().trim();
  2517. if(selStr){
  2518. return;
  2519. }
  2520. }
  2521. if(rulesData.dbClick2Stop && (ruleParser.nextLinkHref || loadmoreBtn)){
  2522. setTimeout(()=>{
  2523. changeStop(!isPause, rulesData.hideBar);
  2524. if(!isPause){
  2525. checkScrollReach();
  2526. }
  2527. showTips(i18n(isPause?"disable":"enable"));
  2528. },10);
  2529. }
  2530. });
  2531. }
  2532.  
  2533. function showTips(content, wordColor, backColor){
  2534. document.body.appendChild(tipsWords);
  2535. tipsWords.style.opacity=0.8;
  2536. tipsWords.innerText=content;
  2537. tipsWords.style.marginLeft=-tipsWords.offsetWidth/2+"px";
  2538. tipsWords.style.color=wordColor||0xFFFFFF;
  2539. tipsWords.style.backgroundColor=backColor||0x000;
  2540. setTimeout(()=>{tipsWords.style.opacity=0},1000);
  2541. }
  2542.  
  2543. function getLoadMore(doc){
  2544. if(ruleParser.curSiteRule.loadMore==="")return null;
  2545. let btnSel=ruleParser.curSiteRule.loadMore||".LoadMore,.load-more,.button-show-more",loadmoreBtn;
  2546. if(btnSel){
  2547. try{
  2548. loadmoreBtn=doc.querySelector(btnSel);
  2549. }catch(e){
  2550. loadmoreBtn=getElementByXpath(btnSel,doc,doc);
  2551. }
  2552. }
  2553. if(!loadmoreBtn){
  2554. let buttons=doc.querySelectorAll("input,button,a,div[onclick]"),loadmoreReg=/^\s*(加载更多|加載更多|load\s*more|もっと読み込む)\s*$/i;
  2555. for(let i=0;i<buttons.length;i++){
  2556. let button=buttons[i];
  2557. if(button && loadmoreReg.test(button.innerText)){
  2558. loadmoreBtn=button;
  2559. break;
  2560. }
  2561. }
  2562. }
  2563. if(loadmoreBtn && !ruleParser.curSiteRule.loadMore && loadmoreBtn.href && !/^(javascript|#)/.test(loadmoreBtn.href))loadmoreBtn=null;
  2564. return loadmoreBtn;
  2565. }
  2566.  
  2567. var hasPageNum=true;
  2568. function createPageBar(url){
  2569. let insert=ruleParser.getInsert();
  2570. if(!insert || !insert.parentNode)return;
  2571. curPage++;
  2572. let example=ruleParser.curSiteRule.insertPos==2?insert.children[0]:(insert.previousElementSibling||insert);
  2573. if(!example || !example.parentNode)example=insert;
  2574. let inTable=example.parentNode.tagName=="TABLE" ||
  2575. example.tagName=="TR" ||
  2576. example.tagName=="TBODY" ||
  2577. (example.previousElementSibling && example.previousElementSibling.tagName=="TR") ||
  2578. (example.previousElementSibling && example.previousElementSibling.tagName=="TBODY");
  2579. let inLi=example.tagName=="LI" || (example.previousElementSibling && example.previousElementSibling.tagName=="LI");
  2580. if(forceState==2){
  2581. inTable=inLi=false;
  2582. }
  2583. let pageBar=document.createElement(inTable?"tr":(inLi?"li":"div"));
  2584. let upSpan=document.createElement("span");
  2585. let downSpan=document.createElement("span");
  2586. let pageText=document.createElement("a");
  2587. let pageNum;
  2588. pageBar.className="pagetual_pageBar";
  2589. pageBar.id="pagetual_pageBar";
  2590. if(isPause){
  2591. pageBar.classList.add("stop");
  2592. }
  2593. pageBar.style.cssText=pageBarStyle;
  2594. pageBar.title=i18n(isPause?"enable":"disable");
  2595. upSpan.innerHTML=upSvg;
  2596. upSpan.children[0].style.cssText=upSvgCSS;
  2597. upSpan.title=i18n("toTop");
  2598. downSpan.innerHTML=downSvg;
  2599. downSpan.children[0].style.cssText=downSvgCSS;
  2600. downSpan.title=i18n("toBottom");
  2601. upSpan.style.cssText=initStyle;
  2602. downSpan.style.cssText=initStyle;
  2603. pageText.href=url;
  2604. pageText.style.cssText=pageTextStyle;
  2605. pageText.title=i18n("current");
  2606. pageBar.appendChild(upSpan);
  2607. pageBar.appendChild(pageText);
  2608. if(ruleParser.nextTitle){
  2609. pageText.innerHTML=ruleParser.nextTitle+" ";
  2610. }
  2611. if(ruleParser.curSiteRule.pageNum || (hasPageNum && /[&\/\?](p=|page[=\/_-]?)\d+|[_-]\d+\./.test(url))){
  2612. pageText.innerHTML+="Page ";
  2613. pageNum=document.createElement("span");
  2614. pageNum.innerText=curPage;
  2615. pageNum.className="pagetual_pageNum";
  2616. pageNum.title=i18n("inputPageNum");
  2617. pageNum.style.cssText=pageTextStyle;
  2618. pageNum.style.cursor="pointer";
  2619. pageNum.style.color="";
  2620. pageNum.addEventListener("click", e=>{
  2621. let pageInput=prompt(i18n("inputPageNum"), "1");
  2622. if(pageInput){
  2623. let pageLink=ruleParser.getLinkByPage(url, pageInput);
  2624. if(pageLink){
  2625. _GM_openInTab(pageLink,{active:true});
  2626. }
  2627. }
  2628. e.preventDefault();
  2629. e.stopPropagation();
  2630. });
  2631. pageBar.appendChild(pageNum);
  2632. }else{
  2633. pageText.innerHTML+="Page "+curPage;
  2634. hasPageNum=false;
  2635. }
  2636. pageBar.appendChild(downSpan);
  2637. let parentStyle=_unsafeWindow.getComputedStyle(example.parentNode);
  2638. let parentWidth=example.parentNode.scrollWidth||parseInt(parentStyle.width);
  2639. pageBar.style.width=parentWidth-parseInt(parentStyle.paddingLeft)-parseInt(parentStyle.paddingRight)-10+"px";
  2640. if(parentStyle.display=="grid" || parentStyle.display=="inline-grid"){
  2641. pageBar.style.gridColumnStart=1;
  2642. pageBar.style.gridColumnEnd=1+parseInt(example.parentNode.offsetWidth/example.offsetWidth);
  2643. }
  2644. if(inTable){
  2645. example=(example.tagName=="TR" || example.tagName=="TBODY")?example:example.previousElementSibling;
  2646. if(example.tagName=="TBODY")example=example.querySelector("tr");
  2647. if(example.previousElementSibling)example=example.previousElementSibling;
  2648. let tdNum=0;
  2649. [].forEach.call(example.children, el=>{
  2650. if(el.tagName=="TD" || el.tagName=="TH"){
  2651. tdNum+=el.colSpan||1;
  2652. }
  2653. });
  2654. pageBar.style.display="table-row";
  2655. pageBar.style.backgroundColor="unset";
  2656. pageBar.style.lineHeight="20px";
  2657. pageBar.style.boxShadow="";
  2658. let td=document.createElement("td");
  2659. td.colSpan=tdNum||1;
  2660. let inTd=document.createElement("div");
  2661. inTd.style.backgroundColor="rgb(240 240 240 / 80%)";
  2662. inTd.style.borderRadius="20px";
  2663. inTd.style.padding="0 0";
  2664. inTd.style.margin="10px";
  2665. inTd.style.lineHeight="20px";
  2666. inTd.style.textAlign="center";
  2667. inTd.style.boxShadow="rgb(0 0 0 / 67%) 0px 0px 10px 0px";
  2668. inTd.appendChild(upSpan);
  2669. inTd.appendChild(pageText);
  2670. if(pageNum)inTd.appendChild(pageNum);
  2671. inTd.appendChild(downSpan);
  2672. td.appendChild(inTd);
  2673. pageBar.appendChild(td);
  2674. }else if(inLi){
  2675. example=example.tagName=="LI"?example:example.previousElementSibling;
  2676. pageBar.style.display="table-row";
  2677. pageBar.style.backgroundColor="unset";
  2678. pageBar.style.lineHeight="20px";
  2679. pageBar.style.boxShadow="";
  2680. let td=document.createElement("td");
  2681. td.colSpan=example.children.length;
  2682. let inTd=document.createElement("div");
  2683. inTd.style.backgroundColor="rgb(240 240 240 / 80%)";
  2684. inTd.style.borderRadius="20px";
  2685. inTd.style.margin="10px"
  2686. inTd.style.padding="0 0";
  2687. inTd.style.textAlign="center";
  2688. inTd.style.minWidth="150px";
  2689. inTd.appendChild(upSpan);
  2690. inTd.appendChild(pageText);
  2691. inTd.style.width=parseInt(pageBar.style.width)-20+"px";
  2692. inTd.style.boxShadow="rgb(0 0 0 / 67%) 0px 0px 10px 0px";
  2693. if(pageNum)inTd.appendChild(pageNum);
  2694. inTd.appendChild(downSpan);
  2695. td.appendChild(inTd);
  2696. pageBar.appendChild(td);
  2697. }
  2698.  
  2699. upSpan.addEventListener("click", e=>{
  2700. document.body.scrollTop=0;
  2701. document.documentElement.scrollTop=0;
  2702. e.preventDefault();
  2703. e.stopPropagation();
  2704. });
  2705. downSpan.addEventListener("click", e=>{
  2706. changeStop(true);
  2707. pageBar.title=i18n(isPause?"enable":"disable");
  2708. document.body.scrollTop=9999999;
  2709. document.documentElement.scrollTop=9999999;
  2710. e.preventDefault();
  2711. e.stopPropagation();
  2712. });
  2713. pageBar.addEventListener("click", e=>{
  2714. changeStop(!isPause);
  2715. pageBar.title=i18n(isPause?"enable":"disable");
  2716. });
  2717. pageText.addEventListener("click", e=>{
  2718. e.stopPropagation();
  2719. });
  2720. if(ruleParser.curSiteRule.insertPos==2){
  2721. insert.appendChild(pageBar);
  2722. }else{
  2723. insert.parentNode.insertBefore(pageBar, insert);
  2724. }
  2725. if(ruleParser.curSiteRule.pageBar){
  2726. try{
  2727. Function("pageBar",'"use strict";' + ruleParser.curSiteRule.pageBar)(pageBar);
  2728. }catch(e){
  2729. debug(e);
  2730. }
  2731. }
  2732.  
  2733. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  2734. let posEle=pageBar.nextElementSibling||pageBar;
  2735. while(posEle && !posEle.offsetParent){
  2736. posEle=posEle.previousElementSibling||posEle.parentNode;
  2737. }
  2738. if(posEle){
  2739. let actualTop = getElementTop(posEle);
  2740. bottomGap=scrollH-actualTop+(window.innerHeight||document.documentElement.clientHeight)*(ruleParser.curSiteRule.rate||1);
  2741. if(bottomGap<100)bottomGap=100;
  2742. }else{
  2743. bottomGap=1000;
  2744. }
  2745. if(rulesData.opacity==0)pageBar.style.display="none";
  2746. return pageBar;
  2747. }
  2748.  
  2749. function emuClick(btn){
  2750. if(!PointerEvent)return btn.click();
  2751. let eventParam={
  2752. isTrusted: true,
  2753. altKey: false,
  2754. azimuthAngle: 0,
  2755. bubbles: true,
  2756. button: 0,
  2757. buttons: 0,
  2758. clientX: 1,
  2759. clientY: 1,
  2760. cancelBubble: false,
  2761. cancelable: true,
  2762. composed: true,
  2763. ctrlKey: false,
  2764. defaultPrevented: false,
  2765. detail: 1,
  2766. eventPhase: 2,
  2767. fromElement: null,
  2768. height: 1,
  2769. isPrimary: false,
  2770. metaKey: false,
  2771. pointerId: 1,
  2772. pointerType: "mouse",
  2773. pressure: 0,
  2774. relatedTarget: null,
  2775. returnValue: true,
  2776. shiftKey: false,
  2777. toElement: null,
  2778. twist: 0,
  2779. which: 1
  2780. };
  2781. var mouseEvent = new PointerEvent("mousedown",eventParam);
  2782. btn.dispatchEvent(mouseEvent);
  2783. mouseEvent = new PointerEvent("mouseup",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. var scrollToResizeInited = false;
  2938. var resizePool = [];
  2939. function scrollToResize() {
  2940. if (scrollToResizeInited) return;
  2941. scrollToResizeInited = true;
  2942. var scrollingToResize = false;
  2943. document.addEventListener("scroll", e => {
  2944. if (scrollingToResize) return;
  2945. else {
  2946. scrollingToResize = true;
  2947. setTimeout(() => {scrollingToResize = false}, 500);
  2948. }
  2949. resizePool.forEach(resizeArr => {
  2950. let iframe = resizeArr[1]();
  2951. let frameDoc = resizeArr[2]();
  2952. if(ruleParser.curSiteRule.singleUrl){
  2953. iframe.style.height=frameDoc.body.scrollHeight+"px";
  2954. iframe.style.width=frameDoc.body.scrollWidth+"px";
  2955. }else{
  2956. let pageEle = resizeArr[0]();
  2957. if(pageEle){
  2958. let targetElement = pageEle[0];
  2959. if(pageEle.length > 1){
  2960. targetElement = targetElement.parentNode;
  2961. }
  2962. iframe.style.height=targetElement.scrollHeight+"px";
  2963. frameDoc.documentElement.scrollTop = 0;
  2964. frameDoc.documentElement.scrollLeft = 0;
  2965. while(targetElement && targetElement.offsetParent){
  2966. targetElement.offsetParent.scrollTop = targetElement.offsetTop;
  2967. if(targetElement.offsetParent.scrollTop == 0){
  2968. frameDoc.documentElement.scrollTop += targetElement.offsetTop;
  2969. }
  2970. targetElement.offsetParent.scrollLeft = targetElement.offsetLeft;
  2971. if(targetElement.offsetParent.scrollLeft == 0){
  2972. frameDoc.documentElement.scrollLeft += targetElement.offsetLeft;
  2973. }
  2974. targetElement = targetElement.offsetParent;
  2975. }
  2976. }
  2977. }
  2978. });
  2979. });
  2980. }
  2981.  
  2982. function forceIframe(url, callback){
  2983. let curIframe = document.createElement('iframe'),iframeDoc;
  2984. let setPosition = ()=>{
  2985. let getIframe = () => {
  2986. return curIframe;
  2987. };
  2988. let getFrameDoc = () => {
  2989. return iframeDoc;
  2990. };
  2991. if(ruleParser.curSiteRule.singleUrl){
  2992. resizePool.push([() => {}, getIframe, getFrameDoc]);
  2993. }else{
  2994. let pageElement = ruleParser.getPageElement(iframeDoc,iframeDoc.defaultView);
  2995. let getPageEle = () => {
  2996. if (!pageElement) {
  2997. pageElement = ruleParser.getPageElement(iframeDoc,iframeDoc.defaultView);
  2998. }
  2999. return pageElement;
  3000. };
  3001. resizePool.push([getPageEle, getIframe, getFrameDoc]);
  3002. }
  3003. };
  3004. curIframe.name = 'pagetual-iframe';
  3005. curIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  3006. curIframe.frameBorder = '0';
  3007. curIframe.scrolling="no";
  3008. 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;';
  3009. curIframe.addEventListener("load", e=>{
  3010. try{
  3011. iframeDoc=curIframe.contentDocument || curIframe.contentWindow.document;
  3012. }catch(e){
  3013. debug("Stop as cors");
  3014. isPause=true;
  3015. callback(false, false);
  3016. return;
  3017. }
  3018. ruleParser.insertPage(iframeDoc, [], url, null, true);
  3019. callback(curIframe, true);
  3020. let css=ruleParser.curSiteRule.css;
  3021. if(css){
  3022. let styleEle=iframeDoc.createElement("style");
  3023. styleEle.innerHTML=css;
  3024. iframeDoc.head.appendChild(styleEle);
  3025. }
  3026. setPosition();
  3027. let code=ruleParser.curSiteRule.init;
  3028. if(code){
  3029. try{
  3030. Function('doc','win','iframe','"use strict";' + code)(iframeDoc,iframeDoc.defaultView,curIframe);
  3031. }catch(e){
  3032. debug(e);
  3033. }
  3034. }
  3035. });
  3036. let inAction=false,checkTimes=0;
  3037. let forceRefresh=e=>{
  3038. if(inAction || !iframeDoc)return;
  3039. inAction=true;
  3040. let foundNext=()=>{
  3041. document.removeEventListener("scroll", forceRefresh);
  3042. }
  3043. setTimeout(()=>{
  3044. inAction=false;
  3045. if(!ruleParser.nextLinkHref){
  3046. checkTimes++;
  3047. ruleParser.getNextLink(iframeDoc);
  3048. if(ruleParser.nextLinkHref){
  3049. foundNext();
  3050. }else if(checkTimes>=10){
  3051. foundNext();
  3052. }
  3053. }else{
  3054. foundNext();
  3055. }
  3056. },50);
  3057. };
  3058. document.addEventListener("scroll", forceRefresh);
  3059. curIframe.src=url;
  3060. let insert=ruleParser.getInsert();
  3061. if(ruleParser.curSiteRule.singleUrl){
  3062. document.body.appendChild(curIframe);
  3063. }else if(ruleParser.curSiteRule.insertPos==2){
  3064. ruleParser.insert.appendChild(curIframe);
  3065. }else{
  3066. ruleParser.insert.parentNode.insertBefore(curIframe, ruleParser.insert);
  3067. }
  3068. scrollToResize();
  3069. return curIframe;
  3070. }
  3071.  
  3072. function loadPageOver(){
  3073. isLoading=false;
  3074. if(loadingDiv.parentNode){
  3075. loadingDiv.parentNode.removeChild(loadingDiv);
  3076. }
  3077. /*setTimeout(()=>{
  3078. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  3079. if(scrollH <= (window.innerHeight || document.documentElement.clientHeight)){
  3080. nextPage();
  3081. }
  3082. },1);*/
  3083. }
  3084.  
  3085. function nextPage(){
  3086. if(isPause || isLoading)return;
  3087. if(ruleParser.curSiteRule.delay){
  3088. try{
  3089. let checkDelay=Function('"use strict";' + ruleParser.curSiteRule.delay)();
  3090. if(!checkDelay)return;
  3091. }catch(e){
  3092. debug(e);
  3093. }
  3094. }
  3095. let nextLink=ruleParser.nextLinkHref;
  3096. if(!nextLink){
  3097. if(ruleParser.curSiteRule.pinUrl && curPage==1){
  3098. ruleParser.getNextLink(document);
  3099. nextLink=ruleParser.nextLinkHref;
  3100. if(!nextLink){
  3101. isPause=true;
  3102. setTimeout(()=>{isPause=false;},500);
  3103. return;
  3104. }
  3105. }else return;
  3106. }
  3107. let pvGallery=document.querySelector("span.pv-gallery-container");
  3108. if(pvGallery && pvGallery.style.display!="none")return;
  3109. let insert=ruleParser.getInsert();
  3110. if(insert){
  3111. let isJs=/^(javascript|#)/.test(nextLink.replace(location.href,""));
  3112. if(location.protocol=="https:" && /^http:/.test(nextLink)){
  3113. nextLink=nextLink.replace(/^http/,"https");
  3114. }
  3115. isLoading=true;
  3116. document.body.appendChild(loadingDiv);
  3117. loadingDiv.style.cssText=loadingCSS;
  3118. let sleep=ruleParser.curSiteRule.sleep||0;
  3119. setTimeout(()=>{
  3120. if(ruleParser.curSiteRule.pageElementByJs){
  3121. var over=ele=>{
  3122. loadPageOver();
  3123. if(ele){
  3124. createPageBar(nextLink);
  3125. ruleParser.insertPage(null, ele, nextLink, null, true);
  3126. if(autoLoadNum>=0){
  3127. if(autoLoadNum!=0 && --autoLoadNum==0){
  3128. autoLoadNum=-1;
  3129. }else{
  3130. nextPage();
  3131. }
  3132. }
  3133. }else{
  3134. debug("Stop as no page when get by js");
  3135. isPause=true;
  3136. }
  3137. };
  3138. try{
  3139. Function("over",'"use strict";' + ruleParser.curSiteRule.pageElementByJs)(over);
  3140. }catch(e){
  3141. debug(e);
  3142. }
  3143. }else if((forceState==3||ruleParser.curSiteRule.action==1) && !isJs){
  3144. requestFromIframe(nextLink, (doc, eles)=>{
  3145. loadPageOver();
  3146. if(eles){
  3147. createPageBar(nextLink);
  3148. ruleParser.insertPage(doc, eles, nextLink, null, true);
  3149. if(autoLoadNum>=0){
  3150. if(autoLoadNum!=0 && --autoLoadNum==0){
  3151. autoLoadNum=-1;
  3152. }else{
  3153. nextPage();
  3154. }
  3155. }
  3156. }
  3157. });
  3158. }else if((forceState==2||ruleParser.curSiteRule.action==2) && !isJs){
  3159. forceIframe(nextLink, (iframe, eles)=>{
  3160. loadPageOver();
  3161. let pageBar=createPageBar(nextLink);
  3162. if(pageBar)iframe.parentNode.insertBefore(pageBar, iframe);
  3163. if(autoLoadNum>=0){
  3164. if(autoLoadNum!=0 && --autoLoadNum==0){
  3165. autoLoadNum=-1;
  3166. }else{
  3167. nextPage();
  3168. }
  3169. }
  3170. });
  3171. }else{
  3172. if(!isJs){
  3173. requestDoc(nextLink, (eles)=>{
  3174. loadPageOver();
  3175. if(eles){
  3176. createPageBar(nextLink);
  3177. if(autoLoadNum>=0){
  3178. if(autoLoadNum!=0 && --autoLoadNum==0){
  3179. autoLoadNum=-1;
  3180. }else{
  3181. nextPage();
  3182. }
  3183. }
  3184. }
  3185. });
  3186. }else{
  3187. emuPage((doc, eles)=>{
  3188. loadPageOver();
  3189. if(eles){
  3190. createPageBar(nextLink);
  3191. ruleParser.insertPage(doc, eles, "", null, true);
  3192. if(autoLoadNum>=0){
  3193. if(autoLoadNum!=0 && --autoLoadNum==0){
  3194. autoLoadNum=-1;
  3195. }else{
  3196. nextPage();
  3197. }
  3198. }
  3199. }
  3200. });
  3201. }
  3202. }
  3203. },sleep);
  3204. }
  3205. }
  3206.  
  3207. function init(){
  3208. initRules(()=>{
  3209. initPage();
  3210. });
  3211. }
  3212. setTimeout(()=>{
  3213. init();
  3214. },100);
  3215. })();