东方永页机

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

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

  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.1
  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 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){
  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=="TBODY"){
  1012. self.curSiteRule.pageElement=geneSelector(ele)+">*";
  1013. if(ele.children.length>0 && ele.children[0].querySelector("th")){
  1014. self.curSiteRule.pageElement+=":not(:first-child)";
  1015. }
  1016. debug(self.curSiteRule.pageElement);
  1017. return ele.children;
  1018. }
  1019. self.curSiteRule.pageElement=geneSelector(ele);
  1020. if(ele.children.length>1){
  1021. let hasText=false;
  1022. for(let i in ele.childNodes){
  1023. let child=ele.childNodes[i];
  1024. if(child.nodeType==3 && child.nodeValue.trim()!=''){
  1025. hasText=true;
  1026. ele=[ele];
  1027. break;
  1028. }
  1029. }
  1030. if(!hasText){
  1031. let middleChild=ele.children[parseInt(ele.children.length/2)];
  1032. if((middleChild.style && middleChild.style.position=="absolute" && middleChild.style.left && middleChild.style.top) || ele.tagName=="UL" || curHeight==0){
  1033. ele=[ele];
  1034. }else{
  1035. self.curSiteRule.pageElement+=">*";
  1036. ele=ele.children;
  1037. }
  1038. }
  1039. }else{
  1040. ele=[ele];
  1041. }
  1042. debug(self.curSiteRule.pageElement);
  1043. return ele;
  1044. }
  1045. pageElement=checkElement(body);
  1046. //if(pageElement)this.saveCurSiteRule();
  1047. }
  1048. if(doc==document && !this.docPageElement){
  1049. this.docPageElement=pageElement;
  1050. }
  1051. if(pageElement && pageElement.length>0){
  1052. let pageElementCss=self.curSiteRule.pageElementCss || self.curSiteRule.pageElementStyle || rulesData.pageElementCss;
  1053. if(pageElementCss){
  1054. [].forEach.call(pageElement, ele=>{
  1055. if(!ele.dataset.pagetualPageElement){
  1056. ele.style.cssText=(ele.style.cssText||'')+pageElementCss;
  1057. ele.dataset.pagetualPageElement=1;
  1058. }
  1059. });
  1060. }
  1061. }
  1062. return pageElement;
  1063. }
  1064.  
  1065. getPage(doc){
  1066. if(typeof _unsafeWindow.Discourse!='undefined')return {};
  1067. let video=document.querySelector("video,iframe[src*=player]");
  1068. if(video){
  1069. if(video.scrollWidth>500 && video.scrollHeight>500){
  1070. debug("Won't run when video found");
  1071. return {};
  1072. }
  1073. }
  1074. let canSave=false;//發現頁碼選擇器在其他頁對不上,還是別保存了
  1075. let url=this.curUrl.replace("#!","").replace("index.php?","?");
  1076. let _url=url.replace(/\.s?html?$/i,"");
  1077. let pageNum=1,preStr="",afterStr="";
  1078. let pageMatch1=url.match(/(.*[a-z\/\-_](?:p|page)?\/?)(\d+)(\.s?html?$|\/?$)/i);
  1079. let pageMatch2=url.match(/(.*[\?&]p(?:age)?=)(\d+)($|[#&].*)/i);
  1080. if(pageMatch1){
  1081. preStr=pageMatch1[1];
  1082. pageNum=parseInt(pageMatch1[2]);
  1083. afterStr=pageMatch1[3];
  1084. }else if(pageMatch2){
  1085. preStr=pageMatch2[1];
  1086. pageNum=parseInt(pageMatch2[2]);
  1087. afterStr=pageMatch2[3];
  1088. }
  1089. let curPage=doc,i,cur,jsNext;
  1090. let next1,next2,next3,next4,nextJs1,nextJs2,nextJs3;
  1091. let next=curPage.querySelector(".page-next>a")||
  1092. curPage.querySelector("a.next_page")||
  1093. curPage.querySelector("#next_page")||
  1094. curPage.querySelector(".nextPage")||
  1095. curPage.querySelector("a[data-pagination=next]")||
  1096. curPage.querySelector("ul.pagination>li.active+li>a")||
  1097. curPage.querySelector(".pagination a[rel=next]")||
  1098. curPage.querySelector(".pagination-nav__item--next>a")||
  1099. curPage.querySelector("a[title='Next page']")||
  1100. curPage.querySelector("a.pageright")||
  1101. curPage.querySelector("a#rightFix")||
  1102. curPage.querySelector("a#next")||
  1103. curPage.querySelector(".next>a")||
  1104. curPage.querySelector(".next>button")||
  1105. curPage.querySelector("a[alt=next]")||
  1106. curPage.querySelector("button.next")||
  1107. curPage.querySelector("[title=next]")||
  1108. curPage.querySelector("a#btnPreGn")||
  1109. getElementByXpath("//a[contains(@class, 'page__next')]",curPage,curPage);
  1110. if(!next){
  1111. let nexts=curPage.querySelectorAll("a.next");
  1112. for(i=0;i<nexts.length;i++){
  1113. if(!/^([上前首尾][一1]?[页頁张張]|previous(\s*page)?\s*›?$|前のページ)/i.test(nexts[i].innerText.trim()) &&
  1114. nexts[i].style.display!=="none" &&
  1115. nexts[i].parentNode.style.display!=="none"){
  1116. next=nexts[i];
  1117. break;
  1118. }
  1119. }
  1120. }
  1121. if(next && (!next.href || /^javascript:/.test(next.href) || next.getAttribute("href")=="#")){
  1122. jsNext=next;
  1123. next=null;
  1124. }
  1125. if(!next){
  1126. next=curPage.querySelectorAll("[aria-label='Next page']");
  1127. if(next && next.length==1){
  1128. next=next[0];
  1129. if(!next.href || /^javascript:/.test(next.href) || next.getAttribute("href")=="#"){
  1130. if(!jsNext)jsNext=next;
  1131. next=null;
  1132. }
  1133. }else{
  1134. next=null;
  1135. }
  1136. }
  1137. if(!next){
  1138. next=curPage.querySelectorAll("[aria-label='Next']");
  1139. if(next && next.length==1){
  1140. next=next[0];
  1141. if(!next.href || /^javascript:/.test(next.href) || next.getAttribute("href")=="#"){
  1142. if(!jsNext)jsNext=next;
  1143. next=null;
  1144. }
  1145. }else{
  1146. next=null;
  1147. }
  1148. }
  1149. if(next && /^[下后後][一1]?[章话話篇]/i.test(next.innerText.trim())){
  1150. next2=next;
  1151. next=null;
  1152. }
  1153. if(!next){
  1154. next=curPage.querySelector("a.curr");
  1155. if(next){
  1156. next=next.nextSibling;
  1157. }
  1158. }
  1159. if(!next){
  1160. next=curPage.querySelector("div.wp-pagenavi>span.current+a,div.page-nav>span.current+a,div.article-paging>span+a");
  1161. }
  1162. if(!next){
  1163. let pageDiv=curPage.querySelector("div.pages>ul");
  1164. if(pageDiv){
  1165. cur=pageDiv.querySelector("li>b");
  1166. if(cur)next=cur.parentNode.nextElementSibling;
  1167. if(next)next=next.querySelector("a");
  1168. }
  1169. }
  1170. if(!next){
  1171. cur=curPage.querySelector(".number>ul>li.active");
  1172. if(cur)next=cur.nextElementSibling;
  1173. if(next)next=next.querySelector("a");
  1174. }
  1175. if(!next){
  1176. let aTags=curPage.querySelectorAll("a,button");
  1177. for(i=aTags.length-1;i>=0;i--){
  1178. if(next1 && next2 && next3 && next4)break;
  1179. let aTag=aTags[i];
  1180. if(aTag.innerText=="§")continue;
  1181. if(aTag.innerText.length>50)continue;
  1182. if(aTag.style.display=="none")continue;
  1183. if(aTag.href && /next$/i.test(aTag.href))continue;
  1184. if(aTag.className && /slick|slide/i.test(aTag.className))continue;
  1185. if(aTag.innerText.length<=18){
  1186. if(!next1){
  1187. if(/^[下后後][一1]?[页頁张張]|^next([ _-]?page)?\s*[›>→»]?$|次のページ|^次へ?$/i.test(aTag.innerText.trim())){
  1188. if(!aTag.href || /^javascript:/.test(aTag.href) || aTag.getAttribute("href")=="#"){
  1189. if(!nextJs1)nextJs1=aTag;
  1190. }else{
  1191. next1=aTag;
  1192. }
  1193. }
  1194. }
  1195. if(!next2){
  1196. if(/^[下后後][一1]?[章话話篇]/i.test(aTag.innerText.trim()) || /nextpage/i.test(aTag.className)){
  1197. if(!aTag.href || /^javascript:/.test(aTag.href) || aTag.getAttribute("href")=="#"){
  1198. if(!nextJs2)nextJs2=aTag;
  1199. }else{
  1200. next2=aTag;
  1201. }
  1202. }
  1203. }
  1204. if(!next3){
  1205. if(aTag.innerText=="&gt;" || aTag.innerText=="▶" || aTag.innerText==">" || aTag.innerText=="›" || aTag.innerText=="→" || aTag.innerText=="»"){
  1206. if(!aTag.href || /^javascript:/.test(aTag.href) || aTag.getAttribute("href")=="#"){
  1207. if(!nextJs3)nextJs3=aTag;
  1208. }else{
  1209. next3=aTag;
  1210. }
  1211. }
  1212. }
  1213. }
  1214. if(!aTag.href || /^javascript:/.test(aTag.href) || aTag.getAttribute("href")=="#")continue;
  1215. if(!next4 && aTag.href.length<250){
  1216. let _aHref=aTag.href.replace("?&","?").replace("#!","").replace("index.php?","?");
  1217. let _aHrefTrim=_aHref;
  1218. if(preStr)_aHrefTrim=_aHrefTrim.replace(preStr,"");
  1219. if(afterStr)_aHrefTrim=_aHrefTrim.replace(afterStr,"");
  1220. if(pageNum<999 && _aHrefTrim==pageNum+1){
  1221. next4=aTag;
  1222. }else if(this.curUrl!=aTag.href){
  1223. _aHref=_aHref.replace(/\.s?html?$/i,"");
  1224. if(_aHref.indexOf(_url)!=-1 && /^[\/\?&]?[_-]?(p|page)?=?\/?2(\/|\?|&|$)/i.test(_aHref.replace(_url,""))){
  1225. let curHref=aTag.getAttribute("href");
  1226. let pageOne=curHref.replace(/\/2(\/|\?|&|$)/,"/1$1");
  1227. if(pageOne==curHref)pageOne=null;
  1228. else pageOne=curPage.querySelector(`a[href='${pageOne}']`);
  1229. if(!pageOne || pageOne.className!=curHref.className)next4=aTag;
  1230. }
  1231. }
  1232. }
  1233. }
  1234. if(next3){
  1235. let eles=getAllElementsByXpath(`//a[text()='${next3.innerText}']`,curPage,curPage);
  1236. if(eles.length>2)next3=null;
  1237. }
  1238. }
  1239. if(!next)next=next1||next4||next3||next2||jsNext||nextJs1||nextJs3||nextJs2;
  1240. if(next && next.classList.contains("results-more"))next=null;
  1241. return {next:next,canSave:canSave};
  1242. }
  1243.  
  1244. canonicalUri(src) {
  1245. if(src.charAt(0)=="#")return location.href+src;
  1246. var root_page = /^[^?#]*\//.exec(location.href)[0],
  1247. base_path = location.pathname.replace(/\/[^\/]+\.[^\/]+$/, "/"),
  1248. root_domain = /^\w+\:\/\/\/?[^\/]+/.exec(root_page)[0],
  1249. absolute_regex = /^\w+\:\/\//;
  1250. src=src.replace(/\.\//,"");
  1251. if (/^\/\/\/?/.test(src)){
  1252. src = location.protocol + src;
  1253. }
  1254. else if (!absolute_regex.test(src) && src.charAt(0) != "/"){
  1255. src = (base_path || "") + src;
  1256. }
  1257. return (absolute_regex.test(src) ? src : ((src.charAt(0) == "/" ? root_domain : root_page) + src));
  1258. }
  1259.  
  1260. getLinkByPage(url, pageNum) {
  1261. if(!url)return;
  1262. if(this.curSiteRule.pageNum){
  1263. let result=this.curSiteRule.pageNum;
  1264. let strMatch=result.match(/\{.*?}/);
  1265. if(!strMatch)return null;
  1266. let urlReg=new RegExp("("+result.replace(strMatch[0], ")\\d+(")+")","i");
  1267. let code=strMatch[0].replace(/^{/,"").replace(/}$/,"").replace(/\$p/g,pageNum);
  1268. if(code==pageNum){
  1269. result=url.replace(urlReg,"$1"+code+"$2");
  1270. }else{
  1271. try{
  1272. code=Function('"use strict";return ' + code)();
  1273. result=url.replace(urlReg,"$1"+code+"$2");
  1274. }catch(e){
  1275. debug(e);
  1276. }
  1277. }
  1278. if(result!=url){
  1279. return result;
  1280. }
  1281. }
  1282. return url.replace(/([&\/\?](p=|page[=\/_-]?))\d+/i, "$1"+pageNum).replace(/([_-])\d+\./i, "$1"+pageNum+".");
  1283. }
  1284.  
  1285. getPageNumFromUrl(url) {
  1286. if(!url)return curPage;
  1287. if(this.curSiteRule.pageNum){
  1288. let result=this.curSiteRule.pageNum;
  1289. let strMatch=result.match(/\{.*?}/);
  1290. if(!strMatch)return null;
  1291. let urlReg=new RegExp(".*"+result.replace(strMatch[0], "(\\d+)")+".*","i");
  1292. let curShowNum=url.replace(urlReg,"$1");
  1293. if (curShowNum!=url){
  1294. let code=strMatch[0].replace(/^{/,"").replace(/}$/,"");
  1295. if(code=="$p"){
  1296. return curShowNum;
  1297. }else{
  1298. try{
  1299. let page1=Function('"use strict";return ' + code.replace("$p", "0"))();
  1300. let page2=Function('"use strict";return ' + code.replace("$p", "1"))();
  1301. let numGap=page2-page1;
  1302. return (curShowNum - page1) / numGap;
  1303. }catch(e){
  1304. debug(e);
  1305. }
  1306. }
  1307. }
  1308. }
  1309. let pageNum=url.replace(/.*[&\/\?](p=|page[=\/_-]?)(\d+).*/i, "$2");
  1310. return pageNum==url?curPage:pageNum;
  1311. }
  1312.  
  1313. getNextLink(doc) {
  1314. let nextLink=null,page,href;
  1315. let getNextLinkByForm=(form,n)=>{
  1316. let params=[];
  1317. [].forEach.call(form.querySelectorAll("input"), input=>{
  1318. if(n && /^(p|page)$/i.test(input.name)){
  1319. params.push('p='+n);
  1320. }else{
  1321. params.push(input.name+'='+input.value);
  1322. }
  1323. });
  1324. return form.action+'?'+params.join('&');
  1325. };
  1326. if(this.curSiteRule.pageElementByJs){
  1327. this.nextLinkHref="#";
  1328. return true;
  1329. }else if(this.curSiteRule.nextLinkByJs){
  1330. try{
  1331. let targetUrl=((typeof _unsafeWindow.pagetualNextLinkByJs=='undefined') ? Function("doc",'"use strict";' + this.curSiteRule.nextLinkByJs) : _unsafeWindow.pagetualNextLinkByJs)(doc);
  1332. if(targetUrl)nextLink={href:targetUrl};
  1333. }catch(e){
  1334. debug(e);
  1335. }
  1336. }else if(this.curSiteRule.nextLinkByUrl){
  1337. let targetUrl=this.curUrl.replace(new RegExp(this.curSiteRule.nextLinkByUrl[0],"i"), this.curSiteRule.nextLinkByUrl[1]);
  1338. if(targetUrl != this.curUrl){
  1339. let reps=targetUrl.match(/{.*?}/g);
  1340. if(reps){
  1341. reps.forEach(rep=>{
  1342. let code=rep.replace("{","").replace("}","").replace(/\(\)/g, "0");
  1343. let result=code.match(/^(\d*)\+1$/);
  1344. if(result){
  1345. result=parseInt(result[1]||1)+1;
  1346. }else{
  1347. try{
  1348. result=Function('"use strict";return ' + code)();
  1349. }catch(e){
  1350. debug(e);
  1351. }
  1352. }
  1353. targetUrl=targetUrl.replace(rep, result);
  1354. });
  1355. }
  1356. }
  1357. nextLink={href:targetUrl};
  1358. }else if(this.curSiteRule.nextLink){
  1359. if(this.curSiteRule.nextLink!="0" && this.curSiteRule.nextLink!=0){
  1360. nextLink=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.nextLink,doc,doc):doc.querySelector(this.curSiteRule.nextLink);
  1361. }
  1362. }else{
  1363. page=this.getPage(doc);
  1364. nextLink=page.next;
  1365. if(nextLink){
  1366. if(nextLink.tagName=="INPUT" && nextLink.parentNode.tagName=="FORM"){
  1367. let form=nextLink.parentNode;
  1368. nextLink.href=getNextLinkByForm(form);
  1369. }
  1370. if(nextLink.parentNode.style.display=="none" || nextLink.style.display=="none" || nextLink.classList.contains("noClick") || nextLink.hasAttribute("disabled")){
  1371. this.nextLinkHref=false;
  1372. return null;
  1373. }else if(doc==document){
  1374. if((!nextLink.href || /^javascript:/.test(nextLink.href)) && !isVisible(nextLink, _unsafeWindow)){
  1375. this.nextLinkHref=false;
  1376. return null;
  1377. }else{
  1378. let nextLinkCs=_unsafeWindow.getComputedStyle(nextLink);
  1379. if(nextLinkCs.cursor=="not-allowed"){
  1380. this.nextLinkHref=false;
  1381. return null;
  1382. }
  1383. this.initNext=nextLink;
  1384. }
  1385. }
  1386. let form=doc.querySelector('#search-form');
  1387. if(!nextLink.href && nextLink.hasAttribute("onclick") && form){
  1388. if(form && /^\d+$/.test(nextLink.innerText)){
  1389. href=getNextLinkByForm(form, nextLink.innerText);
  1390. }
  1391. }
  1392. }
  1393. }
  1394. if(nextLink){
  1395. let needUrl=(this.curSiteRule.action==0 || this.curSiteRule.action==1);
  1396. if(!href)href=nextLink.href;
  1397. if(href && nextLink.getAttribute){
  1398. let _href=nextLink.getAttribute("href");
  1399. if(!_href || _href.charAt(0)=="#" || _href=="?"){
  1400. href="#";
  1401. }
  1402. }
  1403.  
  1404. if((href===""||href===null) && needUrl){
  1405. this.nextLinkHref=false;
  1406. }else if(/^(javascript:void\(0\)|#)/.test(href) && needUrl){
  1407. this.nextLinkHref=false;
  1408. }else{
  1409. this.nextLinkHref=(href && !/^(javascript:|#)/.test(href))?this.canonicalUri(href):"#";
  1410. if(this.nextLinkHref!="#" && (this.nextLinkHref==this.curUrl || this.nextLinkHref==this.curUrl+"#" || this.nextLinkHref==this.oldUrl || this.nextLinkHref==this.oldUrl+"#")){
  1411. this.nextLinkHref=false;
  1412. }else if(doc==document)debug(nextLink);
  1413. }
  1414. }else{
  1415. this.nextLinkHref=false;
  1416. }
  1417. this.preload();
  1418. return nextLink;
  1419. }
  1420.  
  1421. preload(){
  1422. if(!rulesData.preload)return;
  1423. if(!this.nextLinkHref || this.nextLinkHref=="#")return;
  1424. let self=this;
  1425. if(this.curSiteRule && this.curSiteRule.action==1){
  1426. if(!this.preloadIframe){
  1427. this.preloadIframe = document.createElement('iframe');
  1428. let iframe = this.preloadIframe;
  1429. iframe.name = 'pagetual-iframe';
  1430. iframe.width = '100%';
  1431. iframe.height = '0';
  1432. iframe.frameBorder = '0';
  1433. if(ruleParser.curSiteRule.sandbox!=false){
  1434. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1435. }
  1436. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1437. iframe.addEventListener('load', function (e) {
  1438. try{
  1439. let doc=iframe.contentDocument || iframe.contentWindow.document;
  1440. var body = doc.body;
  1441. if (body && body.firstChild) {
  1442. self.lazyImgAction(body.children);
  1443. }
  1444. }catch(e){
  1445. return;
  1446. }
  1447. }, false);
  1448. document.body.appendChild(iframe);
  1449. }
  1450. this.preloadIframe.src = this.nextLinkHref;
  1451. }else{
  1452. _GM_xmlhttpRequest({
  1453. url: this.nextLinkHref,
  1454. method: 'GET',
  1455. overrideMimeType: 'text/html;charset='+document.charset,
  1456. headers: {
  1457. 'Referer': location.href
  1458. },
  1459. timeout: 5000,
  1460. onload: function(res) {
  1461. var doc=null;
  1462. try {
  1463. doc=document.implementation.createHTMLDocument('');
  1464. doc.documentElement.innerHTML=res.response;
  1465. var body = doc.body;
  1466. if (body && body.firstChild) {
  1467. self.lazyImgAction(body.children);
  1468. }
  1469. if(!self.preloadDiv){
  1470. self.preloadDiv = document.createElement('div');
  1471. self.preloadDiv.id = "pagetual-preload";
  1472. self.preloadDiv.style.cssText = 'display:none!important;';
  1473. document.body.appendChild(self.preloadDiv);
  1474. self.checkedImgs={};
  1475. }
  1476. [].forEach.call(doc.images, i=>{
  1477. let iSrc=i.src;
  1478. if(iSrc && !self.checkedImgs[iSrc]){
  1479. self.checkedImgs[iSrc] = true;
  1480. let img = document.createElement('img');
  1481. img.src = iSrc;
  1482. self.preloadDiv.appendChild(img);
  1483. }
  1484. });
  1485. }
  1486. catch (e) {
  1487. return;
  1488. }
  1489. }
  1490. });
  1491. }
  1492. }
  1493.  
  1494. getInsert(refresh) {
  1495. if(refresh){
  1496. this.insert=null;
  1497. }
  1498. if(this.insert && !refresh){
  1499. let parent=this.insert;
  1500. while(parent && parent.nodeName!="BODY"){
  1501. parent=parent.parentNode;
  1502. }
  1503. if(parent && parent.nodeName=="BODY"){
  1504. return this.insert;
  1505. }
  1506. }
  1507. if(this.curSiteRule.insert){
  1508. this.insert=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.insert,document):document.querySelector(this.curSiteRule.insert);
  1509. }else{
  1510. let pageElement=this.getPageElement(document, _unsafeWindow);
  1511. if(pageElement && pageElement.length>0){
  1512. var pELast = pageElement[pageElement.length - 1];
  1513. this.insert = pELast.nextSibling ? pELast.nextSibling : pELast.parentNode.appendChild(document.createTextNode(' '));
  1514. }
  1515. }
  1516. return this.insert;
  1517. }
  1518.  
  1519. pageInit(doc,eles){
  1520. let code=this.curSiteRule.pageInit;
  1521. if(code){
  1522. try{
  1523. ((typeof _unsafeWindow.pagetualPageInit=='undefined') ? Function("doc", "eles", '"use strict";' + code) : _unsafeWindow.pagetualPageInit)(doc, eles);
  1524. }catch(e){
  1525. debug(e);
  1526. }
  1527. }
  1528. }
  1529.  
  1530. pageAction(doc,eles){
  1531. let code=this.curSiteRule.pageAction;
  1532. if(code){
  1533. try{
  1534. ((typeof _unsafeWindow.pagetualPageAction=='undefined') ? Function("doc", "eles", '"use strict";' + code) : _unsafeWindow.pagetualPageAction)(doc, eles);
  1535. }catch(e){
  1536. debug(e);
  1537. }
  1538. }
  1539. this.lazyImgAction(eles);
  1540. this.openInNewTab(eles);
  1541. }
  1542.  
  1543. openInNewTab(eles){
  1544. if(rulesData.openInNewTab){
  1545. [].forEach.call(eles, ele=>{
  1546. if(ele.tagName=="A" && ele.href && !/^(mailto:|javascript:|#)/.test(ele.href)){
  1547. ele.setAttribute('target', '_blank');
  1548. }else{
  1549. [].forEach.call(ele.querySelectorAll('a[href]:not([href^="mailto:"]):not([href^="javascript:"]):not([href^="#"])'), a=>{
  1550. a.setAttribute('target', '_blank');
  1551. if (a.getAttribute('onclick') == 'atarget(this)') {
  1552. a.removeAttribute('onclick');
  1553. }
  1554. });
  1555. }
  1556. });
  1557. }
  1558. }
  1559.  
  1560. lazyImgAction(eles){
  1561. let setLazyImg=img=>{
  1562. let realSrc;
  1563. if(img.getAttribute("_src") && !img.src){
  1564. realSrc=img.getAttribute("_src");
  1565. }else if(img.dataset && img.dataset.original){
  1566. realSrc=img.dataset.original;
  1567. }else if(img.dataset && img.dataset.lazy){
  1568. realSrc=img.dataset.lazy;
  1569. }else if(img.dataset && img.dataset.src){
  1570. realSrc=img.dataset.src;
  1571. }else if(img._lazyrias && img._lazyrias.srcset){
  1572. realSrc=img._lazyrias.srcset[img._lazyrias.srcset.length-1];
  1573. }else if(img.dataset && img.dataset.origFile){
  1574. realSrc=img.dataset.origFile;
  1575. }else if(img.srcset){
  1576. var srcs=img.srcset.split(/[xw],/),largeSize=0;
  1577. srcs.forEach(srci=>{
  1578. let srcInfo=srci.trim().split(" "),curSize=parseInt(srcInfo[1]);
  1579. if(srcInfo[1] && curSize>largeSize){
  1580. largeSize=curSize;
  1581. realSrc=srcInfo[0];
  1582. }
  1583. });
  1584. }
  1585. if(realSrc){
  1586. img.src=realSrc;
  1587. img.style.display="block";
  1588. img.style.opacity=1;
  1589. }
  1590. };
  1591. [].forEach.call(eles, ele=>{
  1592. if(ele.tagName=="IMG"){
  1593. setLazyImg(ele);
  1594. }else{
  1595. [].forEach.call(ele.querySelectorAll("img"), img=>{
  1596. setLazyImg(img);
  1597. });
  1598. [].forEach.call(ele.querySelectorAll("div[data-src][data-thumb]"), div=>{
  1599. div.style.setProperty("background-image", "url("+div.dataset.src+")", "important");
  1600. });
  1601. }
  1602. if(ele.tagName=="A" && ele.classList.contains("lazyload")){
  1603. if(ele.dataset.original){
  1604. ele.style.backgroundImage='url("'+ele.dataset.original+'")';
  1605. }
  1606. }else{
  1607. [].forEach.call(ele.querySelectorAll("a.lazyload"), a=>{
  1608. if(a.dataset.original){
  1609. a.style.backgroundImage='url("'+a.dataset.original+'")';
  1610. }
  1611. });
  1612. }
  1613. });
  1614. let lazyImgSrc=this.curSiteRule.lazyImgSrc;
  1615. if(lazyImgSrc){
  1616. [].forEach.call(eles, ele=>{
  1617. [].forEach.call(ele.querySelectorAll("img"), img=>{
  1618. if(img.getAttribute(lazyImgSrc)){
  1619. img.src=img.getAttribute(lazyImgSrc);
  1620. }
  1621. });
  1622. });
  1623. }
  1624. }
  1625.  
  1626. initPage(callback){
  1627. let self=this;
  1628. curPage=1;
  1629. //if(this.curSiteRule.url && !this.curSiteRule.singleUrl)return;
  1630. this.curSiteRule={};
  1631. this.pageDoc=document;
  1632. this.nextLinkHref=null;
  1633. this.curUrl=location.href;
  1634. this.getRule(()=>{
  1635. if(self.curSiteRule.enable==0){
  1636. debug("Stop as rule disable");
  1637. isPause=true;
  1638. return;
  1639. }
  1640. //若是再亂匹配就不緩存wedata,或者只在找完本地規則之後再考慮wedata的緩存
  1641. if(self.curSiteRule && !self.curSiteRule.singleUrl && self.curSiteRule.url.length>13){
  1642. self.hpRules=self.hpRules.filter(item=>{return item&&item.url!=self.curSiteRule.url});
  1643. self.hpRules.unshift(self.curSiteRule);
  1644. if(self.hpRules.length>30){
  1645. self.hpRules.pop();
  1646. }
  1647. storage.setItem("hpRules", self.hpRules);
  1648. }
  1649. let css=self.curSiteRule.css || rulesData.customCss;
  1650. if(css && !/^inIframe:/.test(css)){
  1651. _GM_addStyle(css);
  1652. }
  1653. let autoClick=self.curSiteRule.autoClick;
  1654. if(autoClick){
  1655. let autoClickBtn;
  1656. try{
  1657. autoClickBtn=document.querySelector(autoClick);
  1658. }catch(e){
  1659. autoClickBtn=getElementByXpath(autoClick);
  1660. }
  1661. if(autoClickBtn){
  1662. emuClick(autoClickBtn);
  1663. }
  1664. }
  1665. let code=self.curSiteRule.init;
  1666. if(code){
  1667. try{
  1668. ((typeof _unsafeWindow.pagetualInit=='undefined') ? Function('doc','win','iframe','"use strict";' + code) : _unsafeWindow.pagetualInit)(null,null,null);
  1669. }catch(e){
  1670. debug(e);
  1671. }
  1672. }
  1673. self.getNextLink(document);
  1674. callback();
  1675. });
  1676. }
  1677.  
  1678. insertElement(ele) {
  1679. if(this.curSiteRule.insertPos==2){
  1680. this.insert.appendChild(ele);
  1681. }else{
  1682. this.insert.parentNode.insertBefore(ele, this.insert);
  1683. }
  1684. }
  1685.  
  1686. insertPage(doc, eles, url, callback, tried){
  1687. this.oldUrl=this.curUrl;
  1688. let oldTitle=this.pageDoc.title;
  1689. this.pageDoc=doc;
  1690. this.curUrl=url;
  1691. let nextLink=this.getNextLink(doc);
  1692. this.nextTitle="";
  1693. if(this.curSiteRule.pageBarText){
  1694. if(this.curSiteRule.pageBarText==1 || this.curSiteRule.pageBarText==true){
  1695. this.nextTitle=doc.title;
  1696. }else{
  1697. try{
  1698. this.nextTitle=((typeof _unsafeWindow.pagetualPageBarText=='undefined') ? Function("doc",'"use strict";' + this.curSiteRule.pageBarText) : _unsafeWindow.pagetualPageBarText)(doc);
  1699. }catch(e){
  1700. debug(e);
  1701. }
  1702. }
  1703. }
  1704. if(curPage==1 && !tried && !nextLink && this.curSiteRule.singleUrl && this.curSiteRule.pageElement && this.curSiteRule.action!=0){
  1705. this.curSiteRule.action=1;
  1706. this.curUrl=location.href;
  1707. return false;
  1708. }
  1709. if(callback)callback(eles);
  1710. this.getInsert();
  1711. var self=this,newEles=[];
  1712. if(!eles || eles.length==0 || !self.insert || !self.insert.parentNode){
  1713. }else{
  1714. this.pageInit(doc, eles);
  1715. [].forEach.call(eles, ele=>{
  1716. let newEle=ele.cloneNode(true);
  1717. let oldCanvass=ele.querySelectorAll("canvas");
  1718. let newCanvass=newEle.querySelectorAll("canvas");
  1719. for(let i=0;i<oldCanvass.length;i++){
  1720. let oldCanvas=oldCanvass[i];
  1721. let newCanvas=newCanvass[i];
  1722. newCanvas.getContext('2d').drawImage(oldCanvas, 0, 0);
  1723. }
  1724. self.insertElement(newEle);
  1725. newEles.push(newEle);
  1726. });
  1727. }
  1728. this.pageAction(doc, newEles);
  1729. if(this.oldUrl!=location.href){
  1730. let isJs=/^(javascript|#)/.test(this.oldUrl.replace(location.href,""));
  1731. let enableHistory = this.curSiteRule.history;
  1732. if (enableHistory == 1) {
  1733. enableHistory = true;
  1734. } else if (enableHistory == 0) {
  1735. enableHistory = false;
  1736. } else {
  1737. enableHistory = rulesData.enableHistory;
  1738. }
  1739. if(enableHistory && !isJs){
  1740. _unsafeWindow.history.replaceState(undefined, oldTitle, this.oldUrl);
  1741. document.title=oldTitle;
  1742. }
  1743. }
  1744. return true;
  1745. }
  1746. }
  1747. var ruleParser = new RuleParser();
  1748.  
  1749. class Picker {
  1750. static picker;
  1751. constructor() {
  1752. this.init();
  1753. }
  1754.  
  1755. static getInstance() {
  1756. if (!Picker.picker) {
  1757. Picker.picker = new Picker();
  1758. }
  1759. return Picker.picker;
  1760. }
  1761.  
  1762. init() {
  1763. let self = this;
  1764. this.signList = [];
  1765. let cssText = `
  1766. body.pagetual-picker,
  1767. body.pagetual-picker *:hover,
  1768. body.pagetual-picker a:hover {
  1769. cursor: crosshair !important;
  1770. }
  1771. #pagetual-picker {
  1772. position: fixed;
  1773. top: 0;
  1774. left: calc(50% - 160px);
  1775. background: aliceblue;
  1776. padding: 10px;
  1777. border-radius: 5px;
  1778. text-align: center;
  1779. opacity: 0.95;
  1780. color: #161616;
  1781. z-index: 2147483647;
  1782. }
  1783. #pagetual-picker>.title {
  1784. margin: -5px 35px 10px 35px;
  1785. font-size: 20px;
  1786. font-weight: bold;
  1787. cursor: move;
  1788. border-bottom: 1px solid black;
  1789. user-select: none;
  1790. }
  1791. #pagetual-picker button {
  1792. background: none;
  1793. border: none;
  1794. vertical-align: top;
  1795. transition: transform .15s ease-in-out;
  1796. float: right;
  1797. }
  1798. #pagetual-picker button:hover {
  1799. transform: scale(1.2);
  1800. }
  1801. #pagetual-picker>.close {
  1802. position: absolute;
  1803. top: 1px;
  1804. right: 10px;
  1805. }
  1806. #pagetual-picker>.selector{
  1807. display: inline-block;
  1808. width: 250px;
  1809. height: 20px;
  1810. padding: 6px 12px;
  1811. font-size: 16px;
  1812. font-weight: 400;
  1813. line-height: 1.5;
  1814. color: #495057;
  1815. background-color: #fff;
  1816. background-clip: padding-box;
  1817. border: 1px solid #ced4da;
  1818. border-radius: 4px;
  1819. transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;
  1820. box-sizing: content-box;
  1821. }
  1822. #pagetual-picker>.selector:focus {
  1823. color: #495057;
  1824. background-color: #fff;
  1825. border-color: #80bdff;
  1826. outline: 0;
  1827. box-shadow: 0 0 0 3.2px rgb(0 123 255 / 25%);
  1828. }
  1829. #pagetual-picker .xpath {
  1830. line-height: 20px;
  1831. height: 25px;
  1832. width: 25px;
  1833. margin-left: 5px;
  1834. }
  1835. #pagetual-picker label {
  1836. font-size: 18px;
  1837. line-height: 25px;
  1838. vertical-align: top;
  1839. display: inline-block;
  1840. }
  1841. #pagetual-picker .bottom {
  1842. text-align: left;
  1843. margin-top: 10px;
  1844. }
  1845. #pagetual-picker .bottom>button {
  1846. float: right;
  1847. }
  1848. #pagetual-picker svg {
  1849. width: 30px;
  1850. height: 30px;
  1851. vertical-align: middle;
  1852. fill: #161616;
  1853. overflow: hidden;
  1854. }
  1855. #pagetual-picker .allpath {
  1856. font-size: 18px;
  1857. margin: 10px;
  1858. max-width: 300px;
  1859. word-break: break-all;
  1860. cursor: context-menu;
  1861. }
  1862. #pagetual-picker .allpath>span.path {
  1863. cursor: pointer;
  1864. }
  1865. #pagetual-picker .allpath>span.path:hover {
  1866. color: orangered;
  1867. }
  1868. `;
  1869. _GM_addStyle(cssText);
  1870. this.mainSignDiv = this.createSignDiv();
  1871. this.allSignDiv = [];
  1872. let frame = document.createElement("div");
  1873. frame.id = "pagetual-picker";
  1874. frame.innerHTML = createHTML(`
  1875. <div class="title">${i18n("picker")}</div>
  1876. <button title="${i18n("closePicker")}" type="button" class="close">
  1877. <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2754">
  1878. <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">
  1879. </path>
  1880. </svg>
  1881. </button>
  1882. <div class="allpath"></div>
  1883. <input class="selector" name="selector" type="text" placeholder="${i18n("pickerPlaceholder")}">
  1884. <button id="check" title="${i18n("pickerCheck")}" type="button">
  1885. <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1609">
  1886. <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">
  1887. </path>
  1888. </svg>
  1889. </button>
  1890. <div class="bottom">
  1891. <input class="xpath" name="xpath" id="checkbox_id" type="checkbox">
  1892. <label for="checkbox_id">XPath</label>
  1893. <button id="edit" title="${i18n("gotoEdit")}" type="button">
  1894. <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4129" style="color: orangered;fill: orangered;">
  1895. <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">
  1896. </path>
  1897. </svg>
  1898. </button>
  1899. </div>
  1900. `);
  1901. let closeBtn = frame.querySelector(".close");
  1902. let title = frame.querySelector(".title");
  1903. let allpath = frame.querySelector(".allpath");
  1904. let selectorInput = frame.querySelector(".selector");
  1905. let xpath = frame.querySelector(".xpath");
  1906. let checkBtn = frame.querySelector("#check");
  1907. let editBtn = frame.querySelector("#edit");
  1908. closeBtn.addEventListener("click", e => {
  1909. self.close();
  1910. }, true);
  1911. let moveHanlder = e => {
  1912. frame.style.left = e.clientX - 160 + "px";
  1913. frame.style.top = e.clientY - 15 + "px";
  1914. e.stopPropagation();
  1915. e.preventDefault();
  1916. };
  1917. let upHanlder = e => {
  1918. document.removeEventListener("mousemove", moveHanlder, true);
  1919. title.removeEventListener("mouseup", upHanlder, true);
  1920. e.stopPropagation();
  1921. e.preventDefault();
  1922. };
  1923. title.addEventListener("mousedown", e => {
  1924. document.addEventListener("mousemove", moveHanlder, true);
  1925. title.addEventListener("mouseup", upHanlder, true);
  1926. });
  1927. frame.addEventListener("mouseenter", e => {
  1928. if (self.mainSignDiv.parentNode) self.mainSignDiv.parentNode.removeChild(self.mainSignDiv);
  1929. self.checkInputSelector();
  1930. });
  1931. frame.addEventListener("mouseleave", e => {
  1932. document.body.appendChild(self.mainSignDiv);
  1933. self.clearSigns();
  1934. });
  1935. checkBtn.addEventListener("click", e => {
  1936. self.checkInputSelector();
  1937. });
  1938. xpath.addEventListener("click", e => {
  1939. if (!selectorInput.value) {
  1940. self.setSelectorDiv("");
  1941. return;
  1942. }
  1943. let element = !xpath.checked ? getElementByXpath(selectorInput.value) : document.querySelector(selectorInput.value);
  1944. let selector = self.getSelectorFromEle(element);
  1945. self.setSelectorDiv(selector);
  1946. selectorInput.value = selector;
  1947. });
  1948. editBtn.addEventListener("click", e => {
  1949. let editTemp;
  1950. if(ruleParser.curSiteRule.url && !ruleParser.curSiteRule.singleUrl){
  1951. editTemp=ruleParser.curSiteRule;
  1952. }else{
  1953. editTemp={
  1954. name: document.title,
  1955. url: "^"+location.origin.replace(/\./g,"\\.")
  1956. };
  1957. }
  1958. if (selectorInput.value) {
  1959. editTemp.pageElement = selectorInput.value;
  1960. let preType = editTemp.type === 0;
  1961. if (xpath.checked !== preType) editTemp.type = xpath.checked ? 0 : 1;
  1962. }
  1963. rulesData.editTemp=editTemp;
  1964. storage.setItem("rulesData", rulesData);
  1965. _GM_openInTab(configPage, {active: true});
  1966. });
  1967. this.frame = frame;
  1968. this.xpath = xpath;
  1969. this.allpath = allpath;
  1970. this.selectorInput = selectorInput;
  1971. this.moveHandler = e => {
  1972. if (e.target === document) return;
  1973. self.adjustSignDiv(self.mainSignDiv, self.getTarget(e.target));
  1974. };
  1975. this.clickHandler = e => {
  1976. if (self.inPicker) {
  1977. e.stopPropagation();
  1978. e.preventDefault();
  1979. }
  1980. let target = self.getTarget(e.target);
  1981. let selector = self.getSelectorFromEle(target);
  1982. self.setSelectorDiv(selector);
  1983. selectorInput.value = selector;
  1984. };
  1985. }
  1986.  
  1987. getTarget(ele) {
  1988. while (ele.parentNode && (ele.scrollWidth === 0 || ele.scrollHeight === 0)) {
  1989. ele = ele.parentNode;
  1990. }
  1991. return ele;
  1992. }
  1993.  
  1994. close() {
  1995. this.clearSigns();
  1996. if (this.frame.parentNode) this.frame.parentNode.removeChild(this.frame);
  1997. if (this.mainSignDiv.parentNode) this.mainSignDiv.parentNode.removeChild(this.mainSignDiv);
  1998. document.body.classList.remove("pagetual-picker");
  1999. document.body.removeEventListener("mousemove", this.moveHandler, true);
  2000. document.body.removeEventListener("click", this.clickHandler, true);
  2001. this.inPicker = false;
  2002. }
  2003.  
  2004. setImportant(ele, prop, value) {
  2005. ele.style.setProperty(prop, value, "important");
  2006. }
  2007.  
  2008. createSignDiv() {
  2009. let signDiv = document.createElement("div");
  2010. this.setImportant(signDiv, "position", "absolute");
  2011. this.setImportant(signDiv, "pointer-events", "none");
  2012. this.setImportant(signDiv, "z-index", "2147483647");
  2013. this.setImportant(signDiv, "background", "rgba(120, 170, 210, 0.6)");
  2014. this.setImportant(signDiv, "transition", "all 0.15s ease-out");
  2015. this.setImportant(signDiv, "box-shadow", "rgb(0 0 0) 0px 0px 3px 0px");
  2016. return signDiv;
  2017. }
  2018.  
  2019. adjustSignDiv(div, target) {
  2020. let rect = target.getBoundingClientRect();
  2021. this.setImportant(div, "width", rect.width + "px");
  2022. this.setImportant(div, "height", rect.height + "px");
  2023. this.setImportant(div, "left", rect.left + window.scrollX + "px");
  2024. this.setImportant(div, "top", rect.top + window.scrollY + "px");
  2025. }
  2026.  
  2027. getSelectorFromEle(ele) {
  2028. return this.xpath.checked ? createXPathFromElement(ele) : geneSelector(ele, true);
  2029. }
  2030.  
  2031. setSelectorDiv(selector) {
  2032. let self = this;
  2033. this.allpath.innerHTML = createHTML("");
  2034. if (!selector) return;
  2035. if (this.xpath.checked) {
  2036. let span = document.createElement("span");
  2037. span.innerText = selector;
  2038. span.addEventListener("click", e => {
  2039. self.selectorInput.value = selector;
  2040. self.checkInputSelector();
  2041. }, true);
  2042. this.allpath.appendChild(span);
  2043. } else {
  2044. selector.split(">").forEach(i => self.geneSelectorItem(i));
  2045. }
  2046. }
  2047.  
  2048. geneSelectorItem(item) {
  2049. let self = this;
  2050. item = item.trim();
  2051. if (!item) return;
  2052. if (item !== "body") {
  2053. let span = document.createElement("span");
  2054. span.innerText = " > ";
  2055. this.allpath.appendChild(span);
  2056. }
  2057. let span = document.createElement("span");
  2058. span.className = "path";
  2059. span.innerText = item;
  2060. span.addEventListener("click", e => {
  2061. let selector = "";
  2062. let target = e.target;
  2063. while (target) {
  2064. selector = target.innerText + selector;
  2065. target = target.previousElementSibling;
  2066. }
  2067. self.selectorInput.value = selector;
  2068. self.checkInputSelector();
  2069. }, true);
  2070. this.allpath.appendChild(span);
  2071. }
  2072.  
  2073. checkInputSelector() {
  2074. let self = this;
  2075. this.clearSigns();
  2076. if (!this.selectorInput.value) return;
  2077. let eles = this.xpath.checked ? getAllElementsByXpath(this.selectorInput.value) : document.querySelectorAll(this.selectorInput.value);
  2078. if (eles && eles.length > 0) {
  2079. eles.forEach(ele => {
  2080. let sign = self.createSignDiv();
  2081. document.body.appendChild(sign);
  2082. self.adjustSignDiv(sign, ele);
  2083. self.signList.push(sign);
  2084. });
  2085. }
  2086. }
  2087.  
  2088. clearSigns() {
  2089. this.signList.forEach(sign => {
  2090. if (sign.parentNode) sign.parentNode.removeChild(sign);
  2091. });
  2092. this.signList = [];
  2093. }
  2094.  
  2095. start() {
  2096. if (this.inPicker) return;
  2097. this.inPicker = true;
  2098. document.documentElement.appendChild(this.frame);
  2099. document.body.appendChild(this.mainSignDiv);
  2100. document.body.classList.add("pagetual-picker");
  2101.  
  2102. document.body.addEventListener("mousemove", this.moveHandler, true);
  2103. document.body.addEventListener("click", this.clickHandler, true);
  2104. this.xpath.checked = ruleParser.curSiteRule.type === 0;
  2105. this.setSelectorDiv(ruleParser.curSiteRule.pageElement || "");
  2106. }
  2107. }
  2108.  
  2109. function initConfig(){
  2110. initView();
  2111. _GM_registerMenuCommand(i18n(forceState==1?"enable":"disableSite"), ()=>{
  2112. forceState=(forceState==1?0:1);
  2113. storage.setItem("forceState_"+location.host, forceState);
  2114. showTips(i18n(forceState==1?"disableSiteTips":"enableSiteTips"));
  2115. if(!ruleParser.curSiteRule.url) location.reload();
  2116. });
  2117. _GM_registerMenuCommand(i18n("update"), ()=>{
  2118. updateRules(()=>{
  2119. showTips(i18n("updateSucc"));
  2120. location.reload();
  2121. },(rule,err)=>{
  2122. showTips("Update "+rule.url+" rules fail!");
  2123. });
  2124. showTips(i18n("beginUpdate"));
  2125. });
  2126.  
  2127. var configCon,insertPos;
  2128. var noRules=!rulesData.urls || rulesData.urls.length===0;
  2129. if(ruleImportUrlReg.test(location.href)){
  2130. let greasyfork=location.href.indexOf("greasyfork.org") != -1;
  2131. if(noRules){
  2132. setTimeout(() => {
  2133. showTips(i18n("firstAlert"));
  2134. }, 3000);
  2135. setTimeout(() => {
  2136. showTips(i18n("firstAlert"));
  2137. }, 6000);
  2138. showTips(i18n("firstAlert"));
  2139. }
  2140. let importBtn = document.createElement("button"), targetPre;
  2141. importBtn.innerText = i18n("import");
  2142. importBtn.style.marginTop = "100px";
  2143. importBtn.style.float = "right";
  2144. importBtn.style.position = "static";
  2145. importBtn.style.display = "block";
  2146. importBtn.style.fontSize = "20px";
  2147. importBtn.addEventListener("click", e => {
  2148. if (targetPre) {
  2149. if (importBtn.parentNode) importBtn.parentNode.removeChild(importBtn);
  2150. try {
  2151. let rules=targetPre.innerText.trim();
  2152. let isContent=/['"]name['"]/i.test(rules);
  2153. if(isContent){
  2154. let ruleList=JSON.parse(`[${rules}]`);
  2155. for(let i in ruleList){
  2156. let hasRule = false;
  2157. let r = ruleList[i];
  2158. for(let j in ruleParser.customRules){
  2159. if(ruleParser.customRules[j].name == r.name){
  2160. ruleParser.customRules[j] = r;
  2161. hasRule = true;
  2162. break;
  2163. }
  2164. }
  2165. if(!hasRule)ruleParser.customRules.push(r);
  2166. }
  2167. storage.setItem("customRules", ruleParser.customRules);
  2168. showTips(i18n("importSucc"));
  2169. }else{
  2170. rules=rules.split("\n");
  2171. let diff=false;
  2172. for(let c=0;c<rules.length;c++){
  2173. let urlArr=rules[c].split("|"),url,type=1;
  2174. if(urlArr.length==1){
  2175. url=urlArr[0].trim();
  2176. if(!/^http/.test(url)){
  2177. showTips("Wrong url, check again!");
  2178. return;
  2179. }
  2180. }else if(urlArr.length==2){
  2181. type=urlArr[0].trim();
  2182. url=urlArr[1].trim();
  2183. if(!/^http/.test(url)){
  2184. showTips("Wrong url, check again!");
  2185. return;
  2186. }
  2187. }else{
  2188. break;
  2189. }
  2190. let maxId=0,hasUrl=false;
  2191. if(!rulesData.urls){
  2192. rulesData.urls=[];
  2193. maxId=1;
  2194. }else{
  2195. rulesData.urls.forEach(u=>{
  2196. if(maxId<u.id){
  2197. maxId=u.id;
  2198. }
  2199. if(u.url==url){
  2200. hasUrl=true;
  2201. }
  2202. });
  2203. if(hasUrl)break;
  2204. }
  2205. diff=true;
  2206. if(!rulesData.sort)rulesData.sort=[1];
  2207. rulesData.urls.push({id:maxId+1,url:url,type:type});
  2208. rulesData.sort.unshift(maxId+1);
  2209. }
  2210. if(!diff)return;
  2211. storage.setItem("rulesData", rulesData);
  2212.  
  2213. if(rulesData.urls)ruleUrls=ruleUrls.concat(rulesData.urls);
  2214. if(rulesData.sort){
  2215. let urls=[];
  2216. rulesData.sort.forEach(id=>{
  2217. for(let s=0;s<ruleUrls.length;s++){
  2218. if(id==ruleUrls[s].id){
  2219. urls.push(ruleUrls[s]);
  2220. break;
  2221. }
  2222. }
  2223. });
  2224. ruleUrls=urls;
  2225. }
  2226. updateRules(()=>{
  2227. showTips(i18n("updateSucc"));
  2228. location.reload();
  2229. },(rule,err)=>{
  2230. showTips("Update "+rule.url+" rules fail!");
  2231. });
  2232. showTips(i18n("beginUpdate"));
  2233. }
  2234. } catch (e) {
  2235. _GM_notification(e.toString());
  2236. }
  2237. }
  2238. });
  2239. document.addEventListener("mouseover", e => {
  2240. if (e.target.tagName === "PRE") {
  2241. let nameAttr=e.target.getAttribute("name");
  2242. if(nameAttr=="pagetual" || nameAttr=="user-content-pagetual" || greasyfork){
  2243. targetPre = e.target;
  2244. importBtn.style.marginTop = `${35 - e.target.clientHeight}px`;
  2245. e.target.appendChild(importBtn);
  2246. }
  2247. }
  2248. });
  2249.  
  2250. if(location.href==configPage){
  2251. _GM_addStyle(`
  2252. p>span:nth-child(1),p>span:nth-child(2),p>span:nth-child(3){
  2253. cursor: pointer;
  2254. user-select: none;
  2255. }
  2256. p>span:nth-child(1):hover,p>span:nth-child(2):hover,p>span:nth-child(3):hover{
  2257. color:red;
  2258. }
  2259. .updateDate{
  2260. cursor: pointer;
  2261. user-select: none;
  2262. }
  2263. .updateDate:hover{
  2264. color:red;
  2265. }
  2266. `);
  2267. document.querySelector("[name='user-content-click2import']").innerText=i18n("click2ImportRule")
  2268. configCon=document.querySelector(".markdown-body");
  2269. insertPos=configCon.querySelector("hr");
  2270.  
  2271. if(!noRules){
  2272. document.querySelector("pre[name='user-content-pagetual']").style.display="none";
  2273. document.querySelector("p[name='user-content-click2import']").style.display="none";
  2274. }
  2275. }else return true;
  2276. }else return false;
  2277. class Rulebar {
  2278. init(ruleUrl){
  2279. this.ruleUrl=ruleUrl;
  2280. this.item=document.createElement("p");
  2281. this.item.dataset.id=this.ruleUrl.id;
  2282. let url=document.createElement("span");
  2283. url.innerHTML=ruleUrl.url;
  2284. let up=document.createElement("span");
  2285. up.innerHTML="↑ ";
  2286. up.title=i18n("sortTitle");
  2287. let down=document.createElement("span");
  2288. down.innerHTML="↓ ";
  2289. down.title=i18n("sortTitle");
  2290. let del=document.createElement("span");
  2291. del.innerHTML="× ";
  2292. up.onclick=e=>{
  2293. this.moveUp();
  2294. };
  2295. down.onclick=e=>{
  2296. this.moveDown();
  2297. };
  2298. del.onclick=e=>{
  2299. this.del();
  2300. };
  2301. this.item.appendChild(up);
  2302. this.item.appendChild(down);
  2303. this.item.appendChild(del);
  2304. this.item.appendChild(url);
  2305. configCon.insertBefore(this.item, insertPos);
  2306. }
  2307. saveSort(){
  2308. let sort=[];
  2309. [].forEach.call(this.item.parentNode.querySelectorAll("p[data-id]"), i=>{
  2310. sort.push(i.dataset.id);
  2311. });
  2312. rulesData.sort=sort;
  2313. storage.setItem("rulesData", rulesData);
  2314. }
  2315. moveUp(){
  2316. let preE=this.item.previousElementSibling;
  2317. if(preE.tagName=="P" && preE.children.length>1){
  2318. this.item.parentNode.insertBefore(this.item,preE);
  2319. this.saveSort();
  2320. }
  2321. }
  2322. moveDown(){
  2323. let nextE=this.item.nextElementSibling;
  2324. if(nextE.tagName=="P" && nextE.children.length>1){
  2325. this.item.parentNode.insertBefore(nextE,this.item);
  2326. this.saveSort();
  2327. }
  2328. }
  2329. del(){
  2330. if(this.ruleUrl.id<2){
  2331. showTips(i18n("cantDel"));
  2332. }else if(window.confirm(i18n("confirmDel"))){
  2333. for(let u=0;u<rulesData.urls.length;u++){
  2334. if(this.ruleUrl.id==rulesData.urls[u].id){
  2335. rulesData.urls.splice(u,1);
  2336. break;
  2337. }
  2338. }
  2339. for(let u=0;u<ruleUrls.length;u++){
  2340. if(this.ruleUrl.id==ruleUrls[u].id){
  2341. ruleUrls.splice(u,1);
  2342. break;
  2343. }
  2344. }
  2345. for(let u=0;u<rulesData.sort.length;u++){
  2346. if(this.ruleUrl.id==rulesData.sort[u]){
  2347. rulesData.sort.splice(u,1);
  2348. break;
  2349. }
  2350. }
  2351. storage.setItem("rulesData", rulesData);
  2352. ruleParser.rules=ruleParser.rules.filter(item=>{return item.from!=this.ruleUrl.id});
  2353. storage.setItem("rules", ruleParser.rules);
  2354. this.item.parentNode.removeChild(this.item);
  2355. //location.reload();
  2356. }
  2357. }
  2358. }
  2359. let updateP=document.createElement("p"),i=0;
  2360. let now=new Date().getTime(),inUpdate=false;
  2361.  
  2362.  
  2363. let pastDate=(new Date(updateDate)).toString(),passStr;
  2364. let passTime=(now-updateDate)/1000;
  2365. if(isNaN(passTime)){
  2366. passStr=i18n("firstUpdate");
  2367. }else if(passTime<60){
  2368. passStr=i18n("passSec", parseInt(passTime))+" 👆 "+i18n("click2update");
  2369. }else if(passTime<60*60){
  2370. passStr=i18n("passMin", parseInt(passTime/60))+" 👆 "+i18n("click2update");
  2371. }else if(passTime<60*60*24){
  2372. passStr=i18n("passHour", parseInt(passTime/3600))+" 👆 "+i18n("click2update");
  2373. }else{
  2374. passStr=i18n("passDay", parseInt(passTime/86400))+" 👆 "+i18n("click2update");
  2375. }
  2376.  
  2377.  
  2378. updateP.className="updateDate";
  2379. updateP.innerHTML=passStr;
  2380. updateP.title=i18n("update")+" - "+pastDate;
  2381. updateP.onclick=e=>{
  2382. updateRules(()=>{
  2383. showTips(i18n("updateSucc"));
  2384. updateP.innerHTML=i18n("passSec", 0);
  2385. updateP.title=i18n("update");
  2386. },(rule,err)=>{
  2387. showTips("Update "+rule.url+" rules fail!");
  2388. });
  2389. showTips(i18n("beginUpdate"));
  2390. };
  2391. configCon.insertBefore(updateP, insertPos);
  2392. if(ruleUrls){
  2393. ruleUrls.forEach(ruleUrl=>{
  2394. var rulebar=new Rulebar();
  2395. rulebar.init(ruleUrl);
  2396. });
  2397. }
  2398. let customUrlsTitle=document.createElement("h2");
  2399. customUrlsTitle.innerHTML=i18n("customUrls");
  2400. configCon.insertBefore(customUrlsTitle, insertPos);
  2401. let customUrlsInput=document.createElement("textarea");
  2402. customUrlsInput.style.width="100%";
  2403. customUrlsInput.placeholder="http://wedata.net/databases/AutoPagerize/items_all.json";
  2404. configCon.insertBefore(customUrlsInput, insertPos);
  2405.  
  2406. let upBtnImg=document.createElement("div");
  2407. upBtnImg.style.width="35%";
  2408. upBtnImg.style.float="left";
  2409. let upBtnImgTitle=document.createElement("h2");
  2410. upBtnImgTitle.style.whiteSpace="nowrap";
  2411. upBtnImgTitle.style.overflow="auto";
  2412. upBtnImgTitle.innerHTML=i18n("upBtnImg");
  2413. upBtnImg.appendChild(upBtnImgTitle);
  2414. let upBtnImgInput=document.createElement("input");
  2415. upBtnImgInput.style.width="100%";
  2416. upBtnImgInput.placeholder="data:image/png;base64,UpBtn";
  2417. upBtnImgInput.value=rulesData.upBtnImg||'';
  2418. upBtnImg.appendChild(upBtnImgInput);
  2419. configCon.insertBefore(upBtnImg, insertPos);
  2420.  
  2421. let downBtnImg=document.createElement("div");
  2422. downBtnImg.style.width="35%";
  2423. downBtnImg.style.float="left";
  2424. let downBtnImgTitle=document.createElement("h2");
  2425. downBtnImgTitle.style.whiteSpace="nowrap";
  2426. downBtnImgTitle.style.overflow="auto";
  2427. downBtnImgTitle.innerHTML=i18n("downBtnImg");
  2428. downBtnImg.appendChild(downBtnImgTitle);
  2429. let downBtnImgInput=document.createElement("input");
  2430. downBtnImgInput.style.width="100%";
  2431. downBtnImgInput.placeholder="data:image/png;base64,DownBtn";
  2432. downBtnImgInput.value=rulesData.downBtnImg||'';
  2433. downBtnImg.appendChild(downBtnImgInput);
  2434. configCon.insertBefore(downBtnImg, insertPos);
  2435.  
  2436. let loadingText=document.createElement("div");
  2437. loadingText.style.width="20%";
  2438. loadingText.style.float="left";
  2439. let loadingTextTitle=document.createElement("h2");
  2440. loadingTextTitle.style.whiteSpace="nowrap";
  2441. loadingTextTitle.style.overflow="auto";
  2442. loadingTextTitle.innerHTML=i18n("loadingTextTitle");
  2443. loadingText.appendChild(loadingTextTitle);
  2444. let loadingTextInput=document.createElement("input");
  2445. loadingTextInput.value=rulesData.loadingText||'';
  2446. loadingTextInput.placeholder=i18n("loadingText");
  2447. loadingTextInput.style.width="100%";
  2448. loadingTextInput.style.margin="0";
  2449. loadingText.appendChild(loadingTextInput);
  2450. configCon.insertBefore(loadingText, insertPos);
  2451.  
  2452. let opacity=document.createElement("div");
  2453. opacity.style.width="10%";
  2454. opacity.style.float="left";
  2455. opacity.style.marginBottom="30px";
  2456. let opacityTitle=document.createElement("h2");
  2457. opacityTitle.style.whiteSpace="nowrap";
  2458. opacityTitle.style.overflow="visible";
  2459. opacityTitle.innerHTML=i18n("opacity");
  2460. opacity.appendChild(opacityTitle);
  2461. let opacityInput=document.createElement("input");
  2462. opacityInput.value=rulesData.opacity*100;
  2463. opacityInput.type="number";
  2464. opacityInput.style.width="95px";
  2465. opacityInput.style.margin="0";
  2466. opacityInput.placeholder=i18n("opacityPlaceholder");
  2467. opacity.appendChild(opacityInput);
  2468. configCon.insertBefore(opacity, insertPos);
  2469.  
  2470. let pageElementCss=document.createElement("div");
  2471. pageElementCss.style.marginBottom="30px";
  2472. let pageElementCssTitle=document.createElement("h2");
  2473. pageElementCssTitle.innerHTML=i18n("pageElementCss");
  2474. pageElementCss.appendChild(pageElementCssTitle);
  2475. let pageElementCssInput=document.createElement("input");
  2476. pageElementCssInput.value=rulesData.pageElementCss||'';
  2477. pageElementCssInput.style.width="100%";
  2478. pageElementCssInput.style.margin="0";
  2479. pageElementCssInput.placeholder="font-size: xx-large;";
  2480. pageElementCss.appendChild(pageElementCssInput);
  2481. configCon.insertBefore(pageElementCss, insertPos);
  2482.  
  2483. let customCss=document.createElement("div");
  2484. customCss.style.marginBottom="50px";
  2485. let customCssTitle=document.createElement("h2");
  2486. customCssTitle.innerHTML=i18n("customCss");
  2487. customCss.appendChild(customCssTitle);
  2488. let customCssInput=document.createElement("textarea");
  2489. customCssInput.value=rulesData.customCss||'';
  2490. customCssInput.style.width="100%";
  2491. customCssInput.style.margin="0";
  2492. customCssInput.placeholder=".pagetual{\n}";
  2493. customCss.appendChild(customCssInput);
  2494. configCon.insertBefore(customCss, insertPos);
  2495.  
  2496. let configTable=document.createElement("table");
  2497. configTable.style.width="100%";
  2498. let configTbody=document.createElement("tbody");
  2499. configTbody.style.width="100%";
  2500. configTbody.style.display="inline-table";
  2501. configTable.appendChild(configTbody);
  2502. configCon.insertBefore(configTable, insertPos);
  2503. function createCheckbox(innerText, val, tag, parentCheck, otherType){
  2504. if (typeof val == 'undefined') val = "";
  2505. let title=document.createElement(tag||"h3");
  2506. title.innerHTML=innerText;
  2507. let input=document.createElement("input");
  2508. input.type=otherType||"checkbox";
  2509. input.style.width="50px";
  2510. input.style.height="20px";
  2511. input.value=val;
  2512. input.checked=val;
  2513. let td=document.createElement("td");
  2514. td.appendChild(input);
  2515. if(parentCheck){
  2516. td.appendChild(title);
  2517. let parent=parentCheck.parentNode.nextElementSibling;
  2518. let tr=parent.querySelector("tr");
  2519. if(!tr){
  2520. tr=document.createElement("tr");
  2521. parent.appendChild(tr);
  2522. }
  2523. tr.appendChild(td);
  2524. if(!parentCheck.checked){
  2525. td.style.display="none";
  2526. }
  2527. parentCheck.addEventListener("click", e=>{
  2528. td.style.display=parentCheck.checked?"":"none";
  2529. });
  2530. }else{
  2531. let tr=document.createElement("tr");
  2532. tr.appendChild(td);
  2533. td=document.createElement("td");
  2534. td.appendChild(title);
  2535. tr.appendChild(td);
  2536. configTable.children[0].appendChild(tr);
  2537. }
  2538. return input;
  2539. }
  2540.  
  2541. let enableWhiteListInput=createCheckbox(i18n("autoRun"), rulesData.enableWhiteList!=true);
  2542. let enableDebugInput=createCheckbox(i18n("enableDebug"), rulesData.enableDebug!=false);
  2543. let enableHistoryInput=createCheckbox(i18n("enableHistory"), rulesData.enableHistory===true);
  2544. let openInNewTabInput=createCheckbox(i18n("openInNewTab"), rulesData.openInNewTab!=false);
  2545. let initRunInput=createCheckbox(i18n("initRun"), rulesData.initRun!=false);
  2546. let preloadInput=createCheckbox(i18n("preload"), rulesData.preload!=false);
  2547. let dbClick2StopInput=createCheckbox(i18n("dbClick2Stop"), rulesData.dbClick2Stop);
  2548. let manualModeInput=createCheckbox(i18n("manualMode"), rulesData.manualMode);
  2549. let hideBarInput=createCheckbox(i18n("hideBar"), rulesData.hideBar, "h4", dbClick2StopInput);
  2550. let dbClick2StopCtrlInput=createCheckbox(i18n("dbClick2StopCtrl"), rulesData.dbClick2StopCtrl, "h4", dbClick2StopInput);
  2551. let dbClick2StopAltInput=createCheckbox(i18n("dbClick2StopAlt"), rulesData.dbClick2StopAlt, "h4", dbClick2StopInput);
  2552. let dbClick2StopShiftInput=createCheckbox(i18n("dbClick2StopShift"), rulesData.dbClick2StopShift, "h4", dbClick2StopInput);
  2553. let dbClick2StopMetaInput=createCheckbox(i18n("dbClick2StopMeta"), rulesData.dbClick2StopMeta, "h4", dbClick2StopInput);
  2554. let dbClick2StopKeyInput=createCheckbox(i18n("dbClick2StopKey"), rulesData.dbClick2StopKey, "h4", dbClick2StopInput, "text");
  2555. dbClick2StopKeyInput.setAttribute("maxlength", "1");
  2556.  
  2557. let customRulesTitle=document.createElement("h2");
  2558. customRulesTitle.innerHTML=i18n("customRules");
  2559. configCon.insertBefore(customRulesTitle, insertPos);
  2560. let customRulesInput=document.createElement("textarea");
  2561. configCon.insertBefore(customRulesInput, insertPos);
  2562. if(rulesData.editTemp){
  2563. if(!ruleParser.customRules){
  2564. ruleParser.customRules=[];
  2565. }
  2566. for(let i in ruleParser.customRules){
  2567. if(ruleParser.customRules[i].url==rulesData.editTemp.url){
  2568. ruleParser.customRules.splice(i, 1);
  2569. break;
  2570. }
  2571. }
  2572. ruleParser.customRules.unshift(rulesData.editTemp);
  2573. rulesData.editTemp=null;
  2574. storage.setItem("rulesData", rulesData);
  2575. customRulesInput.previousElementSibling.scrollIntoView();
  2576. }
  2577. customRulesInput.style.width="100%";
  2578. customRulesInput.style.height="800px";
  2579. 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]`;
  2580. customRulesInput.value=getFormatJSON(ruleParser.customRules);
  2581. let blacklistInput=document.createElement("textarea");
  2582. blacklistInput.style.width="100%";
  2583. blacklistInput.style.height="500px";
  2584. blacklistInput.style.display="none";
  2585. blacklistInput.placeholder="http://*.xxx.com/*/y";
  2586. blacklistInput.value=rulesData.blacklist?rulesData.blacklist.join("\n"):"";
  2587. let blacklistBtn=document.createElement("button");
  2588. blacklistBtn.innerText=i18n("editBlacklist");
  2589. blacklistBtn.style.width="100%";
  2590. blacklistBtn.onclick=e=>{
  2591. blacklistInput.style.display=blacklistInput.style.display=="none"?"":"none";
  2592. };
  2593. configCon.insertBefore(blacklistBtn, insertPos);
  2594. configCon.insertBefore(blacklistInput, insertPos);
  2595. let saveBtn=document.createElement("button");
  2596. saveBtn.innerHTML=i18n("save");
  2597. saveBtn.style.width="100%";
  2598. configCon.insertBefore(saveBtn, insertPos);
  2599. saveBtn.onclick=e=>{
  2600. try{
  2601. storage.setItem("hpRules", []);
  2602. if(customRulesInput.value==""){
  2603. storage.setItem("customRules", "");
  2604. }else{
  2605. let customRules=JSON.parse(customRulesInput.value);
  2606. if(Array && Array.isArray && !Array.isArray(customRules)){
  2607. showTips("Rules must be a Array!");
  2608. return;
  2609. }
  2610. debug(customRules);
  2611. storage.setItem("customRules", customRules);
  2612. }
  2613. }catch(e){
  2614. debug(e);
  2615. showTips("JSON error, check again!");
  2616. return;
  2617. }
  2618. rulesData.opacity=opacityInput.value/100;
  2619. rulesData.blacklist=blacklistInput.value?blacklistInput.value.split("\n"):"";
  2620. rulesData.hideBar=hideBarInput.checked;
  2621. rulesData.dbClick2Stop=dbClick2StopInput.checked;
  2622. rulesData.enableWhiteList=!enableWhiteListInput.checked;
  2623. rulesData.enableDebug=enableDebugInput.checked;
  2624. rulesData.enableHistory=enableHistoryInput.checked;
  2625. rulesData.openInNewTab=openInNewTabInput.checked;
  2626. rulesData.initRun=initRunInput.checked;
  2627. rulesData.preload=preloadInput.checked;
  2628. rulesData.manualMode=manualModeInput.checked;
  2629. rulesData.pageElementCss=pageElementCssInput.value;
  2630. rulesData.customCss=customCssInput.value;
  2631. rulesData.upBtnImg=upBtnImgInput.value;
  2632. rulesData.downBtnImg=downBtnImgInput.value;
  2633. rulesData.loadingText=loadingTextInput.value;
  2634. rulesData.dbClick2StopCtrl=dbClick2StopCtrlInput.checked;
  2635. rulesData.dbClick2StopAlt=dbClick2StopAltInput.checked;
  2636. rulesData.dbClick2StopShift=dbClick2StopShiftInput.checked;
  2637. rulesData.dbClick2StopMeta=dbClick2StopMetaInput.checked;
  2638. rulesData.dbClick2StopKey=dbClick2StopKeyInput.value;
  2639. storage.setItem("rulesData", rulesData);
  2640. let customUrls=customUrlsInput.value.trim();
  2641. if(customUrls){
  2642. customUrls=customUrls.split(/\n/);
  2643. for(let c=0;c<customUrls.length;c++){
  2644. let url;
  2645. if(/^0\s*\|/.test(customUrls[c])){
  2646. url=customUrls[c].replace(/^0\s*\|\s*/, "").trim();
  2647. if(!/^http/.test(url)){
  2648. showTips("Wrong url, check again!");
  2649. return;
  2650. }
  2651. }else{
  2652. url=customUrls[c].trim();
  2653. if(!/^http/.test(url)){
  2654. showTips("Wrong url, check again!");
  2655. return;
  2656. }
  2657. }
  2658. let maxId=1,hasUrl=false;
  2659. if(!rulesData.urls){
  2660. rulesData.urls=[];
  2661. }
  2662. ruleUrls.forEach(u=>{
  2663. if(maxId<u.id){
  2664. maxId=u.id;
  2665. }
  2666. if(u.url==url){
  2667. hasUrl=true;
  2668. }
  2669. });
  2670. if(hasUrl)break;
  2671. if(!rulesData.sort)rulesData.sort=[1];
  2672. rulesData.urls.push({id:maxId+1,url:url});
  2673. rulesData.sort.push(maxId+1);
  2674. storage.setItem("rulesData", rulesData);
  2675. }
  2676. }
  2677. showTips("The settings are saved");
  2678. location.reload();
  2679. };
  2680. return true;
  2681. }
  2682.  
  2683. var inUpdate=false;
  2684. function updateRules(success,fail){
  2685. if(inUpdate)return;
  2686. inUpdate=true;
  2687. let ruleIndex=ruleUrls.length-1;
  2688. storage.setItem("hpRules", []);
  2689. function addNextRule(){
  2690. if(ruleIndex<0){
  2691. let now=new Date().getTime();
  2692. storage.setItem("ruleLastUpdate", now);
  2693. storage.setItem("rules", ruleParser.rules);
  2694. inUpdate=false;
  2695. success();
  2696. }else{
  2697. let rule=ruleUrls[ruleIndex--];
  2698. ruleParser.addRuleByUrl(rule.url, rule.id, (json,err)=>{
  2699. if(!json){
  2700. fail(rule,err);
  2701. }
  2702. addNextRule();
  2703. })
  2704. }
  2705. }
  2706. addNextRule();
  2707. }
  2708.  
  2709. function objIsArr(obj) {
  2710. return obj &&
  2711. typeof obj === 'object' &&
  2712. typeof obj.length === 'number' &&
  2713. !(obj.propertyIsEnumerable('length'));
  2714. }
  2715.  
  2716. function isVisible(el, win) {
  2717. if(!el.offsetParent)return false;
  2718. var loopable = true,
  2719. visible = el.tagName && win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  2720. while(loopable && visible) {
  2721. el = el.parentNode;
  2722.  
  2723. if(el && el.tagName && el.tagName!="BODY") {
  2724. visible = win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  2725. }else {
  2726. loopable = false;
  2727. }
  2728. }
  2729. return visible;
  2730. }
  2731.  
  2732. function getElementTop(ele) {
  2733. var actualTop = ele.offsetTop;
  2734. var current = ele.offsetParent;
  2735. while (current) {
  2736. actualTop += current.offsetTop;
  2737. current = current.offsetParent;
  2738. }
  2739. return actualTop;
  2740. }
  2741.  
  2742. function getFormatJSON(obj){
  2743. if(!objIsArr(obj) || obj.length === 0)return "";
  2744. return JSON.stringify(obj, null, 4);
  2745. let ret="[\n";
  2746. let len=obj.length,i=0,isLast;
  2747. obj.forEach(item=>{
  2748. ret+=" {\n";
  2749. let iLen=Object.keys(item).length,j=0;
  2750. for(let key in item){
  2751. isLast=(++j)==iLen;
  2752. let value=item[key];
  2753. if(objIsArr(value)){
  2754. let vstr="[",v=0,vIsLast=false;
  2755. value.forEach(vi=>{
  2756. vIsLast=(++v)==value.length;
  2757. vstr+="\""+vi.replace(/\\/g,"\\\\")+"\""+(vIsLast?"":",");
  2758. });
  2759. vstr+="]";
  2760. ret+=" \""+key+"\":"+vstr+""+(isLast?"":",")+"\n";
  2761. }else{
  2762. if(typeof value=="string"){
  2763. value=value.replace(/\\/g,"\\\\").replace(/"/g,"\\\"");
  2764. value="\""+value+"\"";
  2765. }
  2766. ret+=" \""+key+"\":"+value+""+(isLast?"":",")+"\n";
  2767. }
  2768. }
  2769. isLast=(++i)==len;
  2770. ret+=" }"+(isLast?"":",")+"\n";
  2771. });
  2772. ret+="]";
  2773. return ret;
  2774. }
  2775.  
  2776. function globMatch(first, second) {
  2777. if (first.length == 0 && second.length == 0){
  2778. return true;
  2779. }
  2780.  
  2781. if (first.length > 1 && first[0] == '*' &&
  2782. second.length == 0){
  2783. return false;
  2784. }
  2785.  
  2786. if ((first.length > 1 && first[0] == '?') ||
  2787. (first.length != 0 && second.length != 0 &&
  2788. first[0] == second[0])){
  2789. return globMatch(first.substring(1),
  2790. second.substring(1));
  2791. }
  2792.  
  2793. if (first.length > 0 && first[0] == '*'){
  2794. return globMatch(first.substring(1), second) ||
  2795. globMatch(first, second.substring(1));
  2796. }
  2797.  
  2798. return false;
  2799. }
  2800.  
  2801. function initRules(callback) {
  2802. /*0 wedata格式,1 pagetual格式*/
  2803. ruleUrls=[
  2804. {
  2805. id:1,
  2806. url:'http://wedata.net/databases/AutoPagerize/items_all.json',
  2807. type:0,
  2808. }
  2809. ];var i=0,j=0;
  2810.  
  2811. ruleParser.initSavedRules(()=>{
  2812. storage.getItem("rulesData", data=>{
  2813. if(data){
  2814. rulesData=data;
  2815. if(data.urls)ruleUrls=ruleUrls.concat(data.urls);
  2816. if(data.sort){
  2817. let urls=[];
  2818. data.sort.forEach(id=>{
  2819. for(let s=0;s<ruleUrls.length;s++){
  2820. if(id==ruleUrls[s].id){
  2821. urls.push(ruleUrls[s]);
  2822. break;
  2823. }
  2824. }
  2825. });
  2826. ruleUrls=urls;
  2827. }
  2828. }
  2829. let upBtnImg=rulesData.upBtnImg,downBtnImg=rulesData.downBtnImg;
  2830. if(upBtnImg && downBtnImg){
  2831. downSvgCSS=downSvgCSS.replace("transform: rotate(180deg);","");
  2832. }else if(upBtnImg && !downBtnImg){
  2833. downBtnImg=upBtnImg;
  2834. }else if(downBtnImg && !upBtnImg){
  2835. upBtnImg=downBtnImg;
  2836. }
  2837. if(upBtnImg){
  2838. upSvg=`<img src="${upBtnImg}"/>`;
  2839. }
  2840. if(downBtnImg){
  2841. downSvg=`<img src="${downBtnImg}"/>`;
  2842. }
  2843. setLoadingDiv(rulesData.loadingText || i18n("loadingText"));
  2844. if(typeof(rulesData.opacity)=="undefined"){
  2845. rulesData.opacity=0.3;
  2846. }
  2847. if(typeof(rulesData.hideBar)=="undefined"){
  2848. rulesData.hideBar=false;
  2849. }
  2850. if(typeof(rulesData.dbClick2Stop)=="undefined"){
  2851. rulesData.dbClick2Stop=true;
  2852. }
  2853. if(typeof(rulesData.enableWhiteList)=="undefined"){
  2854. rulesData.enableWhiteList=false;
  2855. }
  2856. if(typeof(rulesData.enableHistory)=="undefined"){
  2857. rulesData.enableHistory=false;
  2858. }
  2859. if(typeof(rulesData.openInNewTab)=="undefined"){
  2860. rulesData.openInNewTab=true;
  2861. }
  2862. if(typeof(rulesData.enableDebug)=="undefined"){
  2863. rulesData.enableDebug=true;
  2864. }
  2865. if(typeof(rulesData.initRun)=="undefined"){
  2866. rulesData.initRun=true;
  2867. }
  2868. if(typeof(rulesData.preload)=="undefined"){
  2869. rulesData.preload=true;
  2870. }
  2871. if(typeof(rulesData.manualMode)=="undefined"){
  2872. rulesData.manualMode=false;
  2873. }
  2874. if(rulesData.blacklist && rulesData.blacklist.length>0){
  2875. for(let b in rulesData.blacklist){
  2876. let curGlob=rulesData.blacklist[b];
  2877. if(globMatch(curGlob, location.href)){
  2878. return;
  2879. }
  2880. }
  2881. }
  2882. enableDebug=rulesData.enableDebug;
  2883. storage.getItem("forceState_"+location.host, v=>{
  2884. storage.getItem("ruleLastUpdate", date=>{
  2885. if(typeof(v)=="undefined"){
  2886. v=(rulesData.enableWhiteList?1:0);
  2887. }
  2888. forceState=v;
  2889. updateDate=date;
  2890. if(initConfig())return;
  2891. if(forceState==1)return;
  2892. let now=new Date().getTime();
  2893. if(!date || now-date>2*24*60*60*1000){
  2894. updateRules(()=>{
  2895. },(rule,err)=>{});
  2896. storage.setItem("ruleLastUpdate", now);
  2897. }
  2898. callback();
  2899. });
  2900. });
  2901. });
  2902. });
  2903. }
  2904.  
  2905. function requestDoc(url, callback){
  2906. _GM_xmlhttpRequest({
  2907. url: url,
  2908. method: 'GET',
  2909. overrideMimeType: 'text/html;charset='+document.charset,
  2910. headers: {
  2911. 'Referer': location.href,
  2912. "Content-Type": "text/html;charset="+document.charset,
  2913. },
  2914. timeout: 5000,
  2915. onload: function(res) {
  2916. var doc=null,response=res.response;
  2917. let preCode=ruleParser.curSiteRule.pageElementPre || ruleParser.curSiteRule.pagePre;
  2918. if(preCode){
  2919. try{
  2920. if (typeof _unsafeWindow.pagetualPagePre!='undefined') {
  2921. response = _unsafeWindow.pagetualPagePre(response);
  2922. } else if (preCode.length == 2) {
  2923. response = response.replace(new RegExp(preCode[0], "gi"), preCode[1]);
  2924. } else {
  2925. response = Function("response",'"use strict";' + preCode)(response);
  2926. }
  2927. }catch(e){
  2928. debug(e);
  2929. }
  2930. }
  2931. try {
  2932. doc=document.implementation.createHTMLDocument('');
  2933. doc.documentElement.innerHTML=response;
  2934. }
  2935. catch (e) {
  2936. debug('parse error'+e.toString());
  2937. }
  2938. let pageElement=ruleParser.getPageElement(doc);
  2939. if(inCors && (!pageElement || pageElement.length==0)){
  2940. ruleParser.curSiteRule.pageElement=allOfBody;
  2941. pageElement=ruleParser.getPageElement(doc);
  2942. ruleParser.getInsert(true);
  2943. }
  2944. //只有1的話怕不是圖片哦
  2945. if(pageElement && (pageElement.length>1 || (pageElement.length==1 && pageElement[0].tagName!="IMG") )){
  2946. let result=ruleParser.insertPage(doc, pageElement, url, callback, false);
  2947. ruleParser.curSiteRule.action=0;
  2948. if(!result){
  2949. ruleParser.curSiteRule.action=1;
  2950. requestFromIframe(url, (doc, eles)=>{
  2951. loadPageOver();
  2952. if(eles){
  2953. ruleParser.insertPage(doc, eles, url, callback, true);
  2954. }
  2955. });
  2956. }
  2957. }else if(ruleParser.curSiteRule.singleUrl || curPage==1){
  2958. ruleParser.curSiteRule.action=1;
  2959. requestFromIframe(url, (doc, eles)=>{
  2960. loadPageOver();
  2961. if(eles){
  2962. ruleParser.insertPage(doc, eles, url, callback, true);
  2963. }
  2964. });
  2965. }else{
  2966. isPause=true;
  2967. callback(false);
  2968. }
  2969. },
  2970. onerror: function(e){
  2971. debug(e);
  2972. callback(false);
  2973. },
  2974. ontimeout: function(e){
  2975. debug(e);
  2976. callback(false);
  2977. }
  2978. });
  2979. }
  2980.  
  2981. function initPage(){
  2982. ruleParser.initPage(()=>{
  2983. if(ruleParser.nextLinkHref){
  2984. let isJs=/^(javascript|#)/.test(ruleParser.nextLinkHref.replace(location.href,""));
  2985. if(!isJs){
  2986. let inForce=(forceState == 2 || forceState == 3);
  2987. _GM_registerMenuCommand(i18n(inForce?"cancelForceIframe":"forceIframe"), ()=>{
  2988. if(inForce){
  2989. storage.setItem("forceState_"+location.host, "");
  2990. }else{
  2991. let _state=ruleParser.curSiteRule.action>0 || confirm(i18n("forceAllBody"))?2:3;
  2992. storage.setItem("forceState_"+location.host, _state);
  2993. }
  2994. location.reload();
  2995. });
  2996. }
  2997. _GM_registerMenuCommand(i18n("loadNow"), ()=>{
  2998. let loadNum=window.prompt(i18n("loadConfirm"), "1");
  2999. if(loadNum==="" || loadNum===null)return;
  3000. autoLoadNum=Math.abs(parseInt(loadNum));
  3001. nextPage();
  3002. });
  3003. }
  3004. initListener();
  3005. if(rulesData.initRun && ruleParser.curSiteRule.initRun!=0)nextPage();
  3006. });
  3007. }
  3008.  
  3009. var pageBarStyle;
  3010. function initView(){
  3011. _GM_addStyle(`
  3012. .pagetual_pageBar{
  3013. -moz-transition:opacity 0.3s ease-in-out 0s;
  3014. -webkit-transition:opacity 0.3s ease-in-out 0s;
  3015. transition:opacity 0.3s ease-in-out 0s;
  3016. }
  3017. .pagetual_pageBar.stop {
  3018. -webkit-filter: invert(100%);
  3019. filter: invert(100%);
  3020. opacity: 1!important;
  3021. }
  3022. .pagetual_pageBar.hide {
  3023. display: none!important;
  3024. }
  3025. .pagetual_pageBar:hover {
  3026. opacity: 1!important;
  3027. }
  3028. .pagetual_pageBar span {
  3029. vertical-align: super;
  3030. }
  3031. .pagetual_pageBar a>span {
  3032. margin-top: 0!important;
  3033. opacity: 0;
  3034. -moz-transition:all 0.3s ease-in-out 0s;
  3035. -webkit-transition:all 0.3s ease-in-out 0s;
  3036. transition:all 0.3s ease-in-out 0s;
  3037. }
  3038. .pagetual_pageBar a>span:hover {
  3039. color: red;
  3040. }
  3041. .pagetual_pageBar a:hover>span {
  3042. opacity: 1;
  3043. }
  3044. .pagetual_pageBar a:hover>span.prev {
  3045. margin-top: -30px!important;
  3046. }
  3047. .pagetual_pageBar a:hover>span.next {
  3048. margin-top: 30px!important;
  3049. }
  3050.  
  3051. .pagetual_pageBar span>svg:hover {
  3052. animation: touhouAni 1s infinite;
  3053. }
  3054. .pagetual_pageBar .pagetual_pageNum{
  3055. color: #55555f;
  3056. }
  3057. .pagetual_pageBar .pagetual_pageNum:hover{
  3058. color: #ff6464;
  3059. }
  3060. .pagetual_tipsWords{
  3061. font-size: 50px;
  3062. font-weight: bold;
  3063. font-family: "黑体", -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto",
  3064. "Oxygen", "Ubuntu", "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji",
  3065. "Segoe UI Emoji", "Segoe UI Symbol";
  3066. color: #ffffff;
  3067. height: 70px;
  3068. line-height: 70px;
  3069. position: fixed;
  3070. left: 50%;
  3071. top: 10%;
  3072. margin-left: -150px;
  3073. padding: 0 10px;
  3074. z-index: 999999999;
  3075. background-color: #000;
  3076. border: 1px solid black;
  3077. border-radius: 10px;
  3078. opacity: 0;
  3079. filter: alpha(opacity=65);
  3080. box-shadow: 5px 5px 20px 0px #000;
  3081. -moz-transition:opacity 0.3s ease-in-out 0s;
  3082. -webkit-transition:opacity 0.3s ease-in-out 0s;
  3083. transition:opacity 0.3s ease-in-out 0s;
  3084. pointer-events: none;
  3085. }
  3086.  
  3087. @keyframes touhouAni{
  3088. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  3089. to {transform: rotate(360deg);}
  3090. }
  3091. @-webkit-keyframes touhouAni{
  3092. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  3093. to {transform: rotate(360deg);}
  3094. }
  3095. .pagetual_loading {
  3096. width: 50px;
  3097. height: 50px;
  3098. margin: 10px auto;
  3099. border-radius: 100%;
  3100. -webkit-animation: pagetual_loading_scaleout 1.0s infinite ease-in-out;
  3101. animation: pagetual_loading_scaleout 1.0s infinite ease-in-out;
  3102. }
  3103. @-webkit-keyframes pagetual_loading_scaleout {
  3104. 0% { -webkit-transform: scale(0.0) }
  3105. 100% {
  3106. -webkit-transform: scale(1.0);
  3107. opacity: 0;
  3108. }
  3109. }
  3110. @keyframes pagetual_loading_scaleout {
  3111. 0% {
  3112. transform: scale(0.0);
  3113. -webkit-transform: scale(0.0);
  3114. } 100% {
  3115. transform: scale(1.0);
  3116. -webkit-transform: scale(1.0);
  3117. opacity: 0;
  3118. }
  3119. }
  3120. .pagetual_loading_text {
  3121. -webkit-animation: pagetual_loading_opacity 2.6s infinite ease-in-out;
  3122. animation: pagetual_loading_opacity 2.6s infinite ease-in-out;
  3123. }
  3124. @-webkit-keyframes pagetual_loading_opacity {
  3125. 0% { opacity: 1 }
  3126. 50% { opacity: 0.2 }
  3127. 100% { opacity: 1 }
  3128. }
  3129. @keyframes pagetual_loading_opacity {
  3130. 0% { opacity: 1 }
  3131. 50% { opacity: 0.2 }
  3132. 100% { opacity: 1 }
  3133. }
  3134. `);
  3135. 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;`;
  3136. }
  3137. var loadingDiv=document.createElement("div");
  3138. 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;";
  3139. function setLoadingDiv(loadingText){
  3140. 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>`;
  3141. }
  3142.  
  3143. 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;`;
  3144.  
  3145. var upSvg=`<svg width="30" height="30" style="display:initial;position:absolute;cursor: pointer;margin: 0 -45px;width: 30px;height: 30px;vertical-align: middle;fill: currentColor;overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6364"><path d="M296 440c-44.1 0-80 35.9-80 80s35.9 80 80 80 80-35.9 80-80-35.9-80-80-80z" fill="#604b4a" p-id="6365"></path><path d="M960 512c0-247-201-448-448-448S64 265 64 512c0 1.8 0.1 3.5 0.1 5.3 0 0.9-0.1 1.8-0.1 2.7h0.2C68.5 763.3 267.7 960 512 960c236.2 0 430.1-183.7 446.7-415.7 0.1-0.8 0.1-1.6 0.2-2.3 0.4-4.6 0.5-9.3 0.7-13.9 0.1-2.7 0.4-5.3 0.4-8h-0.2c0-2.8 0.2-5.4 0.2-8.1z m-152 8c0 44.1-35.9 80-80 80s-80-35.9-80-80 35.9-80 80-80 80 35.9 80 80zM512 928C284.4 928 99 744.3 96.1 517.3 97.6 408.3 186.6 320 296 320c110.3 0 200 89.7 200 200 0 127.9 104.1 232 232 232 62.9 0 119.9-25.2 161.7-66-66 142.7-210.4 242-377.7 242z" fill="#604b4a" p-id="6366"></path></svg>`;
  3146. var upSvgCSS=`display:initial;position:absolute;cursor: pointer;margin: 0 -45px;width: 30px;height: 30px;vertical-align: middle;fill: currentColor;overflow: hidden;`;
  3147. var downSvg=`<svg width="30" height="30" style="display:initial;position:absolute;cursor: pointer;margin: 0 15px;width: 30px;height: 30px;vertical-align: middle;fill: currentColor;overflow: hidden;transform: rotate(180deg);" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6364"><path d="M296 440c-44.1 0-80 35.9-80 80s35.9 80 80 80 80-35.9 80-80-35.9-80-80-80z" fill="#604b4a" p-id="6365"></path><path d="M960 512c0-247-201-448-448-448S64 265 64 512c0 1.8 0.1 3.5 0.1 5.3 0 0.9-0.1 1.8-0.1 2.7h0.2C68.5 763.3 267.7 960 512 960c236.2 0 430.1-183.7 446.7-415.7 0.1-0.8 0.1-1.6 0.2-2.3 0.4-4.6 0.5-9.3 0.7-13.9 0.1-2.7 0.4-5.3 0.4-8h-0.2c0-2.8 0.2-5.4 0.2-8.1z m-152 8c0 44.1-35.9 80-80 80s-80-35.9-80-80 35.9-80 80-80 80 35.9 80 80zM512 928C284.4 928 99 744.3 96.1 517.3 97.6 408.3 186.6 320 296 320c110.3 0 200 89.7 200 200 0 127.9 104.1 232 232 232 62.9 0 119.9-25.2 161.7-66-66 142.7-210.4 242-377.7 242z" fill="#604b4a" p-id="6366"></path></svg>`;
  3148. 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);`;
  3149.  
  3150. 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;`;
  3151. 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;`;
  3152.  
  3153. var tipsWords=document.createElement("div");
  3154. tipsWords.className="pagetual_tipsWords";
  3155.  
  3156. var isPause=false,isLoading=false,curPage=1,forceState=0,bottomGap=1000,autoLoadNum=-1;
  3157.  
  3158. function changeStop(stop, hide){
  3159. isPause=stop;
  3160. [].forEach.call(document.querySelectorAll(".pagetual_pageBar"), bar=>{
  3161. if(isPause){
  3162. bar.classList.add("stop");
  3163. if(hide)bar.classList.add("hide");
  3164. }else{
  3165. bar.classList.remove("stop");
  3166. if(hide)bar.classList.remove("hide");
  3167. }
  3168. });
  3169. }
  3170.  
  3171. function isInViewPort(element) {
  3172. if(!element.parentNode)return false;
  3173. if(_unsafeWindow.getComputedStyle(element).display=="none")return false;
  3174. const viewWidth = window.innerWidth || document.documentElement.clientWidth;
  3175. const viewHeight = window.innerHeight || document.documentElement.clientHeight;
  3176. const {
  3177. top,
  3178. right,
  3179. bottom,
  3180. left,
  3181. } = element.getBoundingClientRect();
  3182.  
  3183. return (
  3184. top >= 0 &&
  3185. left >= 0 &&
  3186. right <= viewWidth + 1 &&
  3187. bottom <= viewHeight * 2
  3188. );
  3189. }
  3190.  
  3191. var urlChanged=false;
  3192. var _wr = function(type) {
  3193. var orig = history[type];
  3194. return function() {
  3195. var rv = orig.apply(this, arguments);
  3196. var e = new Event(type);
  3197. e.arguments = arguments;
  3198. window.dispatchEvent(e);
  3199. return rv;
  3200. };
  3201. };
  3202. history.pushState = _wr('pushState');
  3203. window.addEventListener('pushState', function(e) {
  3204. urlChanged=true;
  3205. isPause=true;
  3206. setTimeout(()=>{
  3207. if(location.href==configPage){
  3208. location.reload();
  3209. }else if(!ruleParser.ruleMatch(ruleParser.curSiteRule)){
  3210. initPage();
  3211. }
  3212. },1);
  3213. });
  3214.  
  3215. function initListener(){
  3216. let loadmoreBtn,loading=true,lastScroll=0,checkLoadMoreTimes=0;
  3217. let checkLoadMore=setInterval(()=>{
  3218. loadmoreBtn=getLoadMore(document);
  3219. if(loadmoreBtn && isVisible(loadmoreBtn, _unsafeWindow)){
  3220. loading=false;
  3221. clearInterval(checkLoadMore);
  3222. }else if(checkLoadMoreTimes++>10){
  3223. clearInterval(checkLoadMore);
  3224. }
  3225. },300);
  3226. let checkScrollReach=()=>{
  3227. let scrolly=window.scrollY;
  3228. let windowHeight=window.innerHeight || document.documentElement.clientHeight;
  3229. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  3230. if(scrollH-scrolly-windowHeight<bottomGap){
  3231. nextPage();
  3232. }
  3233. };
  3234. let scrollHandler = e=>{
  3235. if(urlChanged){
  3236. ruleParser.initPage(()=>{
  3237. if(ruleParser.nextLinkHref)initView();
  3238. });
  3239. urlChanged=false;
  3240. isPause=false;
  3241. }
  3242. if(isPause)return;
  3243. if(!loading){
  3244. if(!loadmoreBtn || !loadmoreBtn.parentNode){
  3245. loadmoreBtn=getLoadMore(document);
  3246. }
  3247. if(loadmoreBtn){
  3248. if(isInViewPort(loadmoreBtn)){
  3249. emuClick(loadmoreBtn);
  3250. loading=true;
  3251. setTimeout(()=>{loading=false},200);
  3252. }
  3253. }else{
  3254. loading=true;
  3255. setTimeout(()=>{loading=false},200);
  3256. }
  3257. }
  3258. if(!isLoading){
  3259. checkScrollReach();
  3260. }
  3261. if(ruleParser.curSiteRule.lockScroll){
  3262. let curScroll=document.body.scrollTop||document.documentElement.scrollTop;
  3263. if(isLoading && Math.abs(lastScroll-curScroll)>350){
  3264. document.body.scrollTop=lastScroll;
  3265. document.documentElement.scrollTop=lastScroll;
  3266. }else{
  3267. lastScroll=curScroll;
  3268. }
  3269. }
  3270. };
  3271. document.addEventListener('dblclick', e=>{
  3272. if(forceState==1 || e.target.tagName=='INPUT' || e.target.tagName=='TEXTAREA') return;
  3273. if(!rulesData.dbClick2StopKey){
  3274. if((rulesData.dbClick2StopCtrl && !e.ctrlKey) ||
  3275. (rulesData.dbClick2StopAlt && !e.altKey) ||
  3276. (rulesData.dbClick2StopShift && !e.shiftKey) ||
  3277. (rulesData.dbClick2StopMeta && !e.metaKey)){
  3278. return;
  3279. }
  3280. }
  3281. if(e.target.tagName!="BODY"){
  3282. let selStr=document.getSelection().toString();
  3283. if(selStr && selStr.trim()){
  3284. return;
  3285. }
  3286. }
  3287. if(rulesData.dbClick2Stop && (ruleParser.nextLinkHref || loadmoreBtn)){
  3288. setTimeout(()=>{
  3289. changeStop(!isPause, rulesData.hideBar);
  3290. if(!isPause){
  3291. checkScrollReach();
  3292. }
  3293. showTips(i18n(isPause?"disable":"enable"));
  3294. },10);
  3295. }
  3296. });
  3297. if(rulesData.dbClick2StopKey){
  3298. document.addEventListener('keydown', e=>{
  3299. if((rulesData.dbClick2StopCtrl && !e.ctrlKey) ||
  3300. (rulesData.dbClick2StopAlt && !e.altKey) ||
  3301. (rulesData.dbClick2StopShift && !e.shiftKey) ||
  3302. (rulesData.dbClick2StopMeta && !e.metaKey)){
  3303. return;
  3304. }
  3305. if (document.activeElement &&
  3306. (document.activeElement.tagName == 'INPUT' ||
  3307. document.activeElement.tagName == 'TEXTAREA')) {
  3308. return;
  3309. }
  3310. var key = String.fromCharCode(e.keyCode).toLowerCase();
  3311. if(rulesData.dbClick2StopKey.toLowerCase()==key){
  3312. forceState=(forceState==1?0:1);
  3313. showTips(i18n(forceState==1?"disableSiteTips":"enableSiteTips"));
  3314. if(!ruleParser.curSiteRule.url) {
  3315. storage.setItem("forceState_"+location.host, forceState);
  3316. location.reload();
  3317. }
  3318. }
  3319. });
  3320. }
  3321. let clickNext=() => {
  3322. let nextLink=ruleParser.nextLinkHref;
  3323. if(!nextLink)return;
  3324. let isJs=/^(javascript|#)/.test(nextLink.replace(location.href,""));
  3325. if(isJs){
  3326. let nextBtn=ruleParser.getNextLink(document);
  3327. if(nextBtn)emuClick(nextBtn);
  3328. }else{
  3329. window.location.href = nextLink;
  3330. }
  3331. };
  3332. if(typeof ruleParser.curSiteRule.manualMode=='undefined' ? rulesData.manualMode : ruleParser.curSiteRule.manualMode){
  3333. document.addEventListener('keydown', e=>{
  3334. if (document.activeElement &&
  3335. (document.activeElement.tagName == 'INPUT' ||
  3336. document.activeElement.tagName == 'TEXTAREA' ||
  3337. document.activeElement.contentEditable == 'true')) {
  3338. return;
  3339. }
  3340. if(e.keyCode==39){
  3341. clickNext();
  3342. }
  3343. });
  3344. document.addEventListener('pagetual.next', function() {
  3345. clickNext();
  3346. }, false);
  3347. return;
  3348. }
  3349. if(!ruleParser.curSiteRule.wheel){
  3350. document.addEventListener('scroll', scrollHandler, true);
  3351. }
  3352. document.addEventListener('wheel', scrollHandler, true);
  3353. }
  3354.  
  3355. function showTips(content, wordColor, backColor){
  3356. document.body.appendChild(tipsWords);
  3357. tipsWords.style.opacity=0.8;
  3358. tipsWords.innerText=content;
  3359. tipsWords.style.marginLeft=-tipsWords.offsetWidth/2+"px";
  3360. tipsWords.style.color=wordColor||0xFFFFFF;
  3361. tipsWords.style.backgroundColor=backColor||0x000;
  3362. setTimeout(()=>{tipsWords.style.opacity=0},1000);
  3363. }
  3364.  
  3365. function getLoadMore(doc){
  3366. if(ruleParser.curSiteRule.loadMore==="")return null;
  3367. let btnSel=ruleParser.curSiteRule.loadMore||".LoadMore,.load-more,.button-show-more,button[data-testid='more-results-button']",loadmoreBtn;
  3368. if(btnSel){
  3369. try{
  3370. loadmoreBtn=doc.querySelector(btnSel);
  3371. }catch(e){
  3372. loadmoreBtn=getElementByXpath(btnSel,doc,doc);
  3373. }
  3374. }
  3375. if(!loadmoreBtn){
  3376. let buttons=doc.querySelectorAll("input,button,a,div[onclick]"),loadmoreReg=/^\s*(加载更多|加載更多|load\s*more|もっと読み込む)\s*$/i;
  3377. for(let i=0;i<buttons.length;i++){
  3378. let button=buttons[i];
  3379. if(button.innerText.length > 20)continue;
  3380. if(button && loadmoreReg.test(button.innerText)){
  3381. loadmoreBtn=button;
  3382. break;
  3383. }
  3384. }
  3385. }
  3386. if(loadmoreBtn && !ruleParser.curSiteRule.loadMore && loadmoreBtn.href && !/^(javascript|#)/.test(loadmoreBtn.href))loadmoreBtn=null;
  3387. return loadmoreBtn;
  3388. }
  3389.  
  3390. function scrollToPageBar(bar){
  3391. let yOffset = -15;
  3392. if (typeof ruleParser.curSiteRule.pageBarTop !== 'undefined') {
  3393. yOffset = -ruleParser.curSiteRule.pageBarTop;
  3394. }
  3395. const y = bar.getBoundingClientRect().top + window.pageYOffset + yOffset;
  3396. window.scrollTo({ top: y, behavior: 'smooth'});
  3397. }
  3398.  
  3399. var hasPageNum=true;
  3400. function createPageBar(url){
  3401. let insert=ruleParser.getInsert();
  3402. if(!insert || !insert.parentNode)return;
  3403. curPage++;
  3404. let example=ruleParser.curSiteRule.insertPos==2?insert.children[0]:(insert.parentNode.children[parseInt(insert.parentNode.children.length/2)]||insert);
  3405. if (example.className=="pagetual_pageBar") {
  3406. example=example.previousElementSibling;
  3407. }
  3408. if(!example || !example.parentNode)example=insert;
  3409. let exampleStyle = _unsafeWindow.getComputedStyle(example);
  3410. let inTable=example.parentNode.tagName=="TABLE" ||
  3411. example.tagName=="TR" ||
  3412. example.tagName=="TBODY" ||
  3413. exampleStyle.display=="table-row" ||
  3414. (example.previousElementSibling && example.previousElementSibling.tagName=="TR") ||
  3415. (example.previousElementSibling && example.previousElementSibling.tagName=="TBODY");
  3416. let inLi=example.tagName=="LI" || (example.previousElementSibling && example.previousElementSibling.tagName=="LI");
  3417. if(forceState==2){
  3418. inTable=inLi=false;
  3419. }
  3420. let pageBar=document.createElement(inTable?"tr":(inLi?"li":"div"));
  3421. let upSpan=document.createElement("span");
  3422. let downSpan=document.createElement("span");
  3423. let pageText=document.createElement("a");
  3424. let pageNum;
  3425. pageBar.className="pagetual_pageBar";
  3426. pageBar.id="pagetual_pageBar"+curPage;
  3427. if(isPause){
  3428. pageBar.classList.add("stop");
  3429. }
  3430. pageBar.style.cssText=pageBarStyle;
  3431. pageBar.title=i18n(isPause?"enable":"disable");
  3432. upSpan.innerHTML=upSvg;
  3433. upSpan.children[0].style.cssText=upSvgCSS;
  3434. upSpan.title=i18n("toTop");
  3435. downSpan.innerHTML=downSvg;
  3436. downSpan.children[0].style.cssText=downSvgCSS;
  3437. downSpan.title=i18n("toBottom");
  3438. upSpan.style.cssText=initStyle;
  3439. downSpan.style.cssText=initStyle;
  3440. pageText.href=url;
  3441. pageText.style.cssText=pageTextStyle;
  3442. pageText.title=i18n("current");
  3443. pageBar.appendChild(upSpan);
  3444. pageBar.appendChild(pageText);
  3445. if(ruleParser.nextTitle){
  3446. pageText.innerHTML=ruleParser.nextTitle+" ";
  3447. pageText.title=ruleParser.nextTitle;
  3448. }
  3449. if(ruleParser.curSiteRule.pageNum || (hasPageNum && /[&\/\?](p=|page[=\/_-]?)\d+|[_-]\d+\./.test(url))){
  3450. pageText.innerHTML+="Page ";
  3451. pageNum=document.createElement("span");
  3452. pageNum.innerText=ruleParser.getPageNumFromUrl(url);
  3453. pageNum.className="pagetual_pageNum";
  3454. pageNum.title=i18n("inputPageNum");
  3455. pageNum.style.cssText=pageTextStyle;
  3456. pageNum.style.cursor="pointer";
  3457. pageNum.style.color="";
  3458. pageNum.style.marginLeft="5px";
  3459. pageNum.addEventListener("click", e=>{
  3460. let pageInput=prompt(i18n("inputPageNum"), "1");
  3461. if(pageInput){
  3462. let pageLink=ruleParser.getLinkByPage(url, pageInput);
  3463. if(pageLink){
  3464. _GM_openInTab(pageLink,{active:true});
  3465. }
  3466. }
  3467. e.preventDefault();
  3468. e.stopPropagation();
  3469. });
  3470. pageBar.appendChild(pageNum);
  3471. }else{
  3472. pageText.innerHTML+="Page "+curPage;
  3473. hasPageNum=false;
  3474. }
  3475. let preBtn=document.createElement("span");
  3476. preBtn.innerText="∧";
  3477. preBtn.title="Prev page";
  3478. preBtn.className="prev";
  3479. preBtn.style.cssText="float: left; margin-top: -30px; width: 40px; background: rgba(240, 240, 240, 0.8); position: absolute; border-radius: 20px 20px 0 0; box-shadow: rgb(0 0 0 / 50%) 0px -5px 5px;z-index:9999999";
  3480. let nextBtn=document.createElement("span");
  3481. nextBtn.innerText="∨";
  3482. nextBtn.title="Next page";
  3483. nextBtn.className="next";
  3484. nextBtn.style.cssText="float: left; margin-top: 30px; width: 40px; background: rgba(240, 240, 240, 0.8); position: absolute; border-radius: 0 0 20px 20px; box-shadow: rgb(0 0 0 / 50%) 0px 5px 5px;z-index:9999999";
  3485. let localPage=curPage;
  3486. preBtn.addEventListener("click", e=>{
  3487. e.stopPropagation();
  3488. e.preventDefault();
  3489. let prePageBar = document.querySelector("#pagetual_pageBar"+(localPage-1));
  3490. if (prePageBar) {
  3491. scrollToPageBar(prePageBar);
  3492. } else {
  3493. window.scrollTo({ top: 0, behavior: 'smooth'});
  3494. }
  3495. });
  3496. nextBtn.addEventListener("click", e=>{
  3497. e.stopPropagation();
  3498. e.preventDefault();
  3499. let prePageBar=document.querySelector("#pagetual_pageBar"+(localPage+1));
  3500. if (prePageBar) {
  3501. scrollToPageBar(prePageBar);
  3502. } else {
  3503. window.scrollTo({ top: 9999999, behavior: 'smooth'});
  3504. }
  3505. });
  3506. pageText.insertBefore(preBtn, pageText.firstChild);
  3507. pageText.insertBefore(nextBtn, pageText.firstChild);
  3508. pageBar.appendChild(downSpan);
  3509. let parentStyle=_unsafeWindow.getComputedStyle(example.parentNode);
  3510. let parentWidth=example.parentNode.offsetWidth||parseInt(parentStyle.width);
  3511. pageBar.style.width=parentWidth-parseInt(parentStyle.paddingLeft)-parseInt(parentStyle.paddingRight)-10+"px";
  3512. if(parentStyle.display=="grid" || parentStyle.display=="inline-grid"){
  3513. pageBar.style.gridColumnStart=1;
  3514. pageBar.style.gridColumnEnd=1+parseInt(example.parentNode.offsetWidth/example.offsetWidth);
  3515. }
  3516. if(inTable){
  3517. example=(example.tagName=="TR" || example.tagName=="TBODY")?example:example.previousElementSibling;
  3518. if(example.tagName=="TBODY")example=example.querySelector("tr");
  3519. let preTr=example;
  3520. while(preTr && preTr.children.length==0)preTr=preTr.previousElementSibling;
  3521. if(preTr)example=preTr;
  3522. let tdNum=0;
  3523. if (exampleStyle.display=="table-row") {
  3524. tdNum = example.children.length;
  3525. } else {
  3526. [].forEach.call(example.children, el=>{
  3527. if(el.tagName=="TD" || el.tagName=="TH"){
  3528. tdNum+=el.colSpan||1;
  3529. }
  3530. });
  3531. }
  3532. pageBar.style.display="table-row";
  3533. pageBar.style.backgroundColor="unset";
  3534. pageBar.style.lineHeight="20px";
  3535. pageBar.style.boxShadow="";
  3536. let td=document.createElement("td");
  3537. td.colSpan=tdNum||1;
  3538. let inTd=document.createElement("div");
  3539. inTd.style.backgroundColor="rgb(240 240 240 / 80%)";
  3540. inTd.style.borderRadius="20px";
  3541. inTd.style.padding="0 0";
  3542. inTd.style.margin="10px";
  3543. inTd.style.lineHeight="20px";
  3544. inTd.style.textAlign="center";
  3545. inTd.style.boxShadow="rgb(0 0 0 / 67%) 0px 0px 10px 0px";
  3546. inTd.appendChild(upSpan);
  3547. inTd.appendChild(pageText);
  3548. if(pageNum)inTd.appendChild(pageNum);
  3549. inTd.appendChild(downSpan);
  3550. td.appendChild(inTd);
  3551. pageBar.appendChild(td);
  3552. }else if(inLi){
  3553. example=example.tagName=="LI"?example:example.previousElementSibling;
  3554. pageBar.style.display="table-row";
  3555. pageBar.style.backgroundColor="unset";
  3556. pageBar.style.lineHeight="20px";
  3557. pageBar.style.boxShadow="";
  3558. let td=document.createElement("td");
  3559. td.colSpan=example.children.length;
  3560. let inTd=document.createElement("div");
  3561. inTd.style.backgroundColor="rgb(240 240 240 / 80%)";
  3562. inTd.style.borderRadius="20px";
  3563. inTd.style.margin="10px"
  3564. inTd.style.padding="0 0";
  3565. inTd.style.textAlign="center";
  3566. inTd.style.minWidth="150px";
  3567. inTd.appendChild(upSpan);
  3568. inTd.appendChild(pageText);
  3569. inTd.style.width=parseInt(pageBar.style.width)-20+"px";
  3570. inTd.style.boxShadow="rgb(0 0 0 / 67%) 0px 0px 10px 0px";
  3571. if(pageNum)inTd.appendChild(pageNum);
  3572. inTd.appendChild(downSpan);
  3573. td.appendChild(inTd);
  3574. pageBar.appendChild(td);
  3575. }
  3576.  
  3577. upSpan.addEventListener("click", e=>{
  3578. document.body.scrollTop=0;
  3579. document.documentElement.scrollTop=0;
  3580. e.preventDefault();
  3581. e.stopPropagation();
  3582. });
  3583. downSpan.addEventListener("click", e=>{
  3584. changeStop(true);
  3585. pageBar.title=i18n(isPause?"enable":"disable");
  3586. document.body.scrollTop=9999999;
  3587. document.documentElement.scrollTop=9999999;
  3588. e.preventDefault();
  3589. e.stopPropagation();
  3590. });
  3591. pageBar.addEventListener("click", e=>{
  3592. changeStop(!isPause);
  3593. pageBar.title=i18n(isPause?"enable":"disable");
  3594. });
  3595. pageText.addEventListener("click", e=>{
  3596. e.stopPropagation();
  3597. if (e.ctrlKey || e.altKey || e.shiftKey || e.metaKey) return;
  3598. if (e.which == 1) {
  3599. e.preventDefault();
  3600. scrollToPageBar(pageBar);
  3601. }
  3602. });
  3603. ruleParser.insertElement(pageBar);
  3604. if(ruleParser.curSiteRule.pageBar && ruleParser.curSiteRule.pageBar !== 0){
  3605. try{
  3606. ((typeof _unsafeWindow.pagetualPageBar=='undefined') ? Function("pageBar",'"use strict";' + ruleParser.curSiteRule.pageBar) : _unsafeWindow.pagetualPageBar)(pageBar);
  3607. }catch(e){
  3608. debug(e);
  3609. }
  3610. }
  3611.  
  3612. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  3613. let posEle=pageBar.nextElementSibling||pageBar;
  3614. while(posEle && !posEle.offsetParent){
  3615. posEle=posEle.previousElementSibling||posEle.parentNode;
  3616. }
  3617. if(posEle){
  3618. let actualTop = getElementTop(posEle);
  3619. bottomGap=scrollH-actualTop+(window.innerHeight||document.documentElement.clientHeight)*(ruleParser.curSiteRule.rate||1);
  3620. if(bottomGap<100)bottomGap=100;
  3621. }else{
  3622. bottomGap=1000;
  3623. }
  3624. if(rulesData.opacity==0 || ruleParser.curSiteRule.pageBar === 0)pageBar.style.display="none";
  3625. return pageBar;
  3626. }
  3627.  
  3628. function emuClick(btn){
  3629. if(!PointerEvent)return btn.click();
  3630. let eventParam={
  3631. isTrusted: true,
  3632. altKey: false,
  3633. azimuthAngle: 0,
  3634. bubbles: true,
  3635. button: 0,
  3636. buttons: 0,
  3637. clientX: 1,
  3638. clientY: 1,
  3639. cancelBubble: false,
  3640. cancelable: true,
  3641. composed: true,
  3642. ctrlKey: false,
  3643. defaultPrevented: false,
  3644. detail: 1,
  3645. eventPhase: 2,
  3646. fromElement: null,
  3647. height: 1,
  3648. isPrimary: false,
  3649. metaKey: false,
  3650. pointerId: 1,
  3651. pointerType: "mouse",
  3652. pressure: 0,
  3653. relatedTarget: null,
  3654. returnValue: true,
  3655. shiftKey: false,
  3656. toElement: null,
  3657. twist: 0,
  3658. which: 1
  3659. };
  3660. var mouseEvent = new PointerEvent("mousedown",eventParam);
  3661. btn.dispatchEvent(mouseEvent);
  3662. mouseEvent = new PointerEvent("mouseup",eventParam);
  3663. btn.dispatchEvent(mouseEvent);
  3664. btn.click();
  3665. }
  3666.  
  3667. var failFromIframe=0;
  3668. var inCors=false;
  3669. function requestFromIframe(url, callback){
  3670. url=url.replace(/#[^#]*/,"");
  3671. let orgPage,curPage;
  3672. let iframe = document.createElement('iframe');
  3673. iframe.name = 'pagetual-iframe';
  3674. iframe.width = '100%';
  3675. iframe.height = '0';
  3676. iframe.frameBorder = '0';
  3677. if(ruleParser.curSiteRule.sandbox!=false){
  3678. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  3679. }
  3680. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  3681. let waitTime=100,checkEval;
  3682. if(ruleParser.curSiteRule.waitElement){
  3683. checkEval = doc => {
  3684. return ruleParser.waitElement(doc);
  3685. };
  3686. }else if(ruleParser.curSiteRule.wait){
  3687. if(isNaN(ruleParser.curSiteRule.wait)){
  3688. try{
  3689. checkEval=(typeof _unsafeWindow.pagetualWait=='undefined') ? Function("doc",'"use strict";' + ruleParser.curSiteRule.wait) : _unsafeWindow.pagetualWait;
  3690. }catch(e){
  3691. debug(e);
  3692. }
  3693. }else{
  3694. waitTime=ruleParser.curSiteRule.wait;
  3695. }
  3696. }
  3697. let loadedHandler=e=>{
  3698. if(e.data != 'pagetual-iframe:DOMLoaded' && e.type != 'load')return;
  3699. window.removeEventListener('message', loadedHandler, false);
  3700. iframe.removeEventListener('load', loadedHandler, false);
  3701. let tryTimes=0;
  3702. function checkIframe(){
  3703. try{
  3704. let doc=iframe.contentDocument || iframe.contentWindow.document;
  3705. let eles=ruleParser.getPageElement(doc, iframe.contentWindow);
  3706. if(checkEval && !checkEval(doc)){
  3707. setTimeout(()=>{
  3708. checkIframe();
  3709. },waitTime);
  3710. return;
  3711. }else if(eles && eles.length>0){
  3712. callback(doc, eles);
  3713. }else if(tryTimes++ < 10){
  3714. setTimeout(()=>{
  3715. checkIframe();
  3716. },waitTime);
  3717. return;
  3718. }else{
  3719. if(failFromIframe++ > 2){
  3720. failFromIframe=0;
  3721. debug("Stop as failFromIframe");
  3722. isPause=true;
  3723. callback(false, false);
  3724. }else{
  3725. callback(false, false);
  3726. }
  3727. }
  3728. }catch(e){
  3729. debug("Stop as cors");
  3730. inCors=true;
  3731. //isPause=true;
  3732. if(!ruleParser.curSiteRule.pageElement){
  3733. ruleParser.curSiteRule.pageElement=allOfBody;
  3734. ruleParser.getInsert(true);
  3735. }
  3736. ruleParser.curSiteRule.action=0;
  3737. ruleParser.nextLinkHref=url;
  3738. callback(false, false);
  3739. nextPage();
  3740. }
  3741. document.body.removeChild(iframe);
  3742. }
  3743. setTimeout(()=>{
  3744. checkIframe();
  3745. },waitTime);
  3746. };
  3747. window.addEventListener('message', loadedHandler, false);
  3748. iframe.addEventListener('load', loadedHandler, false);
  3749. iframe.src=url;
  3750. document.body.appendChild(iframe);
  3751. }
  3752.  
  3753. var emuIframe,lastActiveUrl;
  3754. function emuPage(callback){
  3755. let orgPage=null,orgContent=null,preContent=null,curPage,iframeDoc,times=0,loadmoreBtn,loadmoreEnd=false,waitTimes=10,changed=false;
  3756. function returnFalse(log){
  3757. debug(log);
  3758. isPause=true;
  3759. callback(false, false);
  3760. if(emuIframe && emuIframe.parentNode){
  3761. emuIframe.parentNode.removeChild(emuIframe);
  3762. emuIframe=null;
  3763. }
  3764. }
  3765. function checkPage(){
  3766. if(isPause)return;
  3767. try{
  3768. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  3769. }catch(e){
  3770. returnFalse("Stop as cors");
  3771. return;
  3772. }
  3773.  
  3774. let nextLink=ruleParser.getNextLink(iframeDoc);
  3775. let waitTime=200,checkEval;
  3776. if(ruleParser.curSiteRule.waitElement){
  3777. checkEval = doc => {
  3778. return ruleParser.waitElement(doc);
  3779. };
  3780. }else if(ruleParser.curSiteRule.wait){
  3781. if(isNaN(ruleParser.curSiteRule.wait)){
  3782. try{
  3783. checkEval=(typeof _unsafeWindow.pagetualWait=='undefined') ? Function("doc",'"use strict";' + ruleParser.curSiteRule.wait) : _unsafeWindow.pagetualWait;
  3784. }catch(e){
  3785. debug(e);
  3786. }
  3787. }else{
  3788. waitTime=ruleParser.curSiteRule.wait;
  3789. }
  3790. }
  3791.  
  3792. if(!orgPage){
  3793. if(!loadmoreEnd){
  3794. loadmoreBtn=getLoadMore(iframeDoc);
  3795. if(loadmoreBtn && isVisible(loadmoreBtn, iframeDoc.defaultView)){
  3796. emuClick(loadmoreBtn);
  3797. let intv=setInterval(()=>{
  3798. loadmoreBtn=getLoadMore(iframeDoc);
  3799. if(!loadmoreBtn || !loadmoreBtn.parentNode || !isVisible(loadmoreBtn, iframeDoc.defaultView)){
  3800. clearInterval(intv);
  3801. loadmoreEnd=true;
  3802. setTimeout(()=>{
  3803. checkPage();
  3804. },500);
  3805. }else{
  3806. emuClick(loadmoreBtn);
  3807. }
  3808. },200);
  3809. return;
  3810. }else{
  3811. loadmoreEnd=true;
  3812. }
  3813. }
  3814. let pageEle=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true);
  3815. if(checkEval && !checkEval(iframeDoc)){
  3816. setTimeout(()=>{
  3817. checkPage();
  3818. },waitTime);
  3819. return;
  3820. }else if(!nextLink || !pageEle || pageEle.length==0){
  3821. if(waitTimes-->0){
  3822. setTimeout(()=>{
  3823. checkPage();
  3824. },waitTime);
  3825. return;
  3826. }
  3827. }
  3828. orgPage=pageEle;
  3829. if(!orgPage || orgPage.length==0){
  3830. returnFalse("Stop as no page when emu");
  3831. return;
  3832. }
  3833. if(orgPage && orgPage[0].tagName=="UL")orgPage=orgPage[0].children;
  3834. if(orgPage && nextLink){
  3835. orgPage=orgPage[parseInt(orgPage.length/2)];
  3836. orgContent=orgPage.innerText;
  3837. preContent=orgContent;
  3838. if(!isVisible(nextLink, iframeDoc.defaultView)){
  3839. returnFalse("Stop as next hide when emu");
  3840. }else{
  3841. emuClick(nextLink);
  3842. setTimeout(()=>{
  3843. checkPage();
  3844. },500);
  3845. }
  3846. }else{
  3847. returnFalse("Stop as no next when emu");
  3848. }
  3849. return;
  3850. }
  3851. if(times++ > 20){
  3852. returnFalse("Stop as timeout when emu");
  3853. return;
  3854. }
  3855. let eles=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true),checkItem;
  3856. if(eles && eles.length>0){
  3857. checkItem=eles;
  3858. if(eles[0].tagName=="UL"){
  3859. checkItem=eles[0].children;
  3860. }
  3861. checkItem=checkItem[parseInt(checkItem.length/2)];
  3862. }
  3863. if(!checkItem || (checkEval && !checkEval(iframeDoc))){
  3864. setTimeout(()=>{
  3865. checkPage();
  3866. },waitTime);
  3867. }else{
  3868. if(orgPage!=checkItem || checkItem.innerText!=preContent){
  3869. changed=true;
  3870. orgPage=checkItem;
  3871. preContent=checkItem.innerText;
  3872. setTimeout(()=>{
  3873. checkPage();
  3874. },waitTime);
  3875. }else if(changed){
  3876. if (orgContent == preContent) {
  3877. returnFalse("Stop as same content");
  3878. } else {
  3879. callback(iframeDoc, eles);
  3880. }
  3881. }else{
  3882. setTimeout(()=>{
  3883. checkPage();
  3884. },waitTime);
  3885. }
  3886. }
  3887. }
  3888. if(!emuIframe){
  3889. let loaded=false;
  3890. emuIframe = document.createElement('iframe');
  3891. emuIframe.name = 'pagetual-iframe';
  3892. if(ruleParser.curSiteRule.sandbox!=false){
  3893. emuIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  3894. }
  3895. emuIframe.width = '100%';
  3896. emuIframe.height = '0';
  3897. emuIframe.frameBorder = '0';
  3898. emuIframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  3899. emuIframe.addEventListener("load", e=>{
  3900. setTimeout(()=>{
  3901. try{
  3902. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  3903. }catch(e){
  3904. returnFalse("Stop as cors");
  3905. return;
  3906. }
  3907. let code=ruleParser.curSiteRule.init;
  3908. if(code){
  3909. try{
  3910. Function('doc','win','iframe','"use strict";' + code)(iframeDoc, iframeDoc.defaultView, emuIframe);
  3911. }catch(e){
  3912. debug(e);
  3913. }
  3914. }
  3915. if(loaded)return;
  3916. loaded=true;
  3917. checkPage();
  3918. },500);
  3919. });
  3920. if (!lastActiveUrl) lastActiveUrl=location.href;
  3921. emuIframe.src=lastActiveUrl.replace(/#[^#]*/,"");
  3922. document.body.appendChild(emuIframe);
  3923. }else{
  3924. checkPage();
  3925. }
  3926. }
  3927.  
  3928. var scrollToResizeInited = false;
  3929. var resizePool = [];
  3930. var scrollingToResize = false;
  3931.  
  3932. function scrollToResize(e) {
  3933. if (scrollingToResize) return;
  3934. else {
  3935. scrollingToResize = true;
  3936. let fitWidth = ruleParser.curSiteRule.fitWidth !== false;
  3937. let resizeHandler = () => {
  3938. resizePool.forEach(resizeArr => {
  3939. let iframe = resizeArr[1]();
  3940. let frameDoc = resizeArr[2]();
  3941. if(ruleParser.curSiteRule.singleUrl){
  3942. iframe.style.height=frameDoc.body.scrollHeight+"px";
  3943. iframe.style.width=frameDoc.body.scrollWidth+"px";
  3944. }else{
  3945. let pageEle = resizeArr[0]();
  3946. if(pageEle){
  3947. let targetElement = pageEle[0];
  3948. if(pageEle.length > 1){
  3949. targetElement = targetElement.parentNode;
  3950. }
  3951. if(parseInt(iframe.style.height)==targetElement.scrollHeight) return;
  3952. iframe.style.height=targetElement.scrollHeight+"px";
  3953. frameDoc.documentElement.scrollTop = 0;
  3954. frameDoc.documentElement.scrollLeft = 0;
  3955. while(targetElement && targetElement.offsetParent){
  3956. targetElement.offsetParent.scrollTop = targetElement.offsetTop;
  3957. if(targetElement.offsetParent.scrollTop == 0){
  3958. frameDoc.documentElement.scrollTop += targetElement.offsetTop;
  3959. }
  3960. if(fitWidth){
  3961. targetElement.offsetParent.scrollLeft = targetElement.offsetLeft;
  3962. if(targetElement.offsetParent.scrollLeft == 0){
  3963. frameDoc.documentElement.scrollLeft += targetElement.offsetLeft;
  3964. }
  3965. }
  3966. targetElement = targetElement.offsetParent;
  3967. }
  3968. if(!fitWidth && iframe.style.marginLeft == '0px'){
  3969. iframe.style.width = "100vw";
  3970. iframe.style.marginLeft = -iframe.getBoundingClientRect().left + "px";
  3971. }
  3972. }
  3973. }
  3974. });
  3975. };
  3976. setTimeout(() => {
  3977. resizeHandler();
  3978. scrollingToResize = false
  3979. }, 200);
  3980. resizeHandler();
  3981. }
  3982. }
  3983.  
  3984. function forceIframe(url, callback){
  3985. url=url.replace(/#[^#]*/,"");
  3986. let curIframe = document.createElement('iframe'),iframeDoc,isloaded=false,inAction=true;
  3987. let loadedHandler = ()=>{
  3988. inAction=false;
  3989. if(isloaded)return;
  3990. isloaded=true;
  3991. ruleParser.insertPage(iframeDoc, [], url, null, true);
  3992. callback(curIframe, true);
  3993. let getIframe = () => {
  3994. return curIframe;
  3995. };
  3996. let getFrameDoc = () => {
  3997. return iframeDoc;
  3998. };
  3999. if(ruleParser.curSiteRule.singleUrl){
  4000. resizePool.push([() => {}, getIframe, getFrameDoc]);
  4001. }else{
  4002. let pageElement = ruleParser.getPageElement(iframeDoc,iframeDoc.defaultView);
  4003. let getPageEle = () => {
  4004. if (!pageElement || pageElement.length===0) {
  4005. pageElement = ruleParser.getPageElement(iframeDoc,iframeDoc.defaultView);
  4006. }
  4007. return pageElement;
  4008. };
  4009. resizePool.push([getPageEle, getIframe, getFrameDoc]);
  4010. }
  4011. scrollToResize();
  4012. };
  4013. curIframe.name = 'pagetual-iframe';
  4014. curIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  4015. curIframe.frameBorder = '0';
  4016. curIframe.scrolling="no";
  4017. 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;';
  4018. curIframe.addEventListener("load", e=>{
  4019. try{
  4020. iframeDoc=curIframe.contentDocument || curIframe.contentWindow.document;
  4021. }catch(e){
  4022. debug("Stop as cors");
  4023. isPause=true;
  4024. callback(false, false);
  4025. return;
  4026. }
  4027. let css=ruleParser.curSiteRule.css || rulesData.customCss;
  4028. if(css){
  4029. css = css.replace(/^inIframe:/, "");
  4030. let styleEle=iframeDoc.createElement("style");
  4031. styleEle.innerHTML=css;
  4032. iframeDoc.head.appendChild(styleEle);
  4033. }
  4034. loadedHandler();
  4035. let code=ruleParser.curSiteRule.init;
  4036. if(code){
  4037. try{
  4038. Function('doc','win','iframe','"use strict";' + code)(iframeDoc,iframeDoc.defaultView,curIframe);
  4039. }catch(e){
  4040. debug(e);
  4041. }
  4042. }
  4043. });
  4044. let checkTimes=0,findPageEle=false;
  4045. let forceRefresh=e=>{
  4046. if(inAction || !iframeDoc)return;
  4047. inAction=true;
  4048. let foundNext=()=>{
  4049. document.removeEventListener("scroll", forceRefresh);
  4050. }
  4051. setTimeout(()=>{
  4052. inAction=false;
  4053. if(!ruleParser.nextLinkHref){
  4054. checkTimes++;
  4055. ruleParser.getNextLink(iframeDoc);
  4056. if(ruleParser.nextLinkHref){
  4057. foundNext();
  4058. }else if(checkTimes>=10){
  4059. foundNext();
  4060. }else if(checkTimes>=3 && !findPageEle){
  4061. let pageElement = ruleParser.getPageElement(iframeDoc,iframeDoc.defaultView);
  4062. if(!pageElement){
  4063. inAction=true;
  4064. curIframe.contentWindow.location.reload();
  4065. }else{
  4066. findPageEle=true;
  4067. }
  4068. }
  4069. }else{
  4070. foundNext();
  4071. }
  4072. },50);
  4073. };
  4074. document.addEventListener("scroll", forceRefresh);
  4075. curIframe.src=url;
  4076. let insert=ruleParser.getInsert();
  4077. if(ruleParser.curSiteRule.singleUrl || forceState==2){
  4078. document.body.appendChild(loadingDiv);
  4079. document.body.appendChild(curIframe);
  4080. }else{
  4081. ruleParser.insertElement(curIframe);
  4082. }
  4083.  
  4084. if (!scrollToResizeInited) {
  4085. scrollToResizeInited = true;
  4086. document.addEventListener("scroll", scrollToResize);
  4087. }
  4088. return curIframe;
  4089. }
  4090.  
  4091. function loadPageOver(){
  4092. isLoading=false;
  4093. if(loadingDiv.parentNode){
  4094. loadingDiv.parentNode.removeChild(loadingDiv);
  4095. }
  4096. /*setTimeout(()=>{
  4097. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  4098. if(scrollH <= (window.innerHeight || document.documentElement.clientHeight)){
  4099. nextPage();
  4100. }
  4101. },1);*/
  4102. }
  4103.  
  4104. var tryTimes = 0;
  4105.  
  4106. function nextPage(){
  4107. if(typeof ruleParser.curSiteRule.manualMode=='undefined' ? rulesData.manualMode : ruleParser.curSiteRule.manualMode)return;
  4108. if(isPause || isLoading || forceState==1)return;
  4109. if(ruleParser.curSiteRule.delay){
  4110. try{
  4111. let checkDelay=((typeof _unsafeWindow.pagetualDelay=='undefined') ? Function('"use strict";' + ruleParser.curSiteRule.delay) : _unsafeWindow.pagetualDelay)();
  4112. if(!checkDelay)return;
  4113. }catch(e){
  4114. debug(e);
  4115. }
  4116. }
  4117. if(ruleParser.curSiteRule.pageElementCss || ruleParser.curSiteRule.pageElementStyle || rulesData.pageElementCss){
  4118. ruleParser.getPageElement(document, _unsafeWindow);
  4119. }
  4120. let nextLink=ruleParser.nextLinkHref;
  4121. if(!nextLink){
  4122. if(curPage==1){
  4123. ruleParser.getNextLink(document);
  4124. nextLink=ruleParser.nextLinkHref;
  4125. }
  4126. if(!nextLink){
  4127. isLoading=true;
  4128. if(curPage==1 && (ruleParser.curSiteRule.pinUrl || tryTimes++ <= 10)){
  4129. setTimeout(()=>{isLoading=false},500);
  4130. }
  4131. return;
  4132. }
  4133. }
  4134. let pvGallery=document.querySelector("span.pv-gallery-container");
  4135. if(pvGallery && pvGallery.style.display!="none")return;
  4136. let insert=ruleParser.getInsert();
  4137. if(insert){
  4138. let isJs=/^(javascript|#)/.test(nextLink.replace(location.href,""));
  4139. if(!isJs){
  4140. emuIframe=null;
  4141. lastActiveUrl=nextLink;
  4142. }
  4143. if(location.protocol=="https:" && /^http:/.test(nextLink)){
  4144. nextLink=nextLink.replace(/^http/,"https");
  4145. }
  4146. isLoading=true;
  4147. ruleParser.insertElement(loadingDiv);
  4148. loadingDiv.style.cssText=loadingCSS;
  4149. let sleep=ruleParser.curSiteRule.sleep||0;
  4150. setTimeout(()=>{
  4151. if(ruleParser.curSiteRule.pageElementByJs){
  4152. var over=ele=>{
  4153. loadPageOver();
  4154. if(ele){
  4155. createPageBar(nextLink);
  4156. ruleParser.insertPage(null, ele, nextLink, null, true);
  4157. if(autoLoadNum>=0){
  4158. if(autoLoadNum!=0 && --autoLoadNum==0){
  4159. autoLoadNum=-1;
  4160. }else{
  4161. nextPage();
  4162. }
  4163. }
  4164. }else{
  4165. debug("Stop as no page when get by js");
  4166. isPause=true;
  4167. }
  4168. };
  4169. try{
  4170. ((typeof _unsafeWindow.pagetualPageElementByJs=='undefined') ? Function("over",'"use strict";' + ruleParser.curSiteRule.pageElementByJs) : _unsafeWindow.pagetualPageElementByJs)(over);
  4171. }catch(e){
  4172. debug(e);
  4173. }
  4174. }else if((forceState==3||ruleParser.curSiteRule.action==1) && !isJs){
  4175. requestFromIframe(nextLink, (doc, eles)=>{
  4176. loadPageOver();
  4177. if(eles){
  4178. ruleParser.insertPage(doc, eles, nextLink, ()=>{
  4179. createPageBar(nextLink);
  4180. }, true);
  4181. if(autoLoadNum>=0){
  4182. if(autoLoadNum!=0 && --autoLoadNum==0){
  4183. autoLoadNum=-1;
  4184. }else{
  4185. nextPage();
  4186. }
  4187. }
  4188. }
  4189. });
  4190. }else if((forceState==2||ruleParser.curSiteRule.action==2) && !isJs){
  4191. forceIframe(nextLink, (iframe, eles)=>{
  4192. loadPageOver();
  4193. let pageBar=createPageBar(nextLink);
  4194. if(pageBar)iframe.parentNode.insertBefore(pageBar, iframe);
  4195. if(autoLoadNum>=0){
  4196. if(autoLoadNum!=0 && --autoLoadNum==0){
  4197. autoLoadNum=-1;
  4198. }else{
  4199. nextPage();
  4200. }
  4201. }
  4202. });
  4203. }else{
  4204. if(!isJs){
  4205. requestDoc(nextLink, (eles)=>{
  4206. loadPageOver();
  4207. if(eles){
  4208. createPageBar(nextLink);
  4209. if(autoLoadNum>=0){
  4210. if(autoLoadNum!=0 && --autoLoadNum==0){
  4211. autoLoadNum=-1;
  4212. }else{
  4213. nextPage();
  4214. }
  4215. }
  4216. }
  4217. });
  4218. }else{
  4219. emuPage((doc, eles)=>{
  4220. loadPageOver();
  4221. if(eles){
  4222. ruleParser.insertPage(doc, eles, "", ()=>{
  4223. createPageBar(nextLink);
  4224. }, true);
  4225. if(autoLoadNum>=0){
  4226. if(autoLoadNum!=0 && --autoLoadNum==0){
  4227. autoLoadNum=-1;
  4228. }else{
  4229. nextPage();
  4230. }
  4231. }
  4232. }
  4233. });
  4234. }
  4235. }
  4236. },sleep);
  4237. }
  4238. }
  4239.  
  4240. function init(){
  4241. initRules(()=>{
  4242. initPage();
  4243. });
  4244. }
  4245.  
  4246. function visibilitychangeHandler(){
  4247. document.removeEventListener('visibilitychange', visibilitychangeHandler);
  4248. init();
  4249. }
  4250.  
  4251. setTimeout(()=>{
  4252. if (document.hidden) {
  4253. document.addEventListener('visibilitychange', visibilitychangeHandler);
  4254. } else {
  4255. init();
  4256. }
  4257. },100);
  4258. })();