东方永页机

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

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