东方永页机

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

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

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