东方永页机

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

目前为 2022-07-09 提交的版本。查看 最新版本

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