东方永页机

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

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

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