东方永页机

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

当前为 2022-07-08 提交的版本,查看 最新版本

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