东方永页机

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

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

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