东方永页机

自动翻页 - 加载并拼接下一分页内容至当前页尾,无需规则自动适配任意网页

当前为 2023-01-11 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Pagetual
  3. // @name:zh-CN 东方永页机
  4. // @name:zh-TW 東方永頁機
  5. // @name:ja 東方永頁機
  6. // @name:ru Pagetual
  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.33.32
  14. // @description Perpetual pages - Most powerful auto-pager script. Auto loading next paginated web pages and inserting into current page. Support thousands of web sites without any rule.
  15. // @description:zh-CN 自动翻页 - 加载并拼接下一分页内容至当前页尾,无需规则自动适配任意网页
  16. // @description:zh-TW 自動翻頁 - 加載並拼接下一分頁內容至當前頁尾,無需規則自動適配任意網頁
  17. // @description:ja Webページを自動で読み込み継ぎ足し表示を行うブラウザ拡張です、次のページ付けされた Web ページの自動読み込みと現在のページへの挿入 ルールなしで何千もの Web サイトをサポートします。
  18. // @description:ru Автоматическая загрузка следующих веб-страниц с разбивкой на страницы и вставка на текущую страницу. Поддержка тысяч веб-сайтов без каких-либо правил.
  19. // @description:de Automatisches Laden der nächsten paginierten Webseiten und Einfügen in die aktuelle Seite. Unterstützen Sie Tausende von Websites ohne Regeln.
  20. // @description:es Carga automática de las siguientes páginas web paginadas e inserción en la página actual. Admite miles de sitios web sin ninguna regla.
  21. // @description:fr Chargement automatique des pages Web paginées suivantes et insertion dans la page en cours. Prend en charge des milliers de sites Web sans aucune règle.
  22. // @description:it Caricamento automatico delle pagine Web impaginate successive e inserimento nella pagina corrente. Supporta migliaia di siti web senza alcuna regola.
  23. // @description:ko 페이지가 매겨진 다음 웹 페이지를 자동으로 로드하고 현재 페이지에 삽입합니다. 규칙 없이 수천 개의 웹 사이트를 지원합니다.
  24. // @author hoothin
  25. // @match *://*/*
  26. // @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==
  27. // @grant GM_xmlhttpRequest
  28. // @grant GM_registerMenuCommand
  29. // @grant GM_notification
  30. // @grant GM_getValue
  31. // @grant GM_setValue
  32. // @grant GM_addStyle
  33. // @grant GM_openInTab
  34. // @grant GM_deleteValue
  35. // @grant GM_info
  36. // @grant GM_setClipboard
  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. // @grant GM.setClipboard
  47. // @supportURL https://github.com/hoothin/UserScripts/issues
  48. // @connect wedata.net
  49. // @connect githubusercontent.com
  50. // @connect ghproxy.com
  51. // @connect hoothin.github.io
  52. // @run-at document-idle
  53. // @exclude http://www.toodledo.com/tasks/*
  54. // @exclude http*://maps.google.com*/*
  55. // @exclude *://www.google.*/_/chrome/newtab*
  56. // @exclude *://mega.*/*
  57. // @exclude *://*.mega.*/*
  58. // @exclude *://*.youku.com/v_*
  59. // @exclude *://*pan.baidu.com
  60. // @exclude *://*.iqiyi.com/v_*
  61. // @exclude *://*.iqiyi.com/w_*
  62. // @exclude *://*.iqiyi.com/a_*
  63. // @exclude *://*.le.com/ptv/vplay/*
  64. // @exclude *://v.qq.com/x/cover/*
  65. // @exclude *://v.qq.com/x/page/*
  66. // @exclude *://v.qq.com/tv/*
  67. // @exclude *://*.tudou.com/listplay/*
  68. // @exclude *://*.tudou.com/albumplay/*
  69. // @exclude *://*.tudou.com/programs/view/*
  70. // @exclude *://*.mgtv.com/b/*
  71. // @exclude *://film.sohu.com/album/*
  72. // @exclude *://tv.sohu.com/v/*
  73. // @exclude *://*.bilibili.com/video/*
  74. // @exclude *://*.bilibili.com/bangumi/play/*
  75. // @exclude *://*.baofeng.com/play/*
  76. // @exclude *://vip.pptv.com/show/*
  77. // @exclude *://v.pptv.com/show/*
  78. // @exclude *://www.le.com/ptv/vplay/*
  79. // @exclude *://www.wasu.cn/Play/show/*
  80. // @exclude *://m.v.qq.com/*
  81. // @exclude *://m.iqiyi.com/*
  82. // @exclude *://m.youku.com/alipay_video/*
  83. // @exclude *://m.mgtv.com/b/*
  84. // @exclude *://m.tv.sohu.com/v/*
  85. // @exclude *://m.film.sohu.com/album/*
  86. // @exclude *://m.le.com/ptv/vplay/*
  87. // @exclude *://m.pptv.com/show/*
  88. // @exclude *://m.acfun.cn/v/*
  89. // @exclude *://m.bilibili.com/video/*
  90. // @exclude *://m.bilibili.com/anime/*
  91. // @exclude *://m.bilibili.com/bangumi/play/*
  92. // @exclude *://m.wasu.cn/Play/show/*
  93. // @exclude *://*.youtube.com
  94. // @exclude *://*.youtube.com/*
  95. // @exclude *://twitter.com/*
  96. // @exclude *://www.youtube.com/watch*
  97. // @exclude *://baike.baidu.com/*
  98. // @exclude *://*.instagram.com/*
  99. // @exclude *://order.jd.com/*
  100. // @exclude *://wenku.baidu.com/view/*
  101. // @exclude *://pan.baidu.com/*
  102. // @connect *
  103. // ==/UserScript==
  104.  
  105. (function() {
  106. 'use strict';
  107.  
  108. if (window.name === 'pagetual-iframe' || (window.frameElement && window.frameElement.name === 'pagetual-iframe')) {
  109. var domloaded = function (){
  110. window.scroll(window.scrollX, 999999);
  111. window.parent.postMessage('pagetual-iframe:DOMLoaded', '*');
  112. };
  113. if(window.opera){
  114. document.addEventListener('DOMContentLoaded', domloaded, false);
  115. } else {
  116. domloaded();
  117. }
  118. if (getComputedStyle(document.documentElement).display == 'none') document.documentElement.style.display = 'block';
  119. if (getComputedStyle(document.body).display == 'none') document.body.style.display = 'block';
  120. return;
  121. }
  122.  
  123. if(window.top != window.self){
  124. try{
  125. if (window.self.innerWidth < 100 || window.self.innerHeight < 100) {
  126. return;
  127. }
  128. }catch(e){
  129. return;
  130. }
  131. }
  132.  
  133. const noRuleTest = false;
  134. const lang = navigator.appName=="Netscape"?navigator.language:navigator.userLanguage;
  135. let config={};
  136. switch (lang){
  137. case "zh-CN":
  138. case "zh-SG":
  139. config = {
  140. enableDebug:"调试模式,输出信息至控制台",
  141. disable:"暂时禁用",
  142. disableSite:"切换禁用状态",
  143. disableSiteTips:"已在此站禁用",
  144. enableSiteTips:"已在此站启用",
  145. enable:"启用翻页",
  146. toTop:"回到顶部",
  147. toBottom:"前往页尾",
  148. current:"当前页",
  149. forceIframe:"强制拼接",
  150. cancelForceIframe:"取消强制拼接",
  151. configure:"打开配置页面",
  152. firstUpdate:"点击此处初始化规则",
  153. update:"更新规则",
  154. click2update:"点击立即更新规则",
  155. loadNow:"立即翻页",
  156. loadConfirm:"要翻几页?(0为不间断)",
  157. noNext:"没有找到下一页,请新建规则",
  158. passSec:"更新于 #t# 秒前",
  159. passMin:"更新于 #t# 分钟前",
  160. passHour:"更新于 #t# 小时前",
  161. passDay:"更新于 #t# 天前",
  162. cantDel:"无法删除内置规则",
  163. confirmDel:"是否确认要删除此规则?",
  164. updateSucc:"更新成功",
  165. beginUpdate:"正在更新,请耐心等待,不要关闭页面",
  166. customUrls:"导入 Pagetual 或 AutoPagerize 规则 url,一行一条",
  167. customRules:"输入【东方永页机】格式的自定义规则",
  168. save:"保存设置",
  169. loadingText:"少女祈祷中...",
  170. opacity:"不透明值",
  171. opacityPlaceholder:"0: 隐藏分隔条",
  172. hideBar:"隐藏分页隔条",
  173. hideBarButNoStop:"隐藏但不停止",
  174. dbClick2Stop:"空白处双击暂停翻页",
  175. sortTitle:"排序在下次更新规则后生效",
  176. autoRun:"自动启用,否则为白名单模式",
  177. autoLoadNum:"自动加载指定页数",
  178. turnRate:"距离页尾X倍页面高度时就开始翻页",
  179. inputPageNum:"输入页码跳转",
  180. enableHistory:"翻页后写入历史记录",
  181. enableHistoryAfterInsert:"拼接后立即写入历史记录,否则浏览完毕后再行写入",
  182. initRun:"打开页面后立即尝试翻页,否则滚动至页尾再翻页",
  183. preload:"翻页前预读下一页,加速浏览",
  184. click2ImportRule:"点击下方添加特殊规则库,并静待更新成功:",
  185. forceAllBody:"是否拼接整个页面?",
  186. openInNewTab:"使拼接页面的内容在新页面打开",
  187. importSucc:"导入成功",
  188. import:"导入",
  189. editCurrent:"编辑此站规则",
  190. editBlacklist:"编辑黑名单网址,一行一条,支持? *通配符",
  191. upBtnImg:"回到页首图标",
  192. downBtnImg:"前往页尾图标",
  193. loadingTextTitle:"加载中文字",
  194. dbClick2StopCtrl:"Ctrl 键",
  195. dbClick2StopAlt:"Alt 键",
  196. dbClick2StopShift:"Shift 键",
  197. dbClick2StopMeta:"Meta 键",
  198. dbClick2StopKey:"快捷键",
  199. pageElementCss:"页面主体框架的样式",
  200. customCss:"自定义 CSS",
  201. firstAlert:"你还未导入规则库,请选择合适的规则库导入哦",
  202. picker:"东方永页机主体元素抓取器",
  203. closePicker:"关闭东方永页机抓取器",
  204. pickerPlaceholder:"没想法建议留空",
  205. pickerCheck:"检查你编辑的选择器并复制",
  206. switchSelector:"点击切换元素",
  207. gotoEdit:"使用当前的选择器前往编辑规则",
  208. manualMode:"禁用拼接,手动用右方向键翻页,可使用 Alt + 左方向键返回",
  209. clickMode:"禁用拼接,滚动至页尾时自动点击下一页",
  210. pageBarMenu:"点击分隔条中间弹出菜单",
  211. nextSwitch:"切换其他页码",
  212. arrowToScroll:"左方向键滚动至上一页,右方向键滚动至下一页",
  213. sideController:"在侧边显示翻页控制栏",
  214. hideLoadingIcon:"隐藏加载动画",
  215. duplicate:"检测到永页机重复安装,请删除其他脚本管理器中的永页机!",
  216. forceStateIframe:"以 iframe 嵌入整页",
  217. forceStateDynamic:"通过 iframe 加载动态内容后取出",
  218. forceStateDisable:"在此站禁用"
  219. };
  220. break;
  221. case "zh-TW":
  222. case "zh-HK":
  223. config = {
  224. enableDebug:"調試模式,輸出信息至控制台",
  225. disable:"暫時禁用",
  226. disableSite:"切換禁用狀態",
  227. disableSiteTips:"已在此站禁用",
  228. enableSiteTips:"已在此站啟用",
  229. enable:"啟用翻頁",
  230. toTop:"回到頂部",
  231. toBottom:"前往頁尾",
  232. current:"當前頁",
  233. forceIframe:"強制拼接",
  234. cancelForceIframe:"取消强制拼接",
  235. configure:"打開配置頁面",
  236. firstUpdate:"點擊此處初始化規則",
  237. update:"更新規則",
  238. click2update:"點擊立即更新規則",
  239. loadNow:"立即翻頁",
  240. loadConfirm:"要翻几頁?(0為不間斷)",
  241. noNext:"沒有找到下一頁,請新建規則",
  242. passSec:"更新于 #t# 秒前",
  243. passMin:"更新于 #t# 分鐘前",
  244. passHour:"更新于 #t# 小時前",
  245. passDay:"更新于 #t# 天前",
  246. cantDel:"無法刪除内置規則",
  247. confirmDel:"是否確認要刪除此規則?",
  248. updateSucc:"更新成功",
  249. beginUpdate:"正在更新,請稍候",
  250. customUrls:"導入 Pagetual 或 AutoPagerize 規則 url,一行一條",
  251. customRules:"輸入【東方永頁機】格式的自定義規則",
  252. save:"存儲設置",
  253. loadingText:"少女祈禱中...",
  254. opacity:"不透明值",
  255. opacityPlaceholder:"0: 隱藏分隔條",
  256. hideBar:"隱藏分頁隔條",
  257. hideBarButNoStop:"隱藏但不停止",
  258. dbClick2Stop:"空白處雙擊暫停翻頁",
  259. sortTitle:"排序在下次更新規則後生效",
  260. autoRun:"自動啓用,否則為白名單模式",
  261. autoLoadNum:"自動加載指定頁數",
  262. turnRate:"距離頁尾X倍頁面高度時就開始翻頁",
  263. inputPageNum:"輸入頁碼跳轉",
  264. enableHistory:"翻頁后寫入歷史記錄",
  265. enableHistoryAfterInsert:"拼接後立即寫入歷史記錄,否則瀏覽完畢後再行寫入",
  266. initRun:"打開頁面后立即嘗試翻頁,否則滾動至頁尾再翻頁",
  267. preload:"翻頁前預讀下一頁,加速瀏覽",
  268. click2ImportRule:"點擊下方添加特殊規則庫,并靜待更新成功:",
  269. forceAllBody:"是否拼接整個頁面?",
  270. openInNewTab:"使拼接頁面的内容在新頁面打開",
  271. importSucc:"導入成功",
  272. import:"導入",
  273. editCurrent:"編輯此站規則",
  274. editBlacklist:"編輯黑名單網址,一行一條,支持? *通配符",
  275. upBtnImg:"回到頁首圖標",
  276. downBtnImg:"前往頁尾圖標",
  277. loadingTextTitle:"加載中文字",
  278. dbClick2StopCtrl:"Ctrl 鍵",
  279. dbClick2StopAlt:"Alt 鍵",
  280. dbClick2StopShift:"Shift 鍵",
  281. dbClick2StopMeta:"Meta 鍵",
  282. dbClick2StopKey:"快捷鍵",
  283. pageElementCss:"頁面主體框架的樣式",
  284. customCss:"自定義 CSS",
  285. firstAlert:"你還未導入規則庫,請選擇合適的規則庫導入哦",
  286. picker:"東方永頁機主體元素抓取器",
  287. closePicker:"關閉東方永頁機抓取器",
  288. pickerPlaceholder:"沒想法建議留空",
  289. pickerCheck:"檢查你編輯的選擇器並複製",
  290. switchSelector:"點擊切換元素",
  291. gotoEdit:"使用當前的選擇器前往編輯規則",
  292. manualMode:"禁用拼接,手動用右方向鍵翻頁",
  293. clickMode:"禁用拼接,滾動至頁尾時自動點擊下一頁",
  294. pageBarMenu:"點擊分隔條中間彈出菜單",
  295. nextSwitch:"切換其他頁碼",
  296. arrowToScroll:"左方向鍵滾動至上一頁,右方向鍵滾動至下一頁",
  297. sideController:"在側邊顯示翻頁控制欄",
  298. hideLoadingIcon:"隱藏加載動畫",
  299. duplicate:"檢測到永頁機重複安裝,請刪除其他腳本管理器中的永頁機!",
  300. forceStateIframe:"以 iframe 嵌入整頁",
  301. forceStateDynamic:"通過 iframe 加載動態內容後取出",
  302. forceStateDisable:"在此站禁用"
  303. };
  304. break;
  305. case "ja":
  306. config = {
  307. enableDebug:"デバッグモード",
  308. disable: "一時的に無効にする",
  309. disableSite:"無効状態の切り替え",
  310. disableSiteTips:"このサイトで既に無効になっています",
  311. enableSiteTips:"このサイトで既に有効になっています",
  312. enable: "ページめくりを有効にする",
  313. toTop: "トップに戻る",
  314. toBottom: "ページの下部に移動",
  315. current: "現在のページ",
  316. forceIframe: "強制ステッチ",
  317. cancelForceIframe: "強制ステッチをキャンセル",
  318. configure: "設定ページを開く",
  319. firstUpdate:"ここをクリックしてルールを初期化します",
  320. update: "更新ルール",
  321. click2update:"今すぐルールを更新してください",
  322. loadNow:"今すぐページをめくる",
  323. loadConfirm:"数ページめくりたいですか?(0は途切れない)",
  324. noNext:"次のページが見つかりません、新しいルールを作成してください",
  325. passSec: "#t#秒前に更新",
  326. passMin: "#t#分前に更新",
  327. passHour: "#t#時間前に更新",
  328. passDay: "#t#日前に更新",
  329. cantDel: "組み込みルールを削除できません",
  330. confirmDel: "このルールを削除してもよろしいですか?",
  331. updateSucc: "更新に成功しました",
  332. beginUpdate: "更新中、お待ちください",
  333. customUrls: "インポートルールのURL、1行に1つ",
  334. customRules: "【東方永頁機】の形式でカスタムルールを入力してください",
  335. save: "設定を保存",
  336. loadingText: "少女祈祷中...",
  337. opacity:"不透明値",
  338. opacityPlaceholder:"0: 隠す",
  339. hideBar:"ページ区切り文字を非表示にします",
  340. hideBarButNoStop:"非表示にするが停止しない",
  341. dbClick2Stop:"空白部分をダブルクリックしてページめくりを一時停止します",
  342. sortTitle:"並べ替えは、次のルールの更新後に有効になります",
  343. autoRun:"自動的に有効",
  344. autoLoadNum:"指定したページ数を自動的に読み込みます",
  345. turnRate:"ページの端からページの高さの X 倍になったらページをめくる",
  346. inputPageNum:"ジャンプするページ番号を入力",
  347. enableHistory:"ページめくり後の履歴を書く",
  348. enableHistoryAfterInsert: "スプライシングの直後に履歴レコードを書き込みます。それ以外の場合は、閲覧後に書き込みます",
  349. initRun:"Webページを開いた直後にページをめくる",
  350. preload:"事前に次のページを読む",
  351. click2ImportRule:"以下をクリックして、ルールベースを追加します:",
  352. forceAllBody:"フルページ埋め込み?",
  353. openInNewTab:"スプライスされたページのコンテンツを新しいページで開きます",
  354. importSucc:"インポート完了",
  355. import:"インポート",
  356. editCurrent:"現在のルールの編集",
  357. editBlacklist:"ブラックリストのURLを編集し、1行ずつ、サポート? *ワイルドカード",
  358. upBtnImg:"トップアイコンに戻る",
  359. downBtnImg:"フッターアイコンに移動",
  360. loadingTextTitle:"テキストをロード",
  361. dbClick2StopCtrl:"Ctrlキー",
  362. dbClick2StopAlt:"Altキー",
  363. dbClick2StopShift:"Shiftキー",
  364. dbClick2StopMeta:"Metaキー",
  365. dbClick2StopKey:"Shortcutキー",
  366. pageElementCss:"ページ本文フレームの STYLE",
  367. customCss:"カスタム CSS",
  368. firstAlert:"ルールベースをインポートしていないため、インポートする適切なルールベースを選択してください",
  369. picker:"Pagetualページ要素ピッカー",
  370. closePicker:"Pagetualピッカーを閉じる",
  371. pickerPlaceholder:"わからない場合は空のままにしてください",
  372. pickerCheck:"セレクターをチェックしてコピー",
  373. switchSelector:"クリックして要素を切り替えます",
  374. gotoEdit:"現在のセレクターでルールを編集する",
  375. manualMode:"スプライシングを無効にします。手動で右の矢印キーを使用してページをめくります",
  376. clickMode: "スティッチングを無効にします。ページの最後までスクロールすると、次のページが自動的にクリックされます",
  377. pageBarMenu:"ページバーの中央をクリックしてメニューをポップアップ表示",
  378. nextSwitch:"次のページに切り替え",
  379. arrowToScroll:"左矢印キーで前へ、右矢印キーで次へ",
  380. sideController:"サイドバーにページング コントロール バーを表示する",
  381. hideLoadingIcon:"読み込み中のアニメーションを隠す",
  382. duplicate: "Pagetual の重複インストールが検出されました。他のスクリプト マネージャで永続的なページ マシンを削除してください!",
  383. forceStateIframe: "iframe にページ全体を埋め込む",
  384. forceStateDynamic: "iframe 経由で動的コンテンツを読み込む",
  385. forceStateDisable: "このステーションでのページめくりを無効にする"
  386. };
  387. break;
  388. case "ru":
  389. case "ru-RU":
  390. config = {
  391. enableDebug:"Включить отладку",
  392. disable:"Отключено",
  393. disableSite:"Переключить состояние отключения",
  394. disableSiteTips:"Отключено на этом сайте",
  395. enableSiteTips:"Включено на этом сайте",
  396. enable:"Включено",
  397. toTop:"В начало",
  398. toBottom:"В конец",
  399. current:"Текущая страница",
  400. forceIframe:"Принудительно присоединить следующую страницу",
  401. cancelForceIframe:"Отменить принудительное присоединение",
  402. configure:"Настроить",
  403. firstUpdate:"Нажмите здесь, чтобы инициализировать правила",
  404. update:"Обновить правила онлайн",
  405. click2update:"Нажмите, чтобы обновить правила по URL сейчас",
  406. loadNow:"Загрузить следующую страницу сейчас",
  407. loadConfirm:"Сколько страниц вы хотите загрузить? (0 означает бесконечность)",
  408. noNext:"Ссылка на следующую страницу не найдена, пожалуйста, создайте новое правило",
  409. passSec:"Обновлено #t# секунд назад",
  410. passMin:"Обновлено #t# минут назад",
  411. passHour:"Обновлено #t# часов назад",
  412. passDay:"Обновлено #t# дней назад",
  413. cantDel:"Невозможно удалить встроенные правила",
  414. confirmDel:"Вы уверены, что хотите удалить это правило?",
  415. updateSucc:"Обновление прошло успешно",
  416. beginUpdate:"Обновление начато, подождите минуту, пожалуйста",
  417. customUrls:"Импортируйте URL-адрес правила Пэйджтуал или AutoPagerize по одному URL на строку",
  418. customRules:"Введите пользовательские правила с форматом [Pagetual]",
  419. save:"Сохранить",
  420. loadingText:"Shojo загружается...",
  421. opacity:"Непрозрачность",
  422. opacityPlaceholder:"0: скрыть",
  423. hideBar:"Скрыть промежуток переключения страниц",
  424. hideBarButNoStop:"Скрыть, но не останавливать",
  425. dbClick2Stop:"Двойной щелчок по пустому пространству для паузы",
  426. sortTitle:"Сортировка вступает в силу после следующего обновления правила",
  427. autoRun:"Автозапуск (режим черного списка)",
  428. autoLoadNum:"Количество для предварительной загрузки страниц",
  429. turnRate:"Переверните страницу, когда она будет в X раз больше высоты страницы от конца страницы",
  430. inputPageNum:"Введите номер страницы для перехода",
  431. enableHistory:"Записать историю после переключения страниц",
  432. enableHistoryAfterInsert: "Записать запись истории сразу после сплайсинга, в противном случае запишите после просмотра",
  433. initRun:"Переключать страницы сразу после открытия",
  434. preload:"Предварительная загрузка следующей страницы для ускорения",
  435. click2ImportRule:"Нажмите, чтобы импортировать ссылку базовых правил, затем дождитесь завершения обновления:",
  436. forceAllBody:"Присоединить полное тело страницы?",
  437. openInNewTab:"Открыть дополнительные URL-адреса в новой вкладке",
  438. importSucc:"Импорт завершен",
  439. import:"Импорт",
  440. editCurrent:"Редактировать правило для текущего",
  441. editBlacklist:"Редактировать URL-адреса черного списка, по одной строке, поддержка ? * для подстановочного знака",
  442. upBtnImg:"Иконка перехода к началу страницы",
  443. downBtnImg:"Иконка перехода к концу страницы",
  444. loadingTextTitle:"Текст загрузки",
  445. dbClick2StopCtrl:"Клавиша Ctrl",
  446. dbClick2StopAlt:"Клавиша Alt",
  447. dbClick2StopShift:"Клавиша Shift",
  448. dbClick2StopMeta:"Клавиша Meta",
  449. dbClick2StopKey:"Клавиша быстрого доступа",
  450. pageElementCss:"Пользовательский стиль для основных элементов страницы",
  451. customCss:"Полный пользовательский CSS",
  452. firstAlert:"Вы не импортировали базовое правило, пожалуйста, выберите соответствующее правило для импорта",
  453. picker:"Выбор элемента страницы Пэйджтуал",
  454. closePicker:"Закрыть выбор Пэйджтуал",
  455. pickerPlaceholder:"Оставьте пустым, если вы не знаете",
  456. pickerCheck:"Проверить селектор и скопируй",
  457. switchSelector:"нажмите для переключения элемента",
  458. gotoEdit:"Перейти к редактированию правила с текущим селектором",
  459. manualMode:"Отключить автоматическую перелистывание страниц, перелистывать страницы вручную с помощью стрелок справа (или вызвать событие 'pagetual.next')",
  460. clickMode: "Отключить \"сшивание\" страниц, т.е. автоматически переходить на следующую страницу при прокрутке к ее концу",
  461. pageBarMenu:"Щелкните середину панели страниц, чтобы открыть меню.",
  462. nextSwitch:"Переключить ссылку на следующую страницу",
  463. arrowToScroll:"Нажмите клавишу со стрелкой влево для предыдущего и клавишу со стрелкой вправо для следующего",
  464. sideController:"Отображение панели управления пейджингом на боковой панели",
  465. hideLoadingIcon:"Скрыть анимацию загрузки",
  466. duplicate: "Обнаружена двойная установка Pagetual, пожалуйста, удалите постоянную страничную машину в других менеджерах скриптов!",
  467. forceStateIframe: "Вставить полную страницу как iframe",
  468. forceStateDynamic:"Загружать динамический контент через iframe",
  469. forceStateDisable: "Отключить перелистывание страниц на этой станции"
  470. };
  471. break;
  472. default:
  473. config = {
  474. enableDebug:"Enable debug output",
  475. disable:"Disable",
  476. disableSite:"Toggle disabled state",
  477. disableSiteTips:"Disabled on this site",
  478. enableSiteTips:"Enabled on this site",
  479. enable:"Enable",
  480. toTop:"To Top",
  481. toBottom:"To Bottom",
  482. current:"Current Page",
  483. forceIframe:"Force to join next page",
  484. cancelForceIframe:"Cancel Force join",
  485. configure:"Configure",
  486. firstUpdate:"Click here to initialize the rules",
  487. update:"Update online rules",
  488. click2update:"Click to update rules from url now",
  489. loadNow:"Load next page manually",
  490. loadConfirm:"How much pages do you want to load? (0 means infinite)",
  491. noNext:"No next link found, please create a new rule",
  492. passSec:"Updated #t# seconds ago",
  493. passMin:"Updated #t# minutes ago",
  494. passHour:"Updated #t# hours ago",
  495. passDay:"Updated #t# days ago",
  496. cantDel:"Can't delete buildin rules",
  497. confirmDel:"Are you sure you want to delete this rule?",
  498. updateSucc:"Update succeeded",
  499. beginUpdate:"Begin update, wait a minute please",
  500. customUrls:"Import Pagetual or AutoPagerize rule url, One url per line",
  501. customRules:"Input custom rules with [Pagetual] format",
  502. save:"Save",
  503. loadingText:"Shojo Now Loading...",
  504. opacity:"Opacity",
  505. opacityPlaceholder:"0: hide spacer",
  506. hideBar:"Hide the paging spacer",
  507. hideBarButNoStop:"Hide but not stop",
  508. dbClick2Stop:"Double-click on the blank space to pause",
  509. sortTitle:"Sorting takes effect after the next rule update",
  510. autoRun:"Auto run (black list mode)",
  511. autoLoadNum:"Amount for preload pages",
  512. turnRate:"Turn the next page when it's less than X times page height from the footer",
  513. inputPageNum:"Enter page number to jump",
  514. enableHistory:"Write history after page turning",
  515. enableHistoryAfterInsert: "Write history immediately after splicing, otherwise write after browsing",
  516. initRun:"Turn pages immediately after opening",
  517. preload:"Preload next page for speeding up",
  518. click2ImportRule:"Click to import base rules link, then wait until the update is complete:",
  519. forceAllBody:"Join full body of page?",
  520. openInNewTab:"Open urls of additions in new tab",
  521. importSucc:"Import completed",
  522. import:"Import",
  523. editCurrent:"Edit rule for current",
  524. editBlacklist:"Edit the blacklist urls, line by line, Support ? * for wildcard",
  525. upBtnImg:"Icon of back to top",
  526. downBtnImg:"Icon of go to footer",
  527. loadingTextTitle:"Loading text",
  528. dbClick2StopCtrl:"Ctrl key",
  529. dbClick2StopAlt:"Alt key",
  530. dbClick2StopShift:"Shift key",
  531. dbClick2StopMeta:"Meta key",
  532. dbClick2StopKey:"Shortcut key",
  533. pageElementCss:"Custom style for main page elements",
  534. customCss:"Custom complete css",
  535. firstAlert:"You have not imported the base rule, please select the appropriate rule to import",
  536. picker:"Pagetual page element picker",
  537. closePicker:"Close Pagetual picker",
  538. pickerPlaceholder:"Leave empty if you have no idea",
  539. pickerCheck:"Check selector and copy",
  540. switchSelector:"Click to switch element",
  541. gotoEdit:"Go to edit rule with current selector",
  542. manualMode:"Disable splicing, manually turn pages with the right arrow keys (or dispatch event 'pagetual.next')",
  543. clickMode: "Disable splicing, automatically click the next page when scrolling to the end of the page",
  544. pageBarMenu:"Click the middle of the page bar to open the menu",
  545. nextSwitch:"Switch next link",
  546. arrowToScroll:"Press left arrow key to scroll prev and right arrow key to scroll next",
  547. sideController:"Display the paging control bar in the sidebar",
  548. hideLoadingIcon:"Hide loading animation",
  549. duplicate:"Duplicate Pagetual have been installed, check your script manager!",
  550. forceStateIframe: "Embed full page as iframe",
  551. forceStateDynamic: "Load dynamic content via iframe",
  552. forceStateDisable: "Disable page turning on this site"
  553. };
  554. break;
  555. }
  556. var enableDebug=true;
  557. function i18n(name, param) {
  558. return config[name]?config[name].replace("#t#",param):name;
  559. };
  560.  
  561. function debug(str, title) {
  562. if(enableDebug){
  563. console.log(
  564. `%cPagetual v.${_GM_info.script.version}】 ${title ? title : 'debug'}:`,
  565. 'color: yellow;font-size: large;font-weight: bold;background-color: darkblue;',
  566. str
  567. );
  568. }
  569. };
  570.  
  571. var _GM_xmlhttpRequest,_GM_registerMenuCommand,_GM_notification,_GM_addStyle,_GM_openInTab,_GM_info,_GM_setClipboard;
  572. if(typeof GM_xmlhttpRequest!='undefined'){
  573. _GM_xmlhttpRequest=GM_xmlhttpRequest;
  574. }else if(typeof GM!='undefined' && typeof GM.xmlHttpRequest!='undefined'){
  575. _GM_xmlhttpRequest=GM.xmlHttpRequest;
  576. }else{
  577. _GM_xmlhttpRequest=(f)=>{fetch(f.url).then(response=>response.text()).then(data=>{let res={response:data};f.onload(res)}).catch(e => f.onerror(e))};
  578. }
  579. if(typeof GM_registerMenuCommand!='undefined'){
  580. _GM_registerMenuCommand=GM_registerMenuCommand;
  581. }else if(typeof GM!='undefined' && typeof GM.registerMenuCommand!='undefined'){
  582. _GM_registerMenuCommand=GM.registerMenuCommand;
  583. }else{
  584. _GM_registerMenuCommand=(s,f)=>{};
  585. }
  586. if(typeof GM_info!='undefined'){
  587. _GM_info=GM_info;
  588. }else if(typeof GM!='undefined' && typeof GM.info!='undefined'){
  589. _GM_info=GM.info;
  590. }else{
  591. _GM_info={script:1};
  592. }
  593. if(typeof GM_notification!='undefined'){
  594. _GM_notification=GM_notification;
  595. }else if(typeof GM!='undefined' && typeof GM.notification!='undefined'){
  596. _GM_notification=GM.notification;
  597. }else{
  598. _GM_notification=(s)=>{showTips(s)};
  599. }
  600. if(typeof GM_openInTab!='undefined'){
  601. _GM_openInTab=GM_openInTab;
  602. }else if(typeof GM!='undefined' && typeof GM.openInTab!='undefined'){
  603. _GM_openInTab=GM.openInTab;
  604. }else{
  605. _GM_openInTab=(s,t)=>{window.open(s)};
  606. }
  607. if(typeof GM_addStyle!='undefined'){
  608. _GM_addStyle=GM_addStyle;
  609. }else if(typeof GM!='undefined' && typeof GM.addStyle!='undefined'){
  610. _GM_addStyle=GM.addStyle;
  611. }else{
  612. _GM_addStyle=cssStr=>{
  613. let styleEle=document.createElement("style");
  614. styleEle.innerHTML=cssStr;
  615. document.head.appendChild(styleEle);
  616. return styleEle;
  617. };
  618. }
  619. if (typeof GM_setClipboard != 'undefined') {
  620. _GM_setClipboard = GM_setClipboard;
  621. } else if (typeof GM != 'undefined' && typeof GM.setClipboard != 'undefined') {
  622. _GM_setClipboard = GM.setClipboard;
  623. } else {
  624. _GM_setClipboard = (s, i) => {};
  625. }
  626. var _unsafeWindow=(typeof unsafeWindow=='undefined')?window:unsafeWindow;//兼容 ios userscripts 的寫法
  627. var storage={
  628. supportGM: typeof GM_getValue=='function' && typeof GM_getValue('a','b')!='undefined',
  629. supportGMPromise: typeof GM!='undefined' && typeof GM.getValue=='function' && typeof GM.getValue('a','b')!='undefined',
  630. mxAppStorage:(function(){
  631. try{
  632. return window.external.mxGetRuntime().storage;
  633. }catch(e){
  634. }
  635. })(),
  636. operaUJSStorage:(function(){
  637. try{
  638. return window.opera.scriptStorage;
  639. }catch(e){
  640. }
  641. })(),
  642. setItem:function(key,value){
  643. if(this.operaUJSStorage){
  644. this.operaUJSStorage.setItem(key,value);
  645. }else if(this.mxAppStorage){
  646. this.mxAppStorage.setConfig(key,value);
  647. }else if(this.supportGM){
  648. GM_setValue(key,value);
  649. if(value==="" && typeof GM_deleteValue!='undefined'){
  650. GM_deleteValue(key);
  651. }
  652. }else if(this.supportGMPromise){
  653. GM.setValue(key,value);
  654. if(value==="" && typeof GM!='undefined' && typeof GM.deleteValue!='undefined'){
  655. GM.deleteValue(key);
  656. }
  657. }else if(window.localStorage){
  658. window.localStorage.setItem(key,value);
  659. }
  660. },
  661. getItem:function(key,cb){
  662. var value;
  663. if(this.operaUJSStorage){
  664. value=this.operaUJSStorage.getItem(key);
  665. }else if(this.mxAppStorage){
  666. value=this.mxAppStorage.getConfig(key);
  667. }else if(this.supportGM){
  668. value=GM_getValue(key);
  669. }else if(this.supportGMPromise){
  670. value=GM.getValue(key).then(v=>{cb(v)});
  671. return;
  672. }else if(window.localStorage){
  673. value=window.localStorage.getItem(key);
  674. };
  675. cb(value);
  676. }
  677. };
  678. var rulesData = {}, ruleUrls, updateDate;
  679. const configPage = ["https://github.com/hoothin/UserScripts/tree/master/Pagetual",
  680. "https://hoothin.github.io/UserScripts/Pagetual/"];
  681. const guidePage = /^https?:\/\/.*pagetual.*rule\.html/i;
  682. const ruleImportUrlReg = /greasyfork\.org\/.*scripts\/438684[^\/]*(\/discussions|\/?$)|github\.com\/hoothin\/UserScripts\/(tree\/master\/Pagetual|issues\/)/i;
  683. const allOfBody = "body>*";
  684. const nextTextReg1 = new RegExp("\u005e\u7ffb\u003f\u005b\u4e0b\u540e\u5f8c\u6b21\u005d\u005b\u4e00\u30fc\u0031\u005d\u003f\u005b\u9875\u9801\u5f20\u5f35\u005d\u007c\u005e\u0028\u006e\u0065\u0078\u0074\u005b\u0020\u005f\u002d\u005d\u003f\u0070\u0061\u0067\u0065\u007c\u006f\u006c\u0064\u0065\u0072\u0029\u005c\u0073\u002a\u005b\u203a\u003e\u2192\u00bb\u005d\u003f\u0024\u007c\u6b21\u306e\u30da\u30fc\u30b8\u007c\u005e\u6b21\u3078\u003f\u0024\u007cВперед", "i");
  685. const nextTextReg2 = new RegExp("\u005e\u005b\u4e0b\u540e\u5f8c\u6b21\u005d\u005b\u4e00\u30fc\u0031\u005d\u003f\u005b\u7ae0\u8bdd\u8a71\u8282\u7bc0\u4e2a\u500b\u5e45\u005d", "i");
  686. _GM_registerMenuCommand(i18n("configure"), ()=>{
  687. _GM_openInTab(configPage[0],{active:true});
  688. });
  689. _GM_registerMenuCommand(i18n("editCurrent"), ()=>{
  690. Picker.getInstance().start();
  691. });
  692.  
  693. function getElementByXpath(xpath, contextNode, doc){
  694. doc = doc || document;
  695. contextNode = contextNode || doc;
  696. try {
  697. var result = doc.evaluate(xpath, contextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
  698. return result.singleNodeValue && result.singleNodeValue.nodeType === 1 && result.singleNodeValue;
  699. } catch (err) {
  700. debug(`Invalid xpath: ${xpath}`);
  701. }
  702. return null;
  703. }
  704.  
  705. function getAllElementsByXpath(xpath, contextNode, doc){
  706. doc = doc || document;
  707. contextNode = contextNode || doc;
  708. var result = [];
  709. try {
  710. var query = doc.evaluate(xpath, contextNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  711. for (var i = 0; i < query.snapshotLength; i++) {
  712. var node = query.snapshotItem(i);
  713. if (node.nodeType === 1) result.push(node);
  714. }
  715. } catch (err) {
  716. debug(`Invalid xpath: ${xpath}`);
  717. }
  718. return result;
  719. }
  720.  
  721. function isXPath(xpath) {
  722. if (!xpath) return false;
  723. return /^\(*(descendant::|\.\/|\/\/|id\()/.test(xpath);
  724. }
  725.  
  726. function getAllElements(sel, doc) {
  727. try {
  728. if (!isXPath(sel)) {
  729. return doc.querySelectorAll(sel);
  730. }
  731. } catch(e) {
  732. debug(e, 'Error selector');
  733. }
  734. return getAllElementsByXpath(sel, doc, doc);
  735. }
  736.  
  737. function getElement(sel, doc) {
  738. try {
  739. if (!isXPath(sel)) {
  740. return doc.querySelector(sel);
  741. }
  742. } catch(e) {
  743. debug(e, 'Error selector');
  744. }
  745. return getElementByXpath(sel, doc, doc);
  746. }
  747.  
  748. function geneSelector(ele, addID) {
  749. let selector = ele.tagName.toLowerCase();
  750. //Google id class都是隨機。百度更過分,style script順序都是隨機的
  751. if (ele.tagName != "HTML" && ele.tagName != "BODY") {
  752. let hasId = false;
  753. if (addID && ele.id && /^[a-z_][\w\-_]*$/i.test(ele.id)) {
  754. hasId = true;
  755. selector += '#' + ele.id;
  756. }
  757. let className = "";
  758. if (ele.className) {
  759. let classList = ele.classList, i = 0;
  760. for (let i = 0; i < classList.length; i++) {
  761. let c = classList[i];
  762. if (/^[\w\-_]+$/.test(c) && !/\d{3,}/.test(c)) {
  763. className += '.' + c;
  764. }
  765. }
  766. selector += className;
  767. }
  768. let parent = ele.parentElement;
  769. if (parent) {
  770. selector = geneSelector(parent, addID) + ' > ' + selector;
  771. if (!className && !hasId && parent.children.length > 1) {
  772. let i, j = 0;
  773. for (i = 0; i < parent.children.length; i++) {
  774. if (parent.children[i].tagName == ele.tagName) {
  775. j++;
  776. if (parent.children[i] == ele) {
  777. break;
  778. }
  779. }
  780. }
  781. selector += (parent.tagName == "HTML" ? "" : `:nth-of-type(${j})`);
  782. }
  783. }
  784. }
  785. return selector;
  786. }
  787.  
  788. function createXPathFromElement(elm) {
  789. let allNodes = document.getElementsByTagName('*'), segs;
  790. for (segs = []; elm && elm.nodeType == 1; elm = elm.parentNode) {
  791. if (elm.hasAttribute('id')) {
  792. var uniqueIdCount = 0;
  793. for (var n=0;n < allNodes.length;n++) {
  794. if (allNodes[n].hasAttribute('id') && allNodes[n].id == elm.id) uniqueIdCount++;
  795. if (uniqueIdCount > 1) break;
  796. }
  797. if ( uniqueIdCount == 1) {
  798. segs.unshift('id("' + elm.getAttribute('id') + '")');
  799. return segs.join('/');
  800. } else {
  801. segs.unshift(elm.localName.toLowerCase() + '[@id="' + elm.getAttribute('id') + '"]');
  802. }
  803. } else if (elm.hasAttribute('class')) {
  804. segs.unshift(elm.localName.toLowerCase() + '[@class="' + elm.getAttribute('class') + '"]');
  805. } else {
  806. let i, sib;
  807. for (i = 1, sib = elm.previousSibling; sib; sib = sib.previousSibling) {
  808. if (sib.localName == elm.localName) i++;
  809. }
  810. segs.unshift(elm.localName.toLowerCase() + '[' + i + ']');
  811. }
  812. }
  813. return segs.length ? '/' + segs.join('/') : null;
  814. }
  815.  
  816. var escapeHTMLPolicy;
  817. if (_unsafeWindow.trustedTypes && _unsafeWindow.trustedTypes.createPolicy) {
  818. escapeHTMLPolicy = _unsafeWindow.trustedTypes.createPolicy('pagetual_default', {
  819. createHTML: (string, sink) => string
  820. });
  821. }
  822.  
  823. function createHTML(html){
  824. return escapeHTMLPolicy?escapeHTMLPolicy.createHTML(html):html;
  825. }
  826.  
  827. const AsyncFunction = Object.getPrototypeOf(async function(){}).constructor;
  828.  
  829. class RuleParser {
  830. constructor() {
  831. this.hpRules = [];
  832. this.smartRules = [];
  833. this.customRules = [];
  834. this.rules = [];
  835. this.pageDoc = document;
  836. this.nextLinkHref = null;
  837. this.nextTitle = "";
  838. this.oldUrl = "";
  839. this.curUrl = location.href;
  840. this.curSiteRule = {};
  841. this.initGetPage = true;
  842. }
  843.  
  844. initSavedRules(callback) {
  845. var self = this;
  846. storage.getItem("smartRules", smartRules => {
  847. if (smartRules) self.smartRules = smartRules;
  848. storage.getItem("hpRules", hpRules => {
  849. if (hpRules) self.hpRules = hpRules;
  850. storage.getItem("customRules", customRules => {
  851. if (customRules) self.customRules = customRules;
  852. storage.getItem("rules", rules => {
  853. if (rules) self.rules = rules;
  854. callback();
  855. });
  856. });
  857. });
  858. });
  859. }
  860.  
  861. saveCurSiteRule(){
  862. /*if(!this.curSiteRule || !this.curSiteRule.url || this.curSiteRule.singleUrl || this.curSiteRule.url.length<13)return;
  863. this.hpRules=this.hpRules.filter(item=>{return item&&item.url!=this.curSiteRule.url});
  864. this.hpRules.unshift(this.curSiteRule);
  865. if(this.hpRules.length>30){
  866. this.hpRules.pop();
  867. }
  868. storage.setItem("hpRules", this.hpRules);*/
  869. }
  870.  
  871. requestJSON(url, callback){
  872. _GM_xmlhttpRequest({
  873. url: url,
  874. method: 'GET',
  875. timeout: 20000,
  876. onload: function(res) {
  877. let json=null;
  878. try{
  879. json=JSON.parse(res.response||res.responseText);
  880. }catch(e){
  881. debug(e, 'Error json');
  882. }
  883. callback(json);
  884. },
  885. onerror: function(e) {
  886. callback(null, e);
  887. },
  888. ontimeout: function(e) {
  889. callback(null, e);
  890. }
  891. });
  892. }
  893.  
  894. formatRule(item, from){
  895. if(item.data && item.data.url){
  896. let result = {
  897. name:item.name,
  898. from:from,
  899. action:item.data.forceIframe=="true"?1:0,
  900. url:item.data.url,
  901. pageElement:item.data.pageElement,
  902. nextLink:item.data.nextLink,
  903. insert:item.data.insertBefore||undefined,
  904. updatedAt:item.updated_at
  905. };
  906. let _css = (item.data.Stylus || '') + (item.data.CSS || '');
  907. if (_css) result.css = _css;
  908. if (item.data.bookmarklet) result.pageAction = item.data.bookmarklet;
  909. return result;
  910. }else{
  911. item.from=from;
  912. return item;
  913. }
  914. return null;
  915. }
  916.  
  917. addRuleByUrl(url, from, callback) {
  918. if(url.indexOf("?")==-1){
  919. url=url+"?"+Date.now();
  920. }else{
  921. url=url+"&"+Date.now();
  922. }
  923. this.requestJSON(url, (json,err)=>{
  924. if(!json){
  925. debug(err, "Update "+url+" rules fail!");
  926. }
  927. this.addRules(json, from);
  928. callback(json, err);
  929. });
  930. }
  931.  
  932. addRules(rules, from) {
  933. if(rules && rules.length>0){
  934. this.rules=this.rules.filter(item=>{return item.from!=from});
  935. rules.forEach(item=>{
  936. let rule=this.formatRule(item, from);
  937. if(rule){
  938. this.rules.unshift(rule);
  939. }
  940. });
  941. }
  942. }
  943.  
  944. ruleMatch(r) {
  945. let findIndex = 0;
  946. if (r.nextLink && r.nextLink != "0" && r.nextLink != 0) {
  947. let nextLinkSel = r.nextLink, nextLink;
  948. if (Array && Array.isArray && Array.isArray(nextLinkSel)) {
  949. nextLink = !nextLinkSel.every((sel, i) => {
  950. let ele = getElement(sel, document);
  951. if (ele) findIndex = i;
  952. return !ele;
  953. });
  954. } else nextLink = getElement(nextLinkSel, document);
  955. if (!nextLink) return false;
  956. }
  957. if (r.pageElement) {
  958. let pageElementSel = r.pageElement, pageElement;
  959. if (Array && Array.isArray && Array.isArray(pageElementSel)) {
  960. pageElementSel = pageElementSel[findIndex];
  961. }
  962. pageElement = getElement(pageElementSel, document);
  963. if (!pageElement) return false;
  964. }
  965. if (r.insert) {
  966. let insertSel = r.insert, insert;
  967. if (Array && Array.isArray && Array.isArray(insertSel)) {
  968. insertSel = insertSel[findIndex];
  969. }
  970. insert = getElement(insertSel, document);
  971. if (!insert) return false;
  972. }
  973. //if (findIndex !== 0) nextIndex = findIndex;
  974. return true;
  975. }
  976.  
  977. scrollToShow(sel, doc) {
  978. let exclude = getElement(sel, doc);
  979. if (exclude) {
  980. var actualTop = exclude.offsetTop;
  981. var current = exclude.offsetParent;
  982. while (current !== null) {
  983. actualTop += current.offsetTop;
  984. current = current.offsetParent;
  985. }
  986. doc.body.scrollTop = 0;
  987. doc.documentElement.scrollTop = 0;
  988. let maxHeight = Math.max(doc.body.scrollHeight, doc.documentElement.scrollHeight);
  989. doc.body.scrollTop = actualTop - 10;
  990. doc.documentElement.scrollTop = actualTop - 10;
  991. setTimeout(() => {
  992. while (actualTop < maxHeight) {
  993. actualTop += 200;
  994. doc.body.scrollTop = actualTop;
  995. doc.documentElement.scrollTop = actualTop;
  996. }
  997. }, 0);
  998. return false;
  999. }
  1000. return true;
  1001. }
  1002.  
  1003. waitElement(doc, selArr) {
  1004. if (!selArr) selArr = this.curSiteRule.waitElement;
  1005. if (selArr[0].trim()) {
  1006. let include = getElement(selArr[0], doc);
  1007. if (!include) {
  1008. if (selArr.length == 2 && selArr[1].trim()) {
  1009. this.scrollToShow(selArr[1], doc);
  1010. }
  1011. return false;
  1012. }
  1013. }
  1014. if (doc === document) return true;
  1015. if (selArr.length == 2 && selArr[1].trim()) {
  1016. if (!this.scrollToShow(selArr[1], doc)) {
  1017. if (!document.documentElement.contains(loadingDiv) && this.insert.parentNode) {
  1018. this.insertElement(loadingDiv);
  1019. }
  1020. return false;
  1021. }
  1022. }
  1023. return true;
  1024. }
  1025.  
  1026. getRule(callback) {
  1027. if(noRuleTest){
  1028. this.curSiteRule={};
  1029. this.curSiteRule.url=location.origin+location.pathname;
  1030. this.curSiteRule.singleUrl=true;
  1031. callback();
  1032. return;
  1033. }
  1034. if(this.curSiteRule && this.curSiteRule.url){
  1035. return this.curSiteRule;
  1036. }
  1037. var self=this;
  1038.  
  1039. function setRule(r) {
  1040. self.curSiteRule=r;
  1041. if (!r.singleUrl) {
  1042. debug(r, 'Match rule');
  1043. }
  1044. callback();
  1045. }
  1046.  
  1047. function checkRule(r) {
  1048. if (r.from == 1 && r.url.length <= 13) return false;
  1049. let urlReg=new RegExp(r.url, "i");
  1050. if(urlReg.test(location.href)){
  1051. if(r.include){
  1052. let include;
  1053. if (Array && Array.isArray && Array.isArray(r.include)) {
  1054. include = r.include.every((sel, i) => {
  1055. let ele = getElement(sel, document);
  1056. return !!ele;
  1057. });
  1058. } else include = getElement(r.include, document);
  1059. if (!include) return false;
  1060. }
  1061. if(r.exclude){
  1062. let exclude;
  1063. if (Array && Array.isArray && Array.isArray(r.exclude)) {
  1064. exclude = !r.exclude.every((sel, i) => {
  1065. let ele = getElement(sel, document);
  1066. return !ele;
  1067. });
  1068. } else exclude = getElement(r.exclude, document);
  1069. if (exclude) return false;
  1070. }
  1071. if(r.waitElement){
  1072. let waitTime=500;
  1073. let checkReady=()=>{
  1074. setTimeout(()=>{
  1075. if(!self.waitElement(document, r.waitElement)){
  1076. checkReady();
  1077. }else{
  1078. setRule(r);
  1079. }
  1080. },parseInt(waitTime));
  1081. };
  1082. checkReady();
  1083. return true;
  1084. }else if(r.wait){
  1085. let waitTime=500, checkEval, maxCheckTimes=20;
  1086. if(isNaN(r.wait)){
  1087. try{
  1088. checkEval=(typeof _unsafeWindow.pagetualWait=='undefined') ? Function("doc",'"use strict";' + r.wait) : _unsafeWindow.pagetualWait;
  1089. }catch(e){
  1090. debug(e, 'Error when checkeval');
  1091. }
  1092. }else{
  1093. waitTime=r.wait;
  1094. }
  1095. let checkReady=()=>{
  1096. if(maxCheckTimes--<=0){
  1097. debug("Wait for rule ready but failed");
  1098. setRule(r);
  1099. return;
  1100. }
  1101. setTimeout(()=>{
  1102. if(!self.ruleMatch(r) || (checkEval && !checkEval(document))){
  1103. checkReady();
  1104. }else{
  1105. setRule(r);
  1106. }
  1107. },parseInt(waitTime));
  1108. };
  1109. checkReady();
  1110. return true;
  1111. }
  1112. if(r.pinUrl){
  1113. setRule(r);
  1114. return true;
  1115. }
  1116. if(!self.ruleMatch(r)){
  1117. return false;
  1118. }
  1119. setRule(r);
  1120. return true;
  1121. }
  1122. return false;
  1123. }
  1124.  
  1125. for (let i in this.hpRules) {
  1126. let rule = this.hpRules[i];
  1127. if (!rule || !rule.url) continue;
  1128. if (rule.singleUrl) {
  1129. continue;
  1130. }
  1131. if (checkRule(rule)) return;
  1132. }
  1133. for (let i in this.customRules) {
  1134. let rule = this.customRules[i];
  1135. if (!rule || !rule.url) continue;
  1136. if (checkRule(rule)) return;
  1137. }
  1138. for (let i in this.smartRules) {
  1139. let rule = this.smartRules[i];
  1140. if (!rule || !rule.url) continue;
  1141. if (rule.singleUrl) {
  1142. if (location.origin + location.pathname == rule.url) {
  1143. setRule(rule);
  1144. return;
  1145. }
  1146. continue;
  1147. }
  1148. }
  1149. let r = 0;
  1150. function searchByTime(){
  1151. setTimeout(()=>{
  1152. let end=r+50;
  1153. end=end>self.rules.length?self.rules.length:end;
  1154. for(;r<end;r++){
  1155. let rule=self.rules[r];
  1156. delete rule.autoLoadNum;
  1157. delete rule.history;
  1158. if(checkRule(rule))return;
  1159. }
  1160. if(end>=self.rules.length){
  1161. self.curSiteRule={};
  1162. self.curSiteRule.url=location.origin+location.pathname;
  1163. self.curSiteRule.singleUrl=true;
  1164. callback();
  1165. return;
  1166. }else{
  1167. searchByTime();
  1168. }
  1169. },1);
  1170. }
  1171. searchByTime();
  1172. }
  1173.  
  1174. replaceElement(doc) {
  1175. if (!doc || doc === document) return;
  1176. let replaceElementSel = this.curSiteRule.replaceElement;
  1177. if (replaceElementSel) {
  1178. if (!Array.isArray(replaceElementSel)) {
  1179. replaceElementSel = [replaceElementSel];
  1180. }
  1181. replaceElementSel.forEach(sel => {
  1182. let pageEles = getAllElements(sel, document);
  1183. let replaceEles = getAllElements(sel, doc);
  1184. for (let i = 0; i < pageEles.length; i++) {
  1185. let replaceEle = replaceEles[i];
  1186. let pageEle = pageEles[i];
  1187. if (replaceEle) {
  1188. pageEle.parentNode.replaceChild(replaceEle.cloneNode(true), pageEle);
  1189. } else break;
  1190. }
  1191. });
  1192. }
  1193. }
  1194.  
  1195. refreshByClick() {
  1196. let refreshByClickSel = this.curSiteRule.refreshByClick;
  1197. if (refreshByClickSel) {
  1198. document.addEventListener("click", e => {
  1199. let checkEles = getAllElements(refreshByClickSel, document);
  1200. for (let i = 0; i < checkEles.length; i++) {
  1201. if (checkEles[i] === e.target) {
  1202. urlChanged = true;
  1203. isPause = true;
  1204. if (!ruleParser.nextLinkHref) isLoading = false;
  1205. break;
  1206. }
  1207. }
  1208. });
  1209. }
  1210. }
  1211.  
  1212. getPageElement(doc, curWin, dontFind) {
  1213. if(doc==document && this.docPageElement){
  1214. let parent=this.docPageElement;
  1215. while(parent && parent.nodeName!="BODY"){
  1216. parent=parent.parentNode;
  1217. }
  1218. if(parent && parent.nodeName=="BODY"){
  1219. return this.docPageElement;
  1220. }
  1221. }
  1222. let pageElement=null;
  1223. let self=this;
  1224. let body=doc.body;
  1225. if(this.curSiteRule.pageElement){
  1226. let pageElementSel=this.curSiteRule.pageElement;
  1227. if(Array && Array.isArray && Array.isArray(pageElementSel)){
  1228. pageElementSel=pageElementSel[nextIndex<pageElementSel.length?nextIndex:0];
  1229. }
  1230. pageElement=getAllElements(pageElementSel, doc);
  1231. }
  1232. if(pageElement && pageElement.length===1 && pageElement[0].style.display==='none'){
  1233. pageElement=[body];
  1234. }
  1235. if(this.curSiteRule.singleUrl && pageElement && pageElement.length>0 && pageElement[0].tagName=="TR"){
  1236. let mainTr=this.insert.parentNode.querySelector('tr'),mainTdNum=0,newTdNum=0;
  1237. [].forEach.call(mainTr.children, el=>{
  1238. if(el.tagName=="TD" || el.tagName=="TH"){
  1239. mainTdNum+=el.colSpan||1;
  1240. }
  1241. });
  1242. [].forEach.call(pageElement[0].children, el=>{
  1243. if(el.tagName=="TD" || el.tagName=="TH"){
  1244. newTdNum+=el.colSpan||1;
  1245. }
  1246. });
  1247. if(mainTdNum!=newTdNum){
  1248. this.curSiteRule.pageElement=allOfBody;
  1249. pageElement=[body];
  1250. this.getInsert(true);
  1251. }
  1252. }
  1253. if((this.curSiteRule.singleUrl || !this.curSiteRule.pageElement) && (!pageElement || pageElement.length==0) && curWin && !dontFind){
  1254. if(!body)return null;
  1255. let bodyHeight=parseInt(body.offsetHeight || body.scrollHeight);
  1256. let curHeight=bodyHeight;
  1257. let windowHeight=window.innerHeight || document.documentElement.clientHeight;
  1258. let needCheckNext=(doc==document && this.initNext);
  1259. function checkElement(ele){
  1260. if (ele.tagName == "PRE" || ele.tagName == "CODE") {
  1261. self.curSiteRule.pageElement = geneSelector(ele.parentNode);
  1262. debug(self.curSiteRule.pageElement, 'Page element');
  1263. return [ele.parentNode];
  1264. }
  1265. if(ele.childNodes && ele.childNodes.length==1)ele=ele.childNodes[0];
  1266. if(ele.tagName=="PICTURE"){
  1267. self.curSiteRule.pageElement=geneSelector(ele.parentNode)+">"+ele.tagName.toLowerCase();
  1268. debug(self.curSiteRule.pageElement, 'Page element');
  1269. return [ele];
  1270. }
  1271. if(curHeight/bodyHeight<=0.25){
  1272. self.curSiteRule.pageElement=allOfBody;
  1273. debug(self.curSiteRule.pageElement, 'Page element');
  1274. return [body];
  1275. }
  1276. if(ele.tagName=="FORM" && ele.parentNode!=document.body){
  1277. self.curSiteRule.pageElement=geneSelector(ele)+">*";
  1278. debug(self.curSiteRule.pageElement, 'Page element');
  1279. return ele.children;
  1280. }
  1281. if(ele.children.length==0 && !self.curSiteRule.pageElement){
  1282. if(ele.parentNode.tagName=="P")ele=ele.parentNode;
  1283. self.curSiteRule.pageElement=geneSelector(ele.parentNode)+">"+ele.tagName.toLowerCase();
  1284. debug(self.curSiteRule.pageElement, 'Page element');
  1285. return getAllElements(self.curSiteRule.pageElement, doc);
  1286. }
  1287. let i,maxHeight=curHeight*0.55,curMaxEle=null,curMaxArea=0,maxWidth=0;
  1288. let isHori=true;
  1289. let offsetTop=ele.children[0].offsetTop;
  1290. for(i=1;i<ele.children.length;i++){
  1291. if(ele.children[i].offsetTop!=offsetTop){
  1292. isHori=false;
  1293. break;
  1294. }
  1295. }
  1296. let hasSameClass = false;
  1297. let articleNum = 0;
  1298. for (i = 0; i < ele.children.length; i++) {
  1299. let curNode = ele.children[i];
  1300. if (curNode.tagName == "CANVAS") continue;
  1301. if (curNode.tagName == "NAV") continue;
  1302. if (!curNode.offsetParent) continue;
  1303. if (curNode.tagName != "IMG" && curNode.querySelector('img') == null && /^\s*$/.test(curNode.innerText)) continue;
  1304. if (needCheckNext && !curNode.contains(self.initNext) && getElementTop(curNode) > windowHeight) {
  1305. continue;
  1306. }
  1307. if (curNode.tagName == "ARTICLE") articleNum++;
  1308. let comStyle = curWin.getComputedStyle(curNode);
  1309. let h = parseInt(curNode.offsetHeight || curNode.scrollHeight);
  1310. let w = parseInt(curNode.scrollWidth);
  1311. if (isNaN(h) || isNaN(w)) continue;
  1312. if (isHori && h <= 50) continue;
  1313. let a = h * w + h, moreChild = curNode.children[0];
  1314. while (moreChild) {
  1315. comStyle = curWin.getComputedStyle(moreChild);
  1316. let ch = parseInt(moreChild.offsetHeight || moreChild.scrollHeight);
  1317. let cw = parseInt(moreChild.scrollWidth);
  1318. if (h < ch) h = ch;
  1319. if (moreChild.innerText != "" && !isNaN(ch) && !isNaN(cw)) {
  1320. a += ch * cw;
  1321. }
  1322. moreChild = moreChild.nextElementSibling;
  1323. }
  1324. let isMax = false;
  1325. if (isHori) {
  1326. if (maxWidth < w) {
  1327. isMax = true;
  1328. } else if (maxWidth < w + 300 && curMaxArea < a) {
  1329. isMax = true;
  1330. }
  1331. } else {
  1332. isMax = curMaxArea < a;
  1333. }
  1334. if (curMaxEle == null || isMax) {
  1335. if (h > 0 || !isHori) curHeight = h;
  1336. curMaxArea = a;
  1337. maxWidth = w;
  1338. curMaxEle = curNode;
  1339. }
  1340. }
  1341. if (curMaxEle) {
  1342. for(i = 0; i < ele.children.length; i++) {
  1343. let curNode = ele.children[i];
  1344. if (curMaxEle != curNode && curNode.className && curNode.style.display !== 'none' && curMaxEle.className == curNode.className && curMaxEle.tagName == curNode.tagName){
  1345. hasSameClass = true;
  1346. break;
  1347. }
  1348. }
  1349. }
  1350. if (curMaxEle && !hasSameClass && (isHori || curHeight > maxHeight || (needCheckNext && curHeight > windowHeight && ele.contains(self.initNext)))) {
  1351. return checkElement(curMaxEle);
  1352. }
  1353. if (ele.parentNode.children.length == 1 && curWin.getComputedStyle(ele.parentNode).float == 'none')ele=ele.parentNode;
  1354. else if(ele.tagName=="P" || ele.tagName=="BR")ele=ele.parentNode;
  1355. else if(ele.tagName=="TD")ele=ele.parentNode;
  1356. else if(ele.tagName=="TBODY"){
  1357. self.curSiteRule.pageElement=geneSelector(ele)+">*";
  1358. if(ele.children.length>0 && ele.children[0].querySelector("th")){
  1359. self.curSiteRule.pageElement+=":not(:first-child)";
  1360. }
  1361. debug(self.curSiteRule.pageElement, 'Page element');
  1362. return ele.children;
  1363. }
  1364. let imgs = ele.querySelectorAll('img');
  1365. if (imgs.length == 1) {
  1366. let img = imgs[0];
  1367. if (img.offsetWidth > ele.offsetWidth / 3 * 2 && img.offsetHeight > ele.offsetHeight / 2) {
  1368. ele = img;
  1369. }
  1370. }
  1371. self.curSiteRule.pageElement = geneSelector(ele);
  1372. let pf = false;
  1373. if (ele.parentNode) {
  1374. let paDisplay = curWin.getComputedStyle(ele.parentNode).display;
  1375. pf = paDisplay.indexOf('flex') !== -1 || paDisplay.indexOf('grid') !== -1;
  1376. }
  1377. if (ele.children.length > 1) {
  1378. if (curWin.getComputedStyle(ele).gridArea) {
  1379. self.curSiteRule.pageElement += ">*";
  1380. ele = ele.children;
  1381. } else if (articleNum > 1) {
  1382. self.curSiteRule.pageElement += ">article";
  1383. ele = ele.children;
  1384. } else {
  1385. let hasText = false;
  1386. for (let i in ele.childNodes) {
  1387. let child = ele.childNodes[i];
  1388. if (child.nodeType == 3 && child.nodeValue.trim() !== '') {
  1389. hasText = true;
  1390. ele = [ele];
  1391. break;
  1392. }
  1393. }
  1394. if (!hasText) {
  1395. let middleChild = ele.children[parseInt(ele.children.length / 2)];
  1396. if (curWin.getComputedStyle(ele).display === 'flex' || (rulesData.opacity != 0 && !pf)) {
  1397. ele = [ele];
  1398. } else if ((middleChild.style && middleChild.style.position === "absolute" && middleChild.style.left && middleChild.style.top) || ele.tagName === "UL" || curHeight == 0) {
  1399. ele = [ele];
  1400. } else {
  1401. self.curSiteRule.pageElement += ">*";
  1402. ele = ele.children;
  1403. }
  1404. }
  1405. }
  1406. } else if (pf) {
  1407. self.curSiteRule.pageElement += ">*";
  1408. ele = ele.children;
  1409. } else {
  1410. ele = [ele];
  1411. }
  1412. debug(self.curSiteRule.pageElement, 'Page element');
  1413. return ele;
  1414. }
  1415. pageElement=checkElement(body);
  1416. if (pageElement && pageElement.length > 0 && self.initNext) {
  1417. let lastBottom = getElementBottom(pageElement[pageElement.length - 1]);
  1418. if (lastBottom && getElementTop(self.initNext) - lastBottom > 1000) {
  1419. debug("Stop as too long between next & page element");
  1420. isPause = true;
  1421. pageElement = [];
  1422. } else {
  1423. if (pageElement.length == 1 && pageElement[0].tagName == "IMG") {
  1424. self.curSiteRule.pageBar = 0;
  1425. }
  1426. }
  1427. }
  1428. //if(pageElement)this.saveCurSiteRule();
  1429. }
  1430. if (doc == document && !this.docPageElement){
  1431. this.docPageElement = pageElement;
  1432. if (this.nextLinkHref) {
  1433. this.openInNewTab(pageElement);
  1434. }
  1435. }
  1436. if(pageElement && pageElement.length>0){
  1437. let pageElementCss=self.curSiteRule.pageElementCss || self.curSiteRule.pageElementStyle || rulesData.pageElementCss;
  1438. if(pageElementCss){
  1439. [].forEach.call(pageElement, ele=>{
  1440. if(!ele.dataset.pagetualPageElement){
  1441. ele.style.cssText=(ele.style.cssText||'')+pageElementCss;
  1442. ele.dataset.pagetualPageElement=1;
  1443. }
  1444. });
  1445. }
  1446. }
  1447. if (doc !== document) this.lazyImgAction(pageElement);
  1448. return pageElement;
  1449. }
  1450.  
  1451. getPage(doc){
  1452. if(typeof _unsafeWindow.Discourse!='undefined')return {};
  1453. let video=document.querySelector("video,iframe[id*=play],[id*=play]>iframe,iframe[src*=player],iframe[src*=m3u8]");
  1454. if(video && video.name != "pagetual-iframe"){
  1455. let scrollWidth = video.scrollWidth || video.offsetWidth;
  1456. let scrollHeight = video.scrollHeight || video.offsetHeight;
  1457. if(scrollWidth>500 && scrollHeight>500){
  1458. debug("Won't run when video found");
  1459. return {};
  1460. }
  1461. }
  1462. let canSave=false;//發現頁碼選擇器在其他頁對不上,還是別保存了
  1463. let url = this.curUrl.replace("index.php?","?");
  1464. let _url=url.replace(/\.s?html?$/i,"");
  1465. let pageNum=1,preStr="",afterStr="";
  1466. let pageMatch1=url.match(/(.*[a-z\/\-_](?:p|page)?\/?)(\d+)(\.s?html?$|\/?$)/i);
  1467. let pageMatch2=url.match(/(.*[\?&]p(?:age)?=)(\d+)($|[#&].*)/i);
  1468. if(pageMatch1){
  1469. preStr=pageMatch1[1];
  1470. pageNum=parseInt(pageMatch1[2]);
  1471. afterStr=pageMatch1[3];
  1472. if (/^\/?$/.test(afterStr) && !/(p(age)?|_|\-|\/)$/.test(preStr)) {
  1473. preStr = "";
  1474. afterStr = "";
  1475. }
  1476. }else if(pageMatch2){
  1477. preStr=pageMatch2[1];
  1478. pageNum=parseInt(pageMatch2[2]);
  1479. afterStr=pageMatch2[3];
  1480. }
  1481. let curPage=doc,i,cur,jsNext,body=doc.body||doc;
  1482. let next1,next2,next3,next4,nextJs1,nextJs2,nextJs3;
  1483. let next=body.querySelector(".page-next>a")||
  1484. body.querySelector("a.next_page")||
  1485. body.querySelector("#next_page")||
  1486. body.querySelector(".nextPage")||
  1487. body.querySelector("a[data-pagination=next]")||
  1488. body.querySelector("ul.pagination>li.active+li>a")||
  1489. body.querySelector(".pagination a.current+a")||
  1490. body.querySelector(".pagination a[rel=next]")||
  1491. body.querySelector(".pagination-nav__item--next>a")||
  1492. body.querySelector("a.pageright")||
  1493. body.querySelector(".page-numbers.current+a")||
  1494. body.querySelector("[title='Next page']")||
  1495. body.querySelector("[title='下一页']")||
  1496. body.querySelector("[title='下一頁']")||
  1497. body.querySelector("input[value='next']")||
  1498. body.querySelector("input[value='Next page']")||
  1499. body.querySelector("input[value='下一页']")||
  1500. body.querySelector("input[value='下一頁']")||
  1501. body.querySelector("a#pb_next")||
  1502. body.querySelector("a#rightFix")||
  1503. body.querySelector("a#btnPreGn")||
  1504. body.querySelector("a.page-next")||
  1505. body.querySelector("a.pages-next")||
  1506. body.querySelector("a.page.right")||
  1507. body.querySelector("a#next")||
  1508. body.querySelector(".next>a")||
  1509. body.querySelector(".next>button")||
  1510. body.querySelector("a[alt=next]")||
  1511. body.querySelector("button.next:not([disabled])")||
  1512. body.querySelector(".btn-next:not([disabled])")||
  1513. body.querySelector("[title=next]")||
  1514. body.querySelector("a#linkNext")||
  1515. body.querySelector("a[class*=page__next]");
  1516. if(!next){
  1517. let nexts=body.querySelectorAll("a.next");
  1518. for(i=0;i<nexts.length;i++){
  1519. if(nexts[i].style.display!=="none" &&
  1520. nexts[i].parentNode.style.display!=="none" &&
  1521. !/^\s*([上前首尾]|previous)/i.test(nexts[i].innerText.trim())){
  1522. next=nexts[i];
  1523. break;
  1524. }
  1525. }
  1526. }
  1527. if(next && (!next.href || /^(javascript|#)/.test(next.href.replace(location.href,"")))){
  1528. jsNext=next;
  1529. next=null;
  1530. }
  1531. if(!next){
  1532. next=body.querySelectorAll("[aria-label='Next page']");
  1533. if(next && next.length==1){
  1534. next=next[0];
  1535. if(!next.href || /^(javascript|#)/.test(next.href.replace(location.href,""))){
  1536. if(!jsNext)jsNext=next;
  1537. next=null;
  1538. }
  1539. }else{
  1540. next=null;
  1541. }
  1542. }
  1543. if(!next){
  1544. next=body.querySelectorAll("[aria-label='Next']");
  1545. if(next && next.length==1){
  1546. next=next[0];
  1547. if(!next.href || /^(javascript|#)/.test(next.href.replace(location.href,""))){
  1548. if(!jsNext)jsNext=next;
  1549. next=null;
  1550. }
  1551. }else{
  1552. next=null;
  1553. }
  1554. }
  1555. if(next && nextTextReg2.test(next.innerText.trim())){
  1556. next2=next;
  1557. next=null;
  1558. }
  1559. if(!next){
  1560. next=body.querySelector("a.curr+a");
  1561. }
  1562. if(!next){
  1563. next=body.querySelector("div.wp-pagenavi>span.current+a,div.page-nav>span.current+a,div.article-paging>span+a");
  1564. }
  1565. if(!next){
  1566. let pageDiv=body.querySelector("div.pages>ul");
  1567. if(pageDiv){
  1568. cur=pageDiv.querySelector("li>b");
  1569. if(cur)next=cur.parentNode.nextElementSibling;
  1570. if(next)next=next.querySelector("a");
  1571. }
  1572. }
  1573. if(!next){
  1574. next=body.querySelector(".number>ul>li.active+li>a");
  1575. }
  1576. if(!next){
  1577. next=body.querySelector(".pages>a[href='javascript:;']+a");
  1578. if(next && (next.href=="javascript:;" || next.getAttribute("href")=="#"))next=null;
  1579. }
  1580. if(!next){
  1581. let pageDiv=body.querySelector(".pagination");
  1582. if(pageDiv){
  1583. cur=pageDiv.querySelector("[class*=current]");
  1584. if(cur)next=cur.parentNode.nextElementSibling;
  1585. if(next)next=next.querySelector("a");
  1586. }
  1587. }
  1588. if(!next){
  1589. let aTags=body.querySelectorAll("a,button,[type='button']");
  1590. for(i=aTags.length-1;i>=0;i--){
  1591. if(next1 && next2 && next3 && next4)break;
  1592. let aTag=aTags[i];
  1593. if(aTag.innerText){
  1594. if(aTag.innerText=="§")continue;
  1595. if(aTag.innerText.trim().length>80)continue;
  1596. }
  1597. if(aTag.style.display=="none")continue;
  1598. if(aTag.href && /next$/i.test(aTag.href))continue;
  1599. if(aTag.className){
  1600. if(/slick|slide|gallery/i.test(aTag.className))continue;
  1601. if(aTag.classList && aTag.classList.contains('disabled'))continue;
  1602. }
  1603. if(aTag.parentNode){
  1604. if(aTag.parentNode.className && /slick|slide|gallery/i.test(aTag.parentNode.className))continue;
  1605. if(aTag.parentNode.classList && aTag.parentNode.classList.contains('disabled'))continue;
  1606. if(aTag.parentNode.tagName == "BLOCKQUOTE")continue;
  1607. }
  1608. let innerText = (aTag.innerText||aTag.value||aTag.title||'').trim().replace(/(\n.*| )/g, '');
  1609. let isJs = !aTag.href || /^(javascript|#)/.test(aTag.href.replace(location.href,""));
  1610. if(innerText && innerText.length<=25){
  1611. if(!next1){
  1612. if(nextTextReg1.test(innerText)){
  1613. if(isJs){
  1614. if(!nextJs1)nextJs1=aTag;
  1615. }else{
  1616. next1=aTag;
  1617. }
  1618. }
  1619. }
  1620. if(!next2){
  1621. if(nextTextReg2.test(innerText) || /nextpage/i.test(aTag.className) || innerText=="»" || innerText==">>"){
  1622. if(isJs){
  1623. if(!nextJs2)nextJs2=aTag;
  1624. }else{
  1625. next2=aTag;
  1626. }
  1627. }
  1628. }
  1629. if(!next3){
  1630. if(innerText=="Next" || innerText=="next" || innerText=="&gt;" || innerText=="▶" || innerText==">" || innerText=="›" || innerText=="→"){
  1631. if(isJs){
  1632. if(!nextJs3)nextJs3=aTag;
  1633. }else{
  1634. next3=aTag;
  1635. }
  1636. }
  1637. }
  1638. }
  1639. if (isJs) continue;
  1640. if (!next4) {
  1641. let prevEle = aTag.previousElementSibling;
  1642. if (prevEle && (prevEle.tagName == 'B' || prevEle.tagName == 'SPAN' || prevEle.tagName == 'STRONG')) {
  1643. if (/^\d+$/.test(aTag.innerText.trim()) && /^\d+$/.test(prevEle.innerText.trim()) && parseInt(aTag.innerText) == parseInt(prevEle.innerText) + 1) {
  1644. next4 = aTag;
  1645. }
  1646. }
  1647. }
  1648. if (!next4 && aTag.href.length < 250) {
  1649. let _aHref = aTag.href.replace("?&", "?").replace("index.php?", "?");
  1650. let _aHrefTrim = _aHref;
  1651. if (preStr) _aHrefTrim = _aHrefTrim.replace(preStr, "");
  1652. if (afterStr) _aHrefTrim = _aHrefTrim.replace(afterStr, "");
  1653. if ((preStr || afterStr) && pageNum < 999 && _aHrefTrim == pageNum + 1) {
  1654. next4 = aTag;
  1655. } else if (this.curUrl != aTag.href) {
  1656. _aHref = _aHref.replace(/\.s?html?$/i, "");
  1657. let pageTwoReg = /^[\/\?&]?[_-]?(p|page)?=?\/?2(\/|\?|&|$)/i;
  1658. if (_aHref.indexOf(_url) != -1 && pageTwoReg.test(_aHref.replace(_url, ""))) {
  1659. let curHref = aTag.getAttribute("href");
  1660. let pageOne = curHref.replace(/\/2(\/|\?|&|$)/,"/1$1");
  1661. if (pageOne == curHref) pageOne = null;
  1662. else pageOne = body.querySelector(`a[href='${pageOne}']`);
  1663. if (!pageOne || pageOne.className != curHref.className) next4 = aTag;
  1664. }
  1665. }
  1666. }
  1667. }
  1668. if(next3){
  1669. let eles=getAllElements(`//a[text()='${next3.innerText}']`, curPage);
  1670. if(eles.length>2)next3=null;
  1671. }
  1672. if(nextJs3){
  1673. let eles=getAllElements(`//a[text()='${nextJs3.innerText}']`, curPage);
  1674. if(eles.length>2)nextJs3=null;
  1675. }
  1676. }
  1677. if (!next) next = next1 || next4 || next3 || next2;
  1678. if (!next && (this.initGetPage || doc != document)) {
  1679. this.initGetPage = false;
  1680. next = jsNext || nextJs1 || nextJs3 || nextJs2;
  1681. if (next && next.parentNode.className.indexOf('tab') != -1) next = null;
  1682. }
  1683. if (next && next.classList && next.classList.contains("results-more")) next=null;
  1684. if (next && next.hasAttribute && next.hasAttribute("disabled")) next=null;
  1685. return {next:next, canSave:canSave};
  1686. }
  1687.  
  1688. canonicalUri(src) {
  1689. if (!src) {
  1690. return "";
  1691. }
  1692. if (src.charAt(0) == "#") return this.curUrl + src;
  1693. if (src.charAt(0) == "?") return this.curUrl.replace(/^([^\?#]+).*/, "$1" + src);
  1694. let origin = location.protocol + '//' + location.host;
  1695. let url = this.basePath || origin;
  1696. url = url.replace(/(\?|#).*/, "");
  1697. if (/https?:\/\/[^\/]+$/.test(url)) url = url + '/';
  1698. if (url.indexOf("http") !== 0) url = origin + url;
  1699. var root_page = /^[^\?#]*\//.exec(url)[0],
  1700. root_domain = /^\w+\:\/\/\/?[^\/]+/.exec(root_page)[0],
  1701. absolute_regex = /^\w+\:\/\//;
  1702. this.updateUrl = false;
  1703. while (src.indexOf("../") === 0) {
  1704. src = src.substr(3);
  1705. root_page = root_page.replace(/\/[^\/]+\/$/, "/");
  1706. this.updateUrl = true;
  1707. }
  1708. src = src.replace(/\.\//, "");
  1709. if (/^\/\/\/?/.test(src)) {
  1710. src = location.protocol + src;
  1711. }
  1712. return (absolute_regex.test(src) ? src : ((src.charAt(0) == "/" ? root_domain : root_page) + src));
  1713. }
  1714.  
  1715. getLinkByPage(url, pageNum) {
  1716. if(!url)return;
  1717. if(this.curSiteRule.pageNum){
  1718. let result=this.curSiteRule.pageNum;
  1719. let strMatch=result.match(/\{.*?}/);
  1720. if(!strMatch)return null;
  1721. let urlReg=new RegExp("("+result.replace(strMatch[0], ")\\d+(")+")","i");
  1722. let code=strMatch[0].replace(/^{/,"").replace(/}$/,"").replace(/\$p/g,pageNum);
  1723. if(code==pageNum){
  1724. result=url.replace(urlReg,"$1"+code+"$2");
  1725. }else{
  1726. try{
  1727. code=Function('"use strict";return ' + code)();
  1728. result=url.replace(urlReg,"$1"+code+"$2");
  1729. }catch(e){
  1730. debug(e);
  1731. }
  1732. }
  1733. if(result!=url){
  1734. return result;
  1735. }
  1736. }
  1737. return url.replace(/([&\/\?](p=|page[=\/_-]?))\d+/i, "$1"+pageNum).replace(/([_-])\d+\./i, "$1"+pageNum+".");
  1738. }
  1739.  
  1740. getPageNumFromUrl(url) {
  1741. if(!url)return curPage;
  1742. if(this.curSiteRule.pageNum){
  1743. let result=this.curSiteRule.pageNum;
  1744. let strMatch=result.match(/\{.*?}/);
  1745. if(!strMatch)return null;
  1746. let urlReg=new RegExp(".*"+result.replace(strMatch[0], "(\\d+)")+".*","i");
  1747. let curShowNum=url.replace(urlReg,"$1");
  1748. if (curShowNum!=url){
  1749. let code=strMatch[0].replace(/^{/,"").replace(/}$/,"");
  1750. if(code=="$p"){
  1751. return curShowNum;
  1752. }else{
  1753. try{
  1754. let page1=Function('"use strict";return ' + code.replace("$p", "0"))();
  1755. let page2=Function('"use strict";return ' + code.replace("$p", "1"))();
  1756. let numGap=page2-page1;
  1757. return (curShowNum - page1) / numGap;
  1758. }catch(e){
  1759. debug(e);
  1760. }
  1761. }
  1762. } else {
  1763. return curPage;
  1764. }
  1765. }
  1766. let pageNum=url.replace(/.*[&\/\?](p=|page[=\/_-]?)(\d+).*/i, "$2");
  1767. return pageNum==url?curPage:pageNum;
  1768. }
  1769.  
  1770. async getNextLink(doc) {
  1771. let nextLink = null, page, href;
  1772. let getNextLinkByForm = (form, n) => {
  1773. let params = [];
  1774. let formData = new FormData(form);
  1775. for (let [key, value] of formData) {
  1776. if (n && /^(p|page)$/i.test(key)) {
  1777. params.push(key + '=' + n);
  1778. } else {
  1779. params.push(key + '=' + encodeURIComponent(value));
  1780. }
  1781. }
  1782. params = params.join('&');
  1783. return form.action + (form.action.indexOf('?') == -1 ? '?' : '&') + params + (form.method == 'post' ? '#p{' + params + '}' : '');
  1784. };
  1785. if (this.curSiteRule.pageElementByJs) {
  1786. this.nextLinkHref = "#";
  1787. return true;
  1788. } else if (this.curSiteRule.nextLinkByJs) {
  1789. try {
  1790. let over = _url => {
  1791. };
  1792. let targetUrl = await ((typeof _unsafeWindow.pagetualNextLinkByJs == 'undefined') ? new AsyncFunction("doc", '"use strict";' + this.curSiteRule.nextLinkByJs) : _unsafeWindow.pagetualNextLinkByJs)(doc);
  1793. if (targetUrl) nextLink = {href: targetUrl};
  1794. } catch(e) {
  1795. debug(e);
  1796. }
  1797. } else if (this.curSiteRule.nextLinkByUrl) {
  1798. let targetUrl = this.curUrl.replace(new RegExp(this.curSiteRule.nextLinkByUrl[0], "i"), this.curSiteRule.nextLinkByUrl[1]);
  1799. if (targetUrl != this.curUrl) {
  1800. let includeSel = this.curSiteRule.nextLinkByUrl[2];
  1801. let excludeSel = this.curSiteRule.nextLinkByUrl[3];
  1802. if (includeSel) {
  1803. includeSel = includeSel.trim();
  1804. if (!getElement(includeSel, doc)) {
  1805. this.nextLinkHref=false;
  1806. return null;
  1807. }
  1808. }
  1809. if (excludeSel) {
  1810. excludeSel = excludeSel.trim();
  1811. if (getElement(excludeSel, doc)) {
  1812. this.nextLinkHref=false;
  1813. return null;
  1814. }
  1815. }
  1816. let reps = targetUrl.match(/{.*?}/g);
  1817. if (reps) {
  1818. reps.forEach(rep => {
  1819. let code = rep.replace("{","").replace("}", "").replace(/\(\)/g, "0");
  1820. let result = code.match(/^(\d*)\+1$/);
  1821. if (result) {
  1822. result = parseInt(result[1] || 1) + 1;
  1823. } else {
  1824. try {
  1825. result = Function('"use strict";return ' + code)();
  1826. } catch(e) {
  1827. debug(e);
  1828. }
  1829. }
  1830. targetUrl = targetUrl.replace(rep, result);
  1831. });
  1832. }
  1833. }
  1834. nextLink = {href: targetUrl};
  1835. } else if (this.curSiteRule.nextLink) {
  1836. let nextLinkSel = this.curSiteRule.nextLink;
  1837. if (nextLinkSel != "0" && nextLinkSel != 0) {
  1838. if (Array && Array.isArray && Array.isArray(nextLinkSel)) {
  1839. nextLink = getElement(nextLinkSel[nextIndex], doc);
  1840. } else nextLink = getElement(nextLinkSel, doc);
  1841. }
  1842. if (nextLink && (this.curSiteRule.action == 0 || this.curSiteRule.action == 1 || this.curSiteRule.action == 2)) {
  1843. let form = doc.querySelector('#search-form');
  1844. if (!nextLink.href && nextLink.hasAttribute("onclick") && form) {
  1845. if (/^\d+$/.test(nextLink.innerText)) {
  1846. nextLink.href = getNextLinkByForm(form, nextLink.innerText);
  1847. }
  1848. } else if (nextLink.tagName == "INPUT" || nextLink.type == "submit") {
  1849. form = nextLink.parentNode;
  1850. while (form) {
  1851. if (form.tagName == "FORM") break;
  1852. else form = form.parentNode;
  1853. }
  1854. if (form) {
  1855. nextLink.href = getNextLinkByForm(form);
  1856. }
  1857. }
  1858. if (nextLink.href && this.curSiteRule.action != 0) {
  1859. nextLink.href = nextLink.href.replace(/#p{.*/, "");
  1860. }
  1861. }
  1862. }else{
  1863. page=this.getPage(doc);
  1864. nextLink=page.next;
  1865. if(nextLink){
  1866. if(nextLink.tagName=="INPUT" || nextLink.type=="submit"){
  1867. let form = nextLink.parentNode;
  1868. while (form) {
  1869. if (form.tagName == "FORM") break;
  1870. else form = form.parentNode;
  1871. }
  1872. if (form) {
  1873. nextLink.href = getNextLinkByForm(form);
  1874. }
  1875. }
  1876. let parent = nextLink;
  1877. while (parent && parent.tagName !== "BODY") {
  1878. if (parent.hasAttribute("disabled")) {
  1879. this.nextLinkHref = false;
  1880. return null;
  1881. }
  1882. if (parent.className && parent.classList) {
  1883. if (parent.classList.contains("noClick") || parent.classList.contains("no-pages")) {
  1884. this.nextLinkHref = false;
  1885. return null;
  1886. }
  1887. }
  1888. if (parent.style.display === "none") {
  1889. this.nextLinkHref = false;
  1890. return null;
  1891. }
  1892. parent = parent.parentNode;
  1893. }
  1894. if(doc==document){
  1895. if((!nextLink.href || /^(javascript|#)/.test(nextLink.href.replace(location.href,""))) && !isVisible(nextLink, _unsafeWindow)){
  1896. this.nextLinkHref=false;
  1897. return null;
  1898. }else{
  1899. let nextLinkCs=_unsafeWindow.getComputedStyle(nextLink);
  1900. if(nextLinkCs.cursor=="not-allowed"){
  1901. this.nextLinkHref=false;
  1902. return null;
  1903. }
  1904. this.initNext=nextLink;
  1905. }
  1906. }
  1907. let form=doc.querySelector('#search-form');
  1908. if(!nextLink.href && nextLink.hasAttribute("onclick") && form){
  1909. if(form && /^\d+$/.test(nextLink.innerText)){
  1910. href=getNextLinkByForm(form, nextLink.innerText);
  1911. }
  1912. }
  1913. }
  1914. }
  1915. if (nextLink) {
  1916. if (this.curSiteRule.stopSign) {
  1917. if (Array && Array.isArray && Array.isArray(this.curSiteRule.stopSign)) {
  1918. let includeSel = this.curSiteRule.stopSign[0];
  1919. let excludeSel = this.curSiteRule.stopSign[1];
  1920. let curSign = this.curSiteRule.stopSign[2];
  1921. let maxSign = this.curSiteRule.stopSign[3];
  1922. if (Array && Array.isArray && Array.isArray(includeSel) && !curSign) {
  1923. curSign = includeSel;
  1924. includeSel = false;
  1925. }
  1926. if (Array && Array.isArray && Array.isArray(excludeSel) && !maxSign) {
  1927. maxSign = excludeSel;
  1928. excludeSel = false;
  1929. }
  1930. if (includeSel) {
  1931. includeSel = includeSel.trim();
  1932. if (!getElement(includeSel, doc)) {
  1933. this.nextLinkHref=false;
  1934. return null;
  1935. }
  1936. }
  1937. if (excludeSel) {
  1938. excludeSel = excludeSel.trim();
  1939. if (getElement(excludeSel, doc)) {
  1940. this.nextLinkHref=false;
  1941. return null;
  1942. }
  1943. }
  1944. if (curSign && maxSign) {
  1945. let currentEle = getElement(curSign[0], doc);
  1946. let maxEle = getElement(maxSign[0], doc);
  1947. if (currentEle && maxEle) {
  1948. let currentSignNum, maxSignNum;
  1949. if (/\(.*\)/.test(curSign[1])) {
  1950. currentSignNum = currentEle.innerText.match(new RegExp(curSign[1]));
  1951. if (currentSignNum) currentSignNum = currentSignNum[1];
  1952. } else if (currentEle.getAttribute) {
  1953. currentSignNum = currentEle.getAttribute(curSign[1]);
  1954. }
  1955. if (/\(.*\)/.test(maxSign[1])) {
  1956. maxSignNum = maxEle.innerText.match(new RegExp(maxSign[1]));
  1957. if (maxSignNum) maxSignNum = maxSignNum[1];
  1958. } else if (maxEle.getAttribute) {
  1959. maxSignNum = maxEle.getAttribute(maxSign[1]);
  1960. }
  1961. if (currentSignNum && maxSignNum && currentSignNum == maxSignNum) {
  1962. this.nextLinkHref = false;
  1963. return null;
  1964. }
  1965. }
  1966. }
  1967. } else {
  1968. try {
  1969. let stopSign = ((typeof _unsafeWindow.stopSign == 'undefined') ? Function("doc", "nextLink", '"use strict";' + this.curSiteRule.stopSign) : _unsafeWindow.stopSign)(doc, nextLink);
  1970. if (stopSign) {
  1971. this.nextLinkHref = false;
  1972. return null;
  1973. }
  1974. } catch(e) {
  1975. debug(e);
  1976. }
  1977. }
  1978. }
  1979. if (this.curSiteRule.action == 3) {
  1980. if (doc == document) debug(nextLink, 'Next link');
  1981. this.nextLinkHref = '#';
  1982. } else {
  1983. let needUrl = (this.curSiteRule.action == 0 || this.curSiteRule.action == 1 || this.curSiteRule.action == 2);
  1984. if (!href) href = nextLink.href;
  1985. if (href && nextLink.getAttribute) {
  1986. let _href = nextLink.getAttribute("href");
  1987. if (_href) {
  1988. if (_href.charAt(0) == "#" || _href == "?"){
  1989. href = "#";
  1990. } else {
  1991. href = _href;
  1992. }
  1993. }
  1994. }
  1995.  
  1996. if(needUrl && (href===""||href===null)){
  1997. this.nextLinkHref=false;
  1998. }else if(needUrl && /^(javascript:|#)/.test(href)){
  1999. this.nextLinkHref=false;
  2000. }else{
  2001. this.nextLinkHref=(href && !/^(javascript:|#)/.test(href))?this.canonicalUri(href):"#";
  2002. if(this.nextLinkHref!="#" && (this.nextLinkHref==this.curUrl || this.nextLinkHref==this.curUrl+"#" || this.nextLinkHref==this.oldUrl || this.nextLinkHref==this.oldUrl+"#")){
  2003. this.nextLinkHref=false;
  2004. }else if(doc==document)debug(nextLink, 'Next link');
  2005. }
  2006. }
  2007. }else{
  2008. this.nextLinkHref=false;
  2009. }
  2010. this.preload();
  2011. return nextLink;
  2012. }
  2013.  
  2014. preload(){
  2015. if(!rulesData.preload)return;
  2016. if(!this.nextLinkHref || this.nextLinkHref=="#")return;
  2017. let self=this;
  2018. _GM_xmlhttpRequest({
  2019. url: this.nextLinkHref,
  2020. method: 'GET',
  2021. overrideMimeType: 'text/html;charset=' + (document.characterSet || document.charset || document.inputEncoding),
  2022. headers: {
  2023. 'Referer': location.href
  2024. },
  2025. timeout: 10000,
  2026. onload: function(res) {
  2027. var doc=null;
  2028. try {
  2029. doc=document.implementation.createHTMLDocument('');
  2030. doc.documentElement.innerHTML=res.response;
  2031. var body = doc.body;
  2032. if (body && body.firstChild) {
  2033. self.lazyImgAction(body.children);
  2034. }
  2035. if(!self.preloadDiv){
  2036. self.preloadDiv = document.createElement('div');
  2037. self.preloadDiv.id = "pagetual-preload";
  2038. self.preloadDiv.style.cssText = 'display:none!important;';
  2039. document.body.appendChild(self.preloadDiv);
  2040. self.checkedImgs={};
  2041. }
  2042. [].forEach.call(doc.images, i=>{
  2043. let iSrc=i.src;
  2044. if(iSrc && !self.checkedImgs[iSrc]){
  2045. self.checkedImgs[iSrc] = true;
  2046. let img = document.createElement('img');
  2047. img.src = iSrc;
  2048. self.preloadDiv.appendChild(img);
  2049. }
  2050. });
  2051. }
  2052. catch (e) {
  2053. return;
  2054. }
  2055. }
  2056. });
  2057. }
  2058.  
  2059. getInsert(refresh) {
  2060. if(refresh){
  2061. this.insert=null;
  2062. }
  2063. if(this.insert && document.documentElement.contains(this.insert)){
  2064. return this.insert;
  2065. }
  2066. if (this.curSiteRule.insert) {
  2067. let insertSel = this.curSiteRule.insert;
  2068. if (Array && Array.isArray && Array.isArray(insertSel)) {
  2069. insertSel = insertSel[nextIndex < insertSel.length ? nextIndex : 0];
  2070. }
  2071. this.insert=getElement(insertSel, document);
  2072. } else {
  2073. let pageElement = this.getPageElement(document, _unsafeWindow);
  2074. if (this.curSiteRule.singleUrl && this.nextLinkHref == "#" && this.curSiteRule.pageElement === 'body') {
  2075. debug("Stop as jsNext & whole body");
  2076. isPause = true;
  2077. return null;
  2078. }
  2079. if (pageElement && pageElement.length > 0) {
  2080. var pELast = pageElement[pageElement.length - 1];
  2081. this.insert = pELast.nextSibling ? pELast.nextSibling : pELast.parentNode.appendChild(document.createTextNode(' '));
  2082. }
  2083. }
  2084. return this.insert;
  2085. }
  2086.  
  2087. pageInit(doc,eles){
  2088. let code=this.curSiteRule.pageInit;
  2089. if(code){
  2090. let initFunc=((typeof _unsafeWindow.pagetualPageInit=='undefined') ? Function("doc", "eles", '"use strict";' + code) : _unsafeWindow.pagetualPageInit);
  2091. let checkInit=(resolve)=>{
  2092. try{
  2093. if(initFunc(doc, eles)===false){
  2094. setTimeout(()=>{
  2095. checkInit(resolve);
  2096. },100);
  2097. } else {
  2098. resolve(true);
  2099. }
  2100. }catch(e){
  2101. resolve(false);
  2102. debug(e);
  2103. }
  2104. };
  2105. return new Promise((resolve) => {
  2106. checkInit(function(e) {
  2107. resolve(e)
  2108. });
  2109. })
  2110. }
  2111. }
  2112.  
  2113. pageAction(doc,eles){
  2114. let code=this.curSiteRule.pageAction;
  2115. if(code){
  2116. try{
  2117. ((typeof _unsafeWindow.pagetualPageAction=='undefined') ? Function("doc", "eles", '"use strict";' + code) : _unsafeWindow.pagetualPageAction)(doc, eles);
  2118. }catch(e){
  2119. debug(e);
  2120. }
  2121. }
  2122. this.openInNewTab(eles);
  2123. this.replaceElement(doc);
  2124. }
  2125.  
  2126. openInNewTab(eles){
  2127. if(rulesData.openInNewTab){
  2128. [].forEach.call(eles, ele=>{
  2129. if(ele.tagName=="A" && ele.href && !/^(mailto:|javascript:)|#/.test(ele.href)){
  2130. ele.setAttribute('target', '_blank');
  2131. }else{
  2132. [].forEach.call(ele.querySelectorAll('a[href]:not([href^="mailto:"]):not([href^="javascript:"]):not([href^="#"])'), a=>{
  2133. a.setAttribute('target', '_blank');
  2134. if (a.getAttribute('onclick') == 'atarget(this)') {
  2135. a.removeAttribute('onclick');
  2136. }
  2137. });
  2138. }
  2139. });
  2140. }
  2141. }
  2142.  
  2143. lazyImgAction(eles) {
  2144. if (!eles || eles.length == 0) return;
  2145. let lazyImgSrc = this.curSiteRule.lazyImgSrc;
  2146. if (lazyImgSrc === 0 || lazyImgSrc === '0') return;
  2147. let setLazyImg = img => {
  2148. let realSrc;
  2149. if (lazyImgSrc) {
  2150. if (!Array.isArray(lazyImgSrc)) {
  2151. lazyImgSrc = [lazyImgSrc];
  2152. }
  2153. realSrc = img.getAttribute(lazyImgSrc[0]);
  2154. if (lazyImgSrc.length == 2) {
  2155. let removeProps = lazyImgSrc[1].split(",");
  2156. removeProps.forEach(prop => {
  2157. img.removeAttribute(prop.trim());
  2158. });
  2159. }
  2160. }
  2161. if (!realSrc) {
  2162. if (img.getAttribute("_src") && !img.src) {
  2163. realSrc = img.getAttribute("_src");
  2164. } else if (img.dataset) {
  2165. if (img.dataset.original) {
  2166. realSrc = img.dataset.original;
  2167. } else if (img.dataset.lazySrc) {
  2168. realSrc = img.dataset.lazySrc;
  2169. } else if (img.dataset.lazy) {
  2170. realSrc = img.dataset.lazy;
  2171. } else if (img.dataset.src) {
  2172. realSrc = img.dataset.src;
  2173. } else if (img.dataset.origFile) {
  2174. realSrc = img.dataset.origFile;
  2175. }
  2176. }
  2177. if (!realSrc && img._lazyrias && img._lazyrias.srcset) {
  2178. realSrc = img._lazyrias.srcset[img._lazyrias.srcset.length - 1];
  2179. }
  2180. if (realSrc) {
  2181. img.removeAttribute("srcset");
  2182. } else if (img.srcset) {
  2183. var srcs = img.srcset.split(/[xw],/), largeSize = 0;
  2184. srcs.forEach(srci => {
  2185. let srcInfo = srci.trim().split(" "), curSize = parseInt(srcInfo[1]);
  2186. if (srcInfo[1] && curSize > largeSize) {
  2187. largeSize = curSize;
  2188. realSrc = srcInfo[0];
  2189. }
  2190. });
  2191. }
  2192. }
  2193. if (realSrc) {
  2194. img.src = realSrc;
  2195. if (img.style.display == "none") {
  2196. img.style.display = "";
  2197. }
  2198. if (img.style.visibility == "hidden") {
  2199. img.style.visibility = "";
  2200. }
  2201. if (img.style.opacity == 0) {
  2202. img.style.opacity = "";
  2203. }
  2204. }
  2205. };
  2206. [].forEach.call(eles, ele=>{
  2207. if(ele.tagName=="IMG"){
  2208. setLazyImg(ele);
  2209. }else{
  2210. [].forEach.call(ele.querySelectorAll("img"), img=>{
  2211. setLazyImg(img);
  2212. });
  2213. [].forEach.call(ele.querySelectorAll("div[data-src][data-thumb]"), div=>{
  2214. div.style.setProperty("background-image", "url("+div.dataset.src+")", "important");
  2215. });
  2216. }
  2217. if(ele.tagName=="A" && ele.classList.contains("lazyload")){
  2218. if(ele.dataset.original){
  2219. ele.style.backgroundImage='url("'+ele.dataset.original+'")';
  2220. }
  2221. }else{
  2222. [].forEach.call(ele.querySelectorAll("a.lazyload"), a=>{
  2223. if(a.dataset.original){
  2224. a.style.backgroundImage='url("'+a.dataset.original+'")';
  2225. }
  2226. });
  2227. }
  2228. });
  2229. }
  2230.  
  2231. initPage(callback){
  2232. let self=this;
  2233. curPage=1;
  2234. //if(this.curSiteRule.url && !this.curSiteRule.singleUrl)return;
  2235. this.curSiteRule={};
  2236. this.pageDoc=document;
  2237. this.nextLinkHref=null;
  2238. this.curUrl=location.href;
  2239. let base=document.querySelector("base");
  2240. this.basePath=base?base.href:location.href;
  2241. this.getRule(async () => {
  2242. if(self.curSiteRule.enable==0){
  2243. debug("Stop as rule disable");
  2244. isPause=true;
  2245. return;
  2246. }
  2247. //若是再亂匹配就不緩存wedata,或者只在找完本地規則之後再考慮wedata的緩存
  2248. if (self.curSiteRule.singleUrl) {
  2249. self.curSiteRule.pageElement = "";
  2250. self.smartRules = self.smartRules.filter(item => {return item && item.url != self.curSiteRule.url});
  2251. self.smartRules.unshift(self.curSiteRule);
  2252. if (self.smartRules.length > 100) {
  2253. self.smartRules.pop();
  2254. }
  2255. storage.setItem("smartRules", self.smartRules);
  2256. } else if (self.curSiteRule && self.curSiteRule.url.length > 13) {
  2257. self.hpRules = self.hpRules.filter(item => {return item && item.url != self.curSiteRule.url});
  2258. self.hpRules.unshift(self.curSiteRule);
  2259. if (self.hpRules.length > 30) {
  2260. self.hpRules.pop();
  2261. }
  2262. storage.setItem("hpRules", self.hpRules);
  2263. }
  2264. let css=self.curSiteRule.css || rulesData.customCss;
  2265. if(css && !/^inIframe:/.test(css)){
  2266. _GM_addStyle(css);
  2267. }
  2268. let autoClick=self.curSiteRule.autoClick;
  2269. if(autoClick){
  2270. let autoClickBtn;
  2271. autoClickBtn=getElement(autoClick, document);
  2272. if(autoClickBtn){
  2273. emuClick(autoClickBtn);
  2274. }
  2275. }
  2276. let code=self.curSiteRule.init;
  2277. if(code){
  2278. try{
  2279. ((typeof _unsafeWindow.pagetualInit=='undefined') ? Function('doc','win','iframe','"use strict";' + code) : _unsafeWindow.pagetualInit)(null,null,null);
  2280. }catch(e){
  2281. debug(e);
  2282. }
  2283. }
  2284. await self.getNextLink(document);
  2285. self.refreshByClick();
  2286. callback();
  2287. });
  2288. }
  2289.  
  2290. insertElement(ele) {
  2291. this.getInsert();
  2292. if(this.curSiteRule.insertPos==2){
  2293. this.insert.appendChild(ele);
  2294. }else{
  2295. this.insert.parentNode.insertBefore(ele, this.insert);
  2296. }
  2297. }
  2298.  
  2299. async insertPage(doc, eles, url, callback, tried) {
  2300. this.oldUrl=this.curUrl;
  2301. let oldTitle=this.pageDoc.title;
  2302. this.pageDoc=doc;
  2303. this.curUrl=url;
  2304. let nextLink=await this.getNextLink(doc);
  2305. this.nextTitle="";
  2306. if(this.curSiteRule.pageBarText){
  2307. if(this.curSiteRule.pageBarText==1 || this.curSiteRule.pageBarText==true){
  2308. this.nextTitle=doc.title;
  2309. }else{
  2310. try{
  2311. this.nextTitle=((typeof _unsafeWindow.pagetualPageBarText=='undefined') ? Function("doc",'"use strict";' + this.curSiteRule.pageBarText) : _unsafeWindow.pagetualPageBarText)(doc);
  2312. }catch(e){
  2313. debug(e);
  2314. }
  2315. }
  2316. }
  2317. if(curPage==1 && !tried && !nextLink && this.curSiteRule.singleUrl && this.curSiteRule.pageElement && this.curSiteRule.action!=0){
  2318. this.curSiteRule.action=1;
  2319. this.curUrl=location.href;
  2320. return false;
  2321. }
  2322. if(callback)callback(eles);
  2323. this.getInsert();
  2324. var self=this,newEles=[];
  2325. if(!eles || eles.length==0 || !self.insert || !self.insert.parentNode){
  2326. }else{
  2327. isLoading=true;
  2328. await this.pageInit(doc, eles);
  2329. let curScroll=document.body.scrollTop||document.documentElement.scrollTop;
  2330. [].forEach.call(eles, ele=>{
  2331. let newEle=ele.cloneNode(true);
  2332. let oldCanvass=ele.querySelectorAll("canvas");
  2333. let newCanvass=newEle.querySelectorAll("canvas");
  2334. if(self.updateUrl){
  2335. [].forEach.call(newEle.querySelectorAll("img"), img=>{
  2336. if (img.getAttribute("src")) img.src=self.canonicalUri(img.getAttribute("src"));
  2337. });
  2338. [].forEach.call(newEle.querySelectorAll("a"), a=>{
  2339. if (a.getAttribute("href")) a.href = self.canonicalUri(a.getAttribute("href"));
  2340. });
  2341. }
  2342. for(let i=0;i<oldCanvass.length;i++){
  2343. let oldCanvas=oldCanvass[i];
  2344. let newCanvas=newCanvass[i];
  2345. newCanvas.getContext('2d').drawImage(oldCanvas, 0, 0);
  2346. }
  2347. self.insertElement(newEle);
  2348. newEles.push(newEle);
  2349. });
  2350. document.body.scrollTop=curScroll;
  2351. document.documentElement.scrollTop=curScroll;
  2352. }
  2353. this.pageAction(doc, newEles);
  2354. let enableHistory = this.curSiteRule.history;
  2355. let enableHistoryAfterInsert = false;
  2356. if (enableHistory == 1) {
  2357. enableHistory = true;
  2358. } else if (enableHistory == 2) {
  2359. enableHistory = true;
  2360. enableHistoryAfterInsert = true;
  2361. } else if (enableHistory == 0) {
  2362. enableHistory = false;
  2363. } else {
  2364. enableHistory = rulesData.enableHistory;
  2365. enableHistoryAfterInsert = rulesData.enableHistoryAfterInsert;
  2366. }
  2367. if (enableHistory) {
  2368. let historyUrl = enableHistoryAfterInsert ? this.curUrl : this.oldUrl;
  2369. if(historyUrl != location.href) {
  2370. let isJs=/^(javascript|#)/.test(historyUrl.replace(location.href, ""));
  2371. if(!isJs){
  2372. let historyTitle = enableHistoryAfterInsert ? doc.title : oldTitle;
  2373. _unsafeWindow.history.replaceState(undefined, historyTitle, historyUrl);
  2374. document.title = historyTitle;
  2375. }
  2376. }
  2377. }
  2378. isLoading = false;
  2379. return true;
  2380. }
  2381. }
  2382. var ruleParser = new RuleParser();
  2383.  
  2384. class SideController {
  2385. static controller;
  2386. constructor() {
  2387. this.init();
  2388. }
  2389.  
  2390. static getInstance() {
  2391. if (!SideController.controller) {
  2392. SideController.controller = new SideController();
  2393. }
  2394. return SideController.controller;
  2395. }
  2396.  
  2397. static setup() {
  2398. if (ruleParser.curSiteRule.sideController === false) return;
  2399. if (!rulesData.sideController && !ruleParser.curSiteRule.sideController) return;
  2400. SideController.getInstance().addToStage();
  2401. }
  2402.  
  2403. init() {
  2404. let self = this;
  2405. let cssText = `
  2406. #pagetual-sideController {
  2407. position: fixed;
  2408. top: calc(50% - 75px);
  2409. left: calc(99% - 45px);
  2410. width: 40px;
  2411. border-radius: 20px;
  2412. box-shadow: rgb(0 0 0) 0px 0px 10px;
  2413. text-align: center;
  2414. font-weight: bold;
  2415. font-style: normal;
  2416. font-size: 20px!important;
  2417. background: #ffffffa0!important;
  2418. color: black!important;
  2419. user-select: none;
  2420. z-index: 2147483647!important;
  2421. padding: 0!important;
  2422. }
  2423. #pagetual-sideController.stop {
  2424. -webkit-filter: invert(100%);
  2425. filter: invert(100%);
  2426. }
  2427. .pagetual-sideController-btn {
  2428. padding: 5px 0;
  2429. cursor: pointer;
  2430. transition: transform .15s ease-in-out;
  2431. }
  2432. .pagetual-sideController-btn:hover {
  2433. transform: scale(1.5);
  2434. color: red;
  2435. }
  2436. `;
  2437. _GM_addStyle(cssText);
  2438. let frame = document.createElement("div");
  2439. frame.id = "pagetual-sideController";
  2440. frame.innerHTML = createHTML(`
  2441. <div id="pagetual-sideController-top" class="pagetual-sideController-btn">⊼</div>
  2442. <div>
  2443. <div id="pagetual-sideController-pre" class="pagetual-sideController-btn">∧</div>
  2444. <div id="pagetual-sideController-move"><svg width="30" height="30" style="display:initial;position:relative;cursor: pointer;margin: 0;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"><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"></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"></path></svg></div>
  2445. <div id="pagetual-sideController-next" class="pagetual-sideController-btn">∨</div>
  2446. </div>
  2447. <div id="pagetual-sideController-bottom" class="pagetual-sideController-btn">⊻</div>
  2448. `);
  2449. let top = frame.querySelector("#pagetual-sideController-top");
  2450. let pre = frame.querySelector("#pagetual-sideController-pre");
  2451. let move = frame.querySelector("#pagetual-sideController-move");
  2452. let next = frame.querySelector("#pagetual-sideController-next");
  2453. let bottom = frame.querySelector("#pagetual-sideController-bottom");
  2454.  
  2455. frame.addEventListener("dblclick", e => {
  2456. e.preventDefault();
  2457. e.stopPropagation();
  2458. }, true);
  2459.  
  2460. pre.addEventListener("click", e => {
  2461. let prePageBar = getPageBar().preBar;
  2462. if (prePageBar) {
  2463. scrollToPageBar(prePageBar);
  2464. } else {
  2465. let scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
  2466. window.scrollTo({ top: scrollTop - (window.innerHeight || document.documentElement.clientHeight), behavior: 'smooth'});
  2467. }
  2468. }, true);
  2469.  
  2470. next.addEventListener("click", e => {
  2471. let pageBarObj = getPageBar();
  2472. let nextPageBar = pageBarObj.nextBar;
  2473. if (nextPageBar) {
  2474. scrollToPageBar(nextPageBar);
  2475. } else {
  2476. if (pageBarObj.preBar) {
  2477. let scrollH = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  2478. window.scrollTo({ top: (scrollH || 9999999), behavior: 'smooth'});
  2479. } else {
  2480. let scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
  2481. window.scrollTo({ top: scrollTop + (window.innerHeight || document.documentElement.clientHeight), behavior: 'smooth'});
  2482. }
  2483. }
  2484. }, true);
  2485.  
  2486. top.addEventListener("click", e => {
  2487. document.body.scrollTop=0;
  2488. document.documentElement.scrollTop=0;
  2489. e.preventDefault();
  2490. e.stopPropagation();
  2491. }, true);
  2492.  
  2493. bottom.addEventListener("click", e => {
  2494. changeStop(true);
  2495. let scrollH = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  2496. document.body.scrollTop = scrollH || 9999999;
  2497. document.documentElement.scrollTop = scrollH || 9999999;
  2498. e.preventDefault();
  2499. e.stopPropagation();
  2500. }, true);
  2501.  
  2502. let initX, initY, moving = false;
  2503. move.addEventListener("click", e => {
  2504. if (!moving) {
  2505. changeStop(!isPause);
  2506. }
  2507. }, true);
  2508.  
  2509. let mouseMoveHandler = e => {
  2510. if (moving) {
  2511. let windowHeight=window.innerHeight || document.documentElement.clientHeight;
  2512. let windowWidth=window.innerWidth || document.documentElement.clientWidth;
  2513. initX = parseInt(e.clientX / windowWidth * 100);
  2514. initY = parseInt(e.clientY / windowHeight * 100);
  2515. this.frame.style.top = `calc(${initY}% - 70px)`;
  2516. this.frame.style.left = `calc(${initX}% - 5px)`;
  2517. } else if (Math.abs(e.clientX - initX) + Math.abs(e.clientY - initY) > 20) {
  2518. moving = true;
  2519. }
  2520. };
  2521. let mouseUpHandler = e => {
  2522. document.removeEventListener("mousemove", mouseMoveHandler, true);
  2523. document.removeEventListener("mouseup", mouseUpHandler, true);
  2524. if (moving) {
  2525. rulesData.sideControllerPos = {x: initX, y: initY};
  2526. storage.setItem("rulesData", rulesData);
  2527. }
  2528. };
  2529.  
  2530. move.addEventListener("mousedown", e => {
  2531. initX = e.clientX;
  2532. initY = e.clientY;
  2533. moving = false;
  2534. document.addEventListener("mousemove", mouseMoveHandler, true);
  2535. document.addEventListener("mouseup", mouseUpHandler, true);
  2536. }, true);
  2537.  
  2538. this.frame = frame;
  2539. if (rulesData.sideControllerPos) {
  2540. this.frame.style.top = `calc(${rulesData.sideControllerPos.y}% - 70px)`;
  2541. this.frame.style.left = `calc(${rulesData.sideControllerPos.x}% - 5px)`;
  2542. }
  2543. }
  2544.  
  2545. addToStage() {
  2546. document.body.appendChild(this.frame);
  2547. }
  2548. }
  2549.  
  2550. class NextSwitch {
  2551. static nextSwitch;
  2552. constructor() {
  2553. this.init();
  2554. }
  2555.  
  2556. static getInstance() {
  2557. if (!NextSwitch.nextSwitch) {
  2558. NextSwitch.nextSwitch = new NextSwitch();
  2559. }
  2560. return NextSwitch.nextSwitch;
  2561. }
  2562.  
  2563. init() {
  2564. let self = this;
  2565. let cssText = `
  2566. #pagetual-nextSwitch {
  2567. position: fixed;
  2568. top: 10px;
  2569. left: calc(50% - 160px);
  2570. background: aliceblue;
  2571. padding: 10px;
  2572. border-radius: 5px;
  2573. text-align: center;
  2574. opacity: 0.95;
  2575. color: #161616;
  2576. z-index: 2147483647;
  2577. font-size: 16px;
  2578. box-shadow: rgb(0 0 0) 0px 0px 10px;
  2579. }
  2580. #pagetual-nextSwitch>.title {
  2581. margin: -5px 45px 10px 45px;
  2582. font-size: 20px;
  2583. font-weight: bold;
  2584. border-bottom: 1px solid black;
  2585. user-select: none;
  2586. color: orangered;
  2587. }
  2588. #pagetual-nextSwitch>.group {
  2589. display: flex;
  2590. flex-direction: column;
  2591. }
  2592. #pagetual-nextSwitch>.group>span {
  2593. color: #161616;
  2594. cursor: pointer;
  2595. margin: 3px;
  2596. font-size: larger;
  2597. }
  2598. #pagetual-nextSwitch>.group>span:hover {
  2599. color: red;
  2600. }
  2601. #pagetual-nextSwitch>.group>span.current {
  2602. border: 2px dotted red;
  2603. border-radius: 10px;
  2604. }
  2605. #pagetual-nextSwitch>.closeSwitch {
  2606. position: absolute;
  2607. top: 3px;
  2608. right: 10px;
  2609. background: none;
  2610. border: none;
  2611. vertical-align: top;
  2612. transition: transform .15s ease-in-out;
  2613. float: right;
  2614. cursor: pointer;
  2615. }
  2616. #pagetual-nextSwitch svg {
  2617. width: 30px;
  2618. height: 30px;
  2619. vertical-align: middle;
  2620. fill: #161616;
  2621. overflow: hidden;
  2622. }
  2623. #pagetual-nextSwitch button:hover {
  2624. transform: scale(1.2);
  2625. }
  2626. `;
  2627. _GM_addStyle(cssText);
  2628. let frame = document.createElement("div");
  2629. frame.id = "pagetual-nextSwitch";
  2630. frame.innerHTML = createHTML(`
  2631. <div class="title">${i18n("nextSwitch")}</div>
  2632. <button type="button" class="closeSwitch">
  2633. <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2754">
  2634. <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">
  2635. </path>
  2636. </svg>
  2637. </button>
  2638. <div class="group"></div>
  2639. `);
  2640. let group = frame.querySelector(".group");
  2641. let closeBtn = frame.querySelector(".closeSwitch");
  2642. closeBtn.addEventListener("click", e => {
  2643. self.close();
  2644. }, true);
  2645. this.frame = frame;
  2646. let currentSpan;
  2647. ruleParser.curSiteRule.nextLink.forEach((link, i) => {
  2648. let span = document.createElement("span");
  2649. let target = getElement(link, document);
  2650. let index = "<b>" + (i + 1) + "</b>: ";
  2651. if (target) {
  2652. let targetInner = target.innerText.trim();
  2653. span.innerHTML = index + (targetInner || link);
  2654. } else {
  2655. span.innerHTML = index + "Not Found";
  2656. }
  2657. span.title = link;
  2658. span.addEventListener("click", e => {
  2659. if (currentSpan) currentSpan.classList.remove("current");
  2660. span.classList.add("current");
  2661. currentSpan = span;
  2662. nextIndex = i;
  2663. storage.setItem("nextSwitch_" + location.host, nextIndex === 0 ? "" : nextIndex);
  2664. ruleParser.curUrl += "#pagetual";
  2665. ruleParser.oldUrl = ruleParser.curUrl;
  2666. autoLoadNum = -1;
  2667. if (!ruleParser.nextLinkHref) {
  2668. isLoading = false;
  2669. }
  2670. ruleParser.getNextLink(ruleParser.pageDoc || document);
  2671. self.close();
  2672. }, true);
  2673. if (i == nextIndex) {
  2674. span.classList.add("current");
  2675. currentSpan = span;
  2676. }
  2677. group.appendChild(span);
  2678. });
  2679. }
  2680.  
  2681. start() {
  2682. document.documentElement.appendChild(this.frame);
  2683. }
  2684.  
  2685. close() {
  2686. if (this.frame.parentNode) this.frame.parentNode.removeChild(this.frame);
  2687. }
  2688. }
  2689.  
  2690. class Picker {
  2691. static picker;
  2692. constructor() {
  2693. this.init();
  2694. }
  2695.  
  2696. static getInstance() {
  2697. if (!Picker.picker) {
  2698. Picker.picker = new Picker();
  2699. }
  2700. return Picker.picker;
  2701. }
  2702.  
  2703. init() {
  2704. let self = this;
  2705. this.signList = [];
  2706. let cssText = `
  2707. body.pagetual-picker,
  2708. body.pagetual-picker *:hover,
  2709. body.pagetual-picker a:hover {
  2710. cursor: crosshair !important;
  2711. }
  2712. #pagetual-picker {
  2713. position: fixed;
  2714. top: 10px;
  2715. left: calc(50% - 178px);
  2716. background: aliceblue;
  2717. padding: 10px;
  2718. border-radius: 5px;
  2719. text-align: center;
  2720. opacity: 0.95;
  2721. color: #161616;
  2722. z-index: 2147483647;
  2723. font-size: 16px;
  2724. box-shadow: rgb(0 0 0) 0px 0px 10px;
  2725. }
  2726. #pagetual-picker * {
  2727. margin: 0;
  2728. padding: 0;
  2729. }
  2730. #pagetual-picker>.title {
  2731. margin: -5px 45px 10px 45px;
  2732. font-size: 20px;
  2733. font-weight: bold;
  2734. cursor: move;
  2735. border-bottom: 1px solid black;
  2736. user-select: none;
  2737. color: orangered;
  2738. font-family: Times New Roman;
  2739. }
  2740. #pagetual-picker button {
  2741. background: none;
  2742. border: none;
  2743. vertical-align: top;
  2744. transition: transform .15s ease-in-out;
  2745. float: right;
  2746. cursor: pointer;
  2747. }
  2748. #pagetual-picker button:hover {
  2749. transform: scale(1.2);
  2750. }
  2751. #pagetual-picker>.closePicker {
  2752. position: absolute;
  2753. top: 3px;
  2754. right: 10px;
  2755. }
  2756. #pagetual-picker>.logoToHome {
  2757. position: absolute;
  2758. top: 3px;
  2759. left: 10px;
  2760. }
  2761. #pagetual-picker .selector{
  2762. display: inline-block;
  2763. width: 290px;
  2764. height: 20px;
  2765. max-width: calc(65vw - 50px);
  2766. padding: 6px 12px;
  2767. font-size: 16px;
  2768. font-weight: 400;
  2769. line-height: 1.5;
  2770. color: #495057;
  2771. background-color: #fff;
  2772. background-clip: padding-box;
  2773. border: 1px solid #ced4da;
  2774. border-radius: 4px;
  2775. transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;
  2776. box-sizing: content-box;
  2777. }
  2778. #pagetual-picker .selector:focus {
  2779. color: #495057;
  2780. background-color: #fff;
  2781. border-color: #80bdff;
  2782. outline: 0;
  2783. box-shadow: 0 0 0 3.2px rgb(0 123 255 / 25%);
  2784. }
  2785. #pagetual-picker [type=checkbox],
  2786. #pagetual-picker [type=radio] {
  2787. line-height: 20px;
  2788. height: 25px;
  2789. width: 25px;
  2790. margin-left: 5px;
  2791. vertical-align: middle;
  2792. appearance: auto;
  2793. display: inline-block;
  2794. }
  2795. #pagetual-picker label {
  2796. font-size: 18px;
  2797. line-height: 25px;
  2798. vertical-align: middle;
  2799. display: inline-block;
  2800. color: black;
  2801. }
  2802. #pagetual-picker .bottom {
  2803. text-align: left;
  2804. margin: 10px 0;
  2805. width: 100%;
  2806. }
  2807. #pagetual-picker .bottom>button {
  2808. float: right;
  2809. }
  2810. #pagetual-picker svg {
  2811. width: 30px;
  2812. height: 30px;
  2813. vertical-align: middle;
  2814. fill: #161616;
  2815. overflow: hidden;
  2816. }
  2817. #pagetual-picker .allpath {
  2818. font-size: 18px;
  2819. margin: 10px;
  2820. max-width: 350px;
  2821. word-break: break-all;
  2822. cursor: context-menu;
  2823. overflow: hidden;
  2824. max-height: 42px;
  2825. -moz-transition:max-height 1s ease-in;
  2826. -webkit-transition:max-height 1s ease-in;
  2827. transition:max-height 1s ease-in;
  2828. color: black;
  2829. }
  2830. #pagetual-picker .allpath:hover {
  2831. max-height: calc(100vh - 130px);
  2832. overflow: auto;
  2833. }
  2834. #pagetual-picker .allpath>span.path {
  2835. cursor: pointer;
  2836. }
  2837. #pagetual-picker .allpath>span.path:hover {
  2838. color: orangered;
  2839. }
  2840. #pagetual-picker .moreConfig {
  2841. display: flex;
  2842. justify-content: space-between;
  2843. border-top: 1px solid;
  2844. padding-top: 10px;
  2845. width: 100%;
  2846. }
  2847. #pagetual-picker .command {
  2848. width: 100%;
  2849. color: black!important;
  2850. text-align: center;
  2851. font-size: large;
  2852. margin-top: 10px;
  2853. }
  2854. #pagetual-picker .command:hover {
  2855. color: orangered;
  2856. }
  2857. `;
  2858. _GM_addStyle(cssText);
  2859. this.mainSignDiv = this.createSignDiv();
  2860. this.allSignDiv = [];
  2861. let frame = document.createElement("div");
  2862. frame.id = "pagetual-picker";
  2863. frame.innerHTML = createHTML(`
  2864. <button title="Pagetual" type="button" class="logoToHome">
  2865. <svg width="30" height="30" class="upSvg pagetual" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><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"></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"></path></svg>
  2866. </button>
  2867. <div class="title">${i18n("picker")}</div>
  2868. <button title="${i18n("closePicker")}" type="button" class="closePicker">
  2869. <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><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" fill="#604b4a"></path></svg>
  2870. </button>
  2871. <div class="allpath" title="${i18n("switchSelector")}"></div>
  2872. <div>
  2873. <textarea class="selector" spellcheck="false" name="selector" placeholder="${i18n("pickerPlaceholder")}"></textarea>
  2874. <button id="check" title="${i18n("pickerCheck")}" type="button">
  2875. <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><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" fill="#604b4a"></path></svg>
  2876. </button>
  2877. </div>
  2878. <div class="bottom">
  2879. <input name="xpath" id="checkbox_id" type="checkbox">
  2880. <label for="checkbox_id">XPath</label>
  2881. <button id="edit" title="${i18n("gotoEdit")}" type="button">
  2882. <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" style="color: orangered;fill: orangered;">
  2883. <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">
  2884. </path>
  2885. </svg>
  2886. </button>
  2887. </div>
  2888. <div class="moreConfig">
  2889. <div title="${i18n('forceStateIframe')}">
  2890. <input name="forceState" id="forceStateIframe" type="radio">
  2891. <label for="forceStateIframe">Iframe</label>
  2892. </div>
  2893. <div title="${i18n('forceStateDynamic')}">
  2894. <input name="forceState" id="forceStateDynamic" type="radio">
  2895. <label for="forceStateDynamic">Dynamic</label>
  2896. </div>
  2897. <div title="${i18n('forceStateDisable')}">
  2898. <input name="forceState" id="forceStateDisable" type="radio">
  2899. <label for="forceStateDisable">Disable</label>
  2900. </div>
  2901. </div>
  2902. <button id="nextSwitch" class="command" title="${i18n("nextSwitch")}" type="button">${i18n("nextSwitch")}</button>
  2903. <button id="loadNow" class="command" title="${i18n("loadNow")}" type="button">${i18n("loadNow")}</button>
  2904. `);
  2905. let forceStateIframe = frame.querySelector("#forceStateIframe");//forceState 1 禁用 2 强嵌 3 动态
  2906. let forceStateDynamic = frame.querySelector("#forceStateDynamic");
  2907. let forceStateDisable = frame.querySelector("#forceStateDisable");
  2908. let clickRadio = e => {
  2909. let radio = e.currentTarget.querySelector('input');
  2910. if (radio.checked) {
  2911. forceState = "";
  2912. } else {
  2913. switch (radio.id) {
  2914. case "forceStateIframe":
  2915. forceState = 2;
  2916. break;
  2917. case "forceStateDynamic":
  2918. forceState = 3;
  2919. break;
  2920. case "forceStateDisable":
  2921. forceState = 1;
  2922. break;
  2923. default:
  2924. return;
  2925. }
  2926. }
  2927. storage.setItem("forceState_"+location.host, forceState);
  2928. self.close();
  2929. location.reload();
  2930. };
  2931. forceStateIframe.parentNode.addEventListener("mousedown", clickRadio);
  2932. forceStateDynamic.parentNode.addEventListener("mousedown", clickRadio);
  2933. forceStateDisable.parentNode.addEventListener("mousedown", clickRadio);
  2934. if (forceState == 1) forceStateDisable.checked = true;
  2935. else if (forceState == 2) forceStateIframe.checked = true;
  2936. else if (forceState == 3) forceStateDynamic.checked = true;
  2937. let closeBtn = frame.querySelector(".closePicker");
  2938. let homeBtn = frame.querySelector(".logoToHome");
  2939. let title = frame.querySelector(".title");
  2940. let allpath = frame.querySelector(".allpath");
  2941. let selectorInput = frame.querySelector(".selector");
  2942. let xpath = frame.querySelector("#checkbox_id");
  2943. let checkBtn = frame.querySelector("#check");
  2944. let editBtn = frame.querySelector("#edit");
  2945. let nextSwitch = frame.querySelector("#nextSwitch");
  2946. let loadNow = frame.querySelector("#loadNow");
  2947. nextSwitch.addEventListener("click", e => {
  2948. self.close();
  2949. NextSwitch.getInstance().start();
  2950. }, true);
  2951. loadNow.addEventListener("click", e => {
  2952. self.close();
  2953. let loadNum=window.prompt(i18n("loadConfirm"), "1");
  2954. if(loadNum==="" || loadNum===null)return;
  2955. autoLoadNum=Math.abs(parseInt(loadNum));
  2956. nextPage();
  2957. }, true);
  2958. closeBtn.addEventListener("click", e => {
  2959. self.close();
  2960. }, true);
  2961. homeBtn.addEventListener("click", e => {
  2962. _GM_openInTab(configPage[0], {active: true});
  2963. }, true);
  2964. let moving = false;
  2965. let moveHanlder = e => {
  2966. frame.style.left = e.clientX - 200 + "px";
  2967. frame.style.top = e.clientY - 15 + "px";
  2968. e.stopPropagation();
  2969. e.preventDefault();
  2970. };
  2971. let upHanlder = e => {
  2972. moving = false;
  2973. document.removeEventListener("mousemove", moveHanlder, true);
  2974. title.removeEventListener("mouseup", upHanlder, true);
  2975. e.stopPropagation();
  2976. e.preventDefault();
  2977. };
  2978. title.addEventListener("mousedown", e => {
  2979. moving = true;
  2980. document.addEventListener("mousemove", moveHanlder, true);
  2981. title.addEventListener("mouseup", upHanlder, true);
  2982. });
  2983. frame.addEventListener("mouseenter", e => {
  2984. if (moving) return;
  2985. if (self.mainSignDiv.parentNode) self.mainSignDiv.parentNode.removeChild(self.mainSignDiv);
  2986. self.checkInputSelector();
  2987. });
  2988. frame.addEventListener("mouseleave", e => {
  2989. if (moving) return;
  2990. document.body.appendChild(self.mainSignDiv);
  2991. self.clearSigns();
  2992. });
  2993. checkBtn.addEventListener("click", e => {
  2994. self.checkInputSelector();
  2995. if (this.selectorInput.value) _GM_setClipboard(this.selectorInput.value);
  2996. });
  2997. xpath.addEventListener("click", e => {
  2998. if (!selectorInput.value) {
  2999. self.setSelectorDiv("");
  3000. return;
  3001. }
  3002. let element = getElement(selectorInput.value, document);
  3003. let selector = self.getSelectorFromEle(element);
  3004. self.setSelectorDiv(selector);
  3005. selectorInput.value = selector;
  3006. });
  3007. editBtn.addEventListener("click", e => {
  3008. let editTemp;
  3009. if (ruleParser.curSiteRule.url && !ruleParser.curSiteRule.singleUrl) {
  3010. editTemp = ruleParser.curSiteRule;
  3011. } else {
  3012. editTemp = {
  3013. name: document.title,
  3014. url: "^" + location.origin.replace(/^https?/, "https?").replace(/\./g,"\\.") + "/"
  3015. };
  3016. }
  3017. if (selectorInput.value) {
  3018. editTemp.pageElement = selectorInput.value;
  3019. }
  3020. delete editTemp.from;
  3021. delete editTemp.type;
  3022. delete editTemp.updatedAt;
  3023. rulesData.editTemp = editTemp;
  3024. storage.setItem("rulesData", rulesData);
  3025. _GM_openInTab(configPage[0], {active: true});
  3026. });
  3027. this.frame = frame;
  3028. this.xpath = xpath;
  3029. this.allpath = allpath;
  3030. this.selectorInput = selectorInput;
  3031. this.nextSwitch = nextSwitch;
  3032. this.loadNow = loadNow;
  3033. this.moveHandler = e => {
  3034. if (e.target === document) return;
  3035. self.adjustSignDiv(self.mainSignDiv, self.getTarget(e.target));
  3036. };
  3037. this.clickHandler = e => {
  3038. if (self.inPicker) {
  3039. e.stopPropagation();
  3040. e.preventDefault();
  3041. }
  3042. let target = self.getTarget(e.target);
  3043. let selector = self.getSelectorFromEle(target);
  3044. self.setSelectorDiv(selector);
  3045. selectorInput.value = selector;
  3046. };
  3047. }
  3048.  
  3049. getTarget(ele) {
  3050. while (ele.parentNode && (ele.scrollWidth === 0 || ele.scrollHeight === 0)) {
  3051. ele = ele.parentNode;
  3052. }
  3053. return ele;
  3054. }
  3055.  
  3056. close() {
  3057. this.clearSigns();
  3058. if (this.frame.parentNode) this.frame.parentNode.removeChild(this.frame);
  3059. if (this.mainSignDiv.parentNode) this.mainSignDiv.parentNode.removeChild(this.mainSignDiv);
  3060. document.body.classList.remove("pagetual-picker");
  3061. document.body.removeEventListener("mousemove", this.moveHandler, true);
  3062. document.body.removeEventListener("click", this.clickHandler, true);
  3063. this.inPicker = false;
  3064. }
  3065.  
  3066. setImportant(ele, prop, value) {
  3067. ele.style.setProperty(prop, value, "important");
  3068. }
  3069.  
  3070. createSignDiv() {
  3071. let signDiv = document.createElement("div");
  3072. this.setImportant(signDiv, "position", "absolute");
  3073. this.setImportant(signDiv, "pointer-events", "none");
  3074. this.setImportant(signDiv, "z-index", "2147483647");
  3075. this.setImportant(signDiv, "background", "rgba(120, 170, 210, 0.6)");
  3076. this.setImportant(signDiv, "transition", "all 0.15s ease-out");
  3077. this.setImportant(signDiv, "box-shadow", "rgb(0 0 0) 0px 0px 3px 0px");
  3078. return signDiv;
  3079. }
  3080.  
  3081. adjustSignDiv(div, target) {
  3082. let rect = target.getBoundingClientRect();
  3083. this.setImportant(div, "width", rect.width + "px");
  3084. this.setImportant(div, "height", rect.height + "px");
  3085. this.setImportant(div, "left", rect.left + window.scrollX + "px");
  3086. this.setImportant(div, "top", rect.top + window.scrollY + "px");
  3087. }
  3088.  
  3089. getSelectorFromEle(ele) {
  3090. return this.xpath.checked ? createXPathFromElement(ele) : geneSelector(ele, true);
  3091. }
  3092.  
  3093. setSelectorDiv(selector) {
  3094. let self = this;
  3095. this.allpath.innerHTML = createHTML("");
  3096. if (!selector) return;
  3097. if (this.xpath.checked) {
  3098. let span = document.createElement("span");
  3099. span.innerText = selector;
  3100. span.addEventListener("click", e => {
  3101. self.selectorInput.value = selector;
  3102. self.checkInputSelector();
  3103. }, true);
  3104. this.allpath.appendChild(span);
  3105. } else {
  3106. selector.split(">").forEach((item, index) => self.geneSelectorItem(item, index));
  3107. }
  3108. }
  3109.  
  3110. geneSelectorItem(item, index) {
  3111. let self = this;
  3112. item = item.trim();
  3113. if (!item) return;
  3114. if (index !== 0) {
  3115. let span = document.createElement("span");
  3116. span.innerText = " > ";
  3117. this.allpath.appendChild(span);
  3118. }
  3119. let span = document.createElement("span");
  3120. span.className = "path";
  3121. span.innerText = item;
  3122. span.addEventListener("click", e => {
  3123. let selector = "";
  3124. let target = e.target;
  3125. while (target) {
  3126. selector = target.innerText + selector;
  3127. target = target.previousElementSibling;
  3128. }
  3129. self.selectorInput.value = selector;
  3130. self.checkInputSelector();
  3131. }, true);
  3132. this.allpath.appendChild(span);
  3133. }
  3134.  
  3135. checkInputSelector() {
  3136. let self = this;
  3137. this.clearSigns();
  3138. if (!this.selectorInput.value) return;
  3139. let eles = getAllElements(this.selectorInput.value, document);
  3140. if (eles && eles.length > 0) {
  3141. eles.forEach(ele => {
  3142. let sign = self.createSignDiv();
  3143. document.body.appendChild(sign);
  3144. self.adjustSignDiv(sign, ele);
  3145. self.signList.push(sign);
  3146. });
  3147. }
  3148. }
  3149.  
  3150. clearSigns() {
  3151. this.signList.forEach(sign => {
  3152. if (sign.parentNode) sign.parentNode.removeChild(sign);
  3153. });
  3154. this.signList = [];
  3155. }
  3156.  
  3157. start() {
  3158. if (this.inPicker) return;
  3159. this.inPicker = true;
  3160. document.documentElement.appendChild(this.frame);
  3161. document.body.appendChild(this.mainSignDiv);
  3162. document.body.classList.add("pagetual-picker");
  3163.  
  3164. document.body.addEventListener("mousemove", this.moveHandler, true);
  3165. document.body.addEventListener("click", this.clickHandler, true);
  3166. this.xpath.checked = isXPath(ruleParser.curSiteRule.pageElement);
  3167.  
  3168. this.loadNow.style.display = ruleParser.nextLinkHref ? "block" : "none";
  3169. if (ruleParser.curSiteRule.nextLink && Array && Array.isArray && Array.isArray(ruleParser.curSiteRule.nextLink)) {
  3170. this.nextSwitch.style.display = "block";
  3171. } else {
  3172. this.nextSwitch.style.display = "none";
  3173. }
  3174.  
  3175. let pageElementSel=ruleParser.curSiteRule.pageElement || "";
  3176. if(Array && Array.isArray && Array.isArray(pageElementSel)){
  3177. pageElementSel=pageElementSel[nextIndex<pageElementSel.length?nextIndex:0];
  3178. }
  3179. this.setSelectorDiv(pageElementSel);
  3180. }
  3181. }
  3182.  
  3183. function createEdit(){
  3184. var options = {
  3185. mode: 'code',
  3186. modes: ['code', 'tree'],
  3187. templates: [
  3188. {
  3189. text: 'New site',
  3190. title: 'Insert a new site',
  3191. className: 'jsoneditor-type-object',
  3192. field: 'SiteTemplate',
  3193. value: {
  3194. 'name': 'Site name',
  3195. 'url': 'Site url'
  3196. }
  3197. }
  3198. ],
  3199. schema: {
  3200. "title": "Sites data",
  3201. "description": "Object containing site config",
  3202. "type": "array",
  3203. "items": {
  3204. "type": 'object',
  3205. "properties": {
  3206. "name": {
  3207. "title": "Site Name",
  3208. "description": "The site's name.",
  3209. "examples": [
  3210. "Google"
  3211. ],
  3212. "type": "string"
  3213. },
  3214. "url": {
  3215. "title": "Site Url",
  3216. "description": "The Regexp of site's url.",
  3217. "examples": [
  3218. "^https:\/\/yande\\.re\/"
  3219. ],
  3220. "type": "string"
  3221. }
  3222. },
  3223. "required": ["name", "url"]
  3224. }
  3225. }
  3226. };
  3227. var container = document.getElementById("jsoneditor");
  3228. container.style.height = '800px';
  3229. container.innerHTML = "";
  3230. var editor = new JSONEditor(container, options);
  3231. editor.set(ruleParser.customRules);
  3232. document.querySelector("#saveBtn").onclick=e=>{
  3233. try{
  3234. storage.setItem("hpRules", []);
  3235. storage.setItem("smartRules", []);
  3236. let customRules=editor.get();
  3237. if(!customRules){
  3238. storage.setItem("customRules", "");
  3239. }else{
  3240. if(Array && Array.isArray && !Array.isArray(customRules)){
  3241. showTips("Rules must be a Array!");
  3242. return;
  3243. }
  3244. debug(customRules);
  3245. storage.setItem("customRules", customRules);
  3246. }
  3247. }catch(e){
  3248. debug(e);
  3249. showTips("JSON error, check again!");
  3250. return;
  3251. }
  3252. showTips("Edit successfully");
  3253. };
  3254. }
  3255.  
  3256. function initConfig(){
  3257. initView();
  3258. try{
  3259. if(_unsafeWindow.initedPagetual){
  3260. if(ruleImportUrlReg.test(location.href)){
  3261. showTips(i18n('duplicate'));
  3262. }
  3263. return true;
  3264. }
  3265. _unsafeWindow.initedPagetual=true;
  3266. }catch(e){}
  3267. _GM_registerMenuCommand(i18n(forceState==1?"enable":"disableSite"), ()=>{
  3268. forceState=(forceState==1?0:1);
  3269. storage.setItem("forceState_"+location.host, forceState);
  3270. showTips(i18n(forceState==1?"disableSiteTips":"enableSiteTips"));
  3271. if(!ruleParser.curSiteRule.url) location.reload();
  3272. });
  3273. _GM_registerMenuCommand(i18n("update"), ()=>{
  3274. updateRules(()=>{
  3275. showTips(i18n("updateSucc"));
  3276. location.reload();
  3277. },(rule,err)=>{
  3278. showTips("Update "+rule.url+" rules fail!");
  3279. });
  3280. showTips(i18n("beginUpdate"));
  3281. });
  3282. if(guidePage.test(location.href)){
  3283. if(typeof JSONEditor !== 'undefined'){
  3284. createEdit();
  3285. }else{
  3286. window.onload = e => {
  3287. createEdit();
  3288. }
  3289. }
  3290. return true;
  3291. }
  3292. if(location.href.indexOf("PagetualGuide")!=-1) return true;
  3293. if(location.hostname==="pagetual.hoothin.com") return true;
  3294.  
  3295. var configCon,insertPos;
  3296. var noRules=!rulesData.urls || rulesData.urls.length===0;
  3297.  
  3298. let inConfig = false;
  3299. for (let i = 0; i < configPage.length; i++) {
  3300. if (configPage[i] == location.href) {
  3301. inConfig = true;
  3302. break;
  3303. }
  3304. }
  3305. if(ruleImportUrlReg.test(location.href) || inConfig){
  3306. let importing = false;
  3307. if(noRules){
  3308. setTimeout(() => {
  3309. if (!importing) showTips(i18n("firstAlert"));
  3310. }, 3000);
  3311. setTimeout(() => {
  3312. if (!importing) showTips(i18n("firstAlert"));
  3313. }, 6000);
  3314. showTips(i18n("firstAlert"));
  3315. }
  3316. let createImportBtn = () => {
  3317. let importBtn = document.createElement("button");
  3318. importBtn.innerText = i18n("import");
  3319. importBtn.style.marginTop = "100px";
  3320. importBtn.style.float = "right";
  3321. importBtn.style.position = "relative";
  3322. importBtn.style.display = "block";
  3323. importBtn.style.fontSize = "20px";
  3324. importBtn.addEventListener("click", e => {
  3325. let parentNode = importBtn.parentNode;
  3326. if (!parentNode) return;
  3327. parentNode.removeChild(importBtn);
  3328. try {
  3329. let rules=parentNode.innerText.trim();
  3330. let isContent=/['"]name['"]/i.test(rules);
  3331. if(isContent){
  3332. let ruleList=JSON.parse(`[${rules}]`);
  3333. for(let i in ruleList){
  3334. let hasRule = false;
  3335. let r = ruleList[i];
  3336. for(let j in ruleParser.customRules){
  3337. if(ruleParser.customRules[j].name == r.name){
  3338. ruleParser.customRules[j] = r;
  3339. hasRule = true;
  3340. break;
  3341. }
  3342. }
  3343. if(!hasRule)ruleParser.customRules.push(r);
  3344. }
  3345. storage.setItem("customRules", ruleParser.customRules);
  3346. storage.setItem("hpRules", []);
  3347. storage.setItem("smartRules", []);
  3348. showTips(i18n("importSucc"));
  3349. }else{
  3350. rules=rules.split("\n");
  3351. let diff=false;
  3352. for(let c=0;c<rules.length;c++){
  3353. let urlArr=rules[c].split("|"),url,type=1;
  3354. if(urlArr.length==1){
  3355. url=urlArr[0].trim();
  3356. if(!/^http/.test(url)){
  3357. showTips("Wrong url, check again!");
  3358. return;
  3359. }
  3360. }else if(urlArr.length==2){
  3361. type=urlArr[0].trim();
  3362. url=urlArr[1].trim();
  3363. if(!/^http/.test(url)){
  3364. showTips("Wrong url, check again!");
  3365. return;
  3366. }
  3367. }else{
  3368. break;
  3369. }
  3370. let maxId=0,hasUrl=false;
  3371. if(!rulesData.urls){
  3372. rulesData.urls=[];
  3373. maxId=1;
  3374. }else{
  3375. rulesData.urls.forEach(u=>{
  3376. if(maxId<u.id){
  3377. maxId=u.id;
  3378. }
  3379. if(u.url==url){
  3380. hasUrl=true;
  3381. }
  3382. });
  3383. if(hasUrl)break;
  3384. }
  3385. diff=true;
  3386. if(!rulesData.sort)rulesData.sort=[1];
  3387. rulesData.urls.push({id:maxId+1,url:url,type:type});
  3388. rulesData.sort.unshift(maxId+1);
  3389. }
  3390. if(!diff){
  3391. showTips("Already exists!");
  3392. return;
  3393. }
  3394. storage.setItem("rulesData", rulesData);
  3395.  
  3396. if(rulesData.urls)ruleUrls=ruleUrls.concat(rulesData.urls);
  3397. if(rulesData.sort){
  3398. let urls=[];
  3399. rulesData.sort.forEach(id=>{
  3400. for(let s=0;s<ruleUrls.length;s++){
  3401. if(id==ruleUrls[s].id){
  3402. urls.push(ruleUrls[s]);
  3403. break;
  3404. }
  3405. }
  3406. });
  3407. ruleUrls=urls;
  3408. }
  3409. updateRules(()=>{
  3410. showTips(i18n("updateSucc"));
  3411. location.reload();
  3412. },(rule,err)=>{
  3413. showTips("Update "+rule.url+" rules fail!");
  3414. });
  3415. importing = true;
  3416. showTips(i18n("beginUpdate"));
  3417. }
  3418. } catch (e) {
  3419. _GM_notification(e.toString());
  3420. }
  3421. });
  3422. return importBtn;
  3423. };
  3424. [].forEach.call(document.querySelectorAll('pre[name=pagetual],pre[name=user-content-pagetual]'), pre => {
  3425. let importBtn = createImportBtn();
  3426. let clientHeight = 35 - pre.clientHeight;
  3427. if (clientHeight > -20) clientHeight = -20;
  3428. importBtn.style.marginTop = `${clientHeight}px`;
  3429. pre.appendChild(importBtn);
  3430. });
  3431. document.addEventListener("mouseover", e => {
  3432. if (e.target.tagName === "PRE") {
  3433. let nameAttr=e.target.getAttribute("name");
  3434. if(nameAttr=="pagetual" || nameAttr=="user-content-pagetual"){
  3435. if (e.target.querySelector('button')) return;
  3436. let importBtn = createImportBtn();
  3437. let clientHeight = 35 - e.target.clientHeight;
  3438. if (clientHeight > -20) clientHeight = -20;
  3439. importBtn.style.marginTop = `${clientHeight}px`;
  3440. e.target.appendChild(importBtn);
  3441. }
  3442. }
  3443. });
  3444.  
  3445. if(inConfig){
  3446. _GM_addStyle(`
  3447. p>span:nth-child(1),p>span:nth-child(2),p>span:nth-child(3){
  3448. cursor: pointer;
  3449. user-select: none;
  3450. }
  3451. p>span:nth-child(1):hover,p>span:nth-child(2):hover,p>span:nth-child(3):hover{
  3452. color:red;
  3453. }
  3454. .updateDate{
  3455. cursor: pointer;
  3456. user-select: none;
  3457. }
  3458. .updateDate:hover{
  3459. color:red;
  3460. }
  3461. input[type=number]::-webkit-inner-spin-button,
  3462. input[type=number]::-webkit-outer-spin-button {
  3463. -webkit-appearance: none;
  3464. margin: 0;
  3465. }
  3466. input[type=number] {
  3467. -moz-appearance:textfield;
  3468. }
  3469. `);
  3470. document.querySelector("[name='user-content-click2import'],[name='click2import']").innerText=i18n("click2ImportRule")
  3471. configCon=document.querySelector(".markdown-body");
  3472. insertPos=configCon.querySelector("hr");
  3473.  
  3474. if(!noRules){
  3475. document.querySelector("pre[name='user-content-pagetual'],pre[name='pagetual']").style.display="none";
  3476. document.querySelector("p[name='user-content-click2import'],p[name='click2import']").style.display="none";
  3477. }
  3478. }else return true;
  3479. }else return false;
  3480. class Rulebar {
  3481. init(ruleUrl){
  3482. this.ruleUrl=ruleUrl;
  3483. this.item=document.createElement("p");
  3484. this.item.dataset.id=this.ruleUrl.id;
  3485. let url=document.createElement("span");
  3486. url.innerHTML=ruleUrl.url;
  3487. let up=document.createElement("span");
  3488. up.innerHTML="↑ ";
  3489. up.title=i18n("sortTitle");
  3490. let down=document.createElement("span");
  3491. down.innerHTML="↓ ";
  3492. down.title=i18n("sortTitle");
  3493. let del=document.createElement("span");
  3494. del.innerHTML="× ";
  3495. up.onclick=e=>{
  3496. this.moveUp();
  3497. };
  3498. down.onclick=e=>{
  3499. this.moveDown();
  3500. };
  3501. del.onclick=e=>{
  3502. this.del();
  3503. };
  3504. this.item.appendChild(up);
  3505. this.item.appendChild(down);
  3506. this.item.appendChild(del);
  3507. this.item.appendChild(url);
  3508. configCon.insertBefore(this.item, insertPos);
  3509. }
  3510. saveSort(){
  3511. let sort=[];
  3512. [].forEach.call(this.item.parentNode.querySelectorAll("p[data-id]"), i=>{
  3513. sort.push(i.dataset.id);
  3514. });
  3515. rulesData.sort=sort;
  3516. storage.setItem("rulesData", rulesData);
  3517. }
  3518. moveUp(){
  3519. let preE=this.item.previousElementSibling;
  3520. if(preE.tagName=="P" && preE.children.length>1){
  3521. this.item.parentNode.insertBefore(this.item,preE);
  3522. this.saveSort();
  3523. }
  3524. }
  3525. moveDown(){
  3526. let nextE=this.item.nextElementSibling;
  3527. if(nextE.tagName=="P" && nextE.children.length>1){
  3528. this.item.parentNode.insertBefore(nextE,this.item);
  3529. this.saveSort();
  3530. }
  3531. }
  3532. del(){
  3533. if(this.ruleUrl.id<2){
  3534. showTips(i18n("cantDel"));
  3535. }else if(window.confirm(i18n("confirmDel"))){
  3536. for(let u=0;u<rulesData.urls.length;u++){
  3537. if(this.ruleUrl.id==rulesData.urls[u].id){
  3538. rulesData.urls.splice(u,1);
  3539. break;
  3540. }
  3541. }
  3542. for(let u=0;u<ruleUrls.length;u++){
  3543. if(this.ruleUrl.id==ruleUrls[u].id){
  3544. ruleUrls.splice(u,1);
  3545. break;
  3546. }
  3547. }
  3548. for(let u=0;u<rulesData.sort.length;u++){
  3549. if(this.ruleUrl.id==rulesData.sort[u]){
  3550. rulesData.sort.splice(u,1);
  3551. break;
  3552. }
  3553. }
  3554. storage.setItem("rulesData", rulesData);
  3555. ruleParser.rules=ruleParser.rules.filter(item=>{return item.from!=this.ruleUrl.id});
  3556. storage.setItem("rules", ruleParser.rules);
  3557. this.item.parentNode.removeChild(this.item);
  3558. //location.reload();
  3559. }
  3560. }
  3561. }
  3562. let updateP=document.createElement("p"),i=0;
  3563. let now=new Date().getTime(),inUpdate=false;
  3564.  
  3565.  
  3566. let pastDate=(new Date(updateDate)).toString(),passStr;
  3567. let passTime=(now-updateDate)/1000;
  3568. if(isNaN(passTime)){
  3569. passStr=i18n("firstUpdate");
  3570. }else if(passTime<60){
  3571. passStr=i18n("passSec", parseInt(passTime))+" 👆 "+i18n("click2update");
  3572. }else if(passTime<60*60){
  3573. passStr=i18n("passMin", parseInt(passTime/60))+" 👆 "+i18n("click2update");
  3574. }else if(passTime<60*60*24){
  3575. passStr=i18n("passHour", parseInt(passTime/3600))+" 👆 "+i18n("click2update");
  3576. }else{
  3577. passStr=i18n("passDay", parseInt(passTime/86400))+" 👆 "+i18n("click2update");
  3578. }
  3579.  
  3580.  
  3581. updateP.className="updateDate";
  3582. updateP.innerHTML=passStr;
  3583. updateP.title=i18n("update")+" - "+pastDate;
  3584. updateP.onclick=e=>{
  3585. updateRules(()=>{
  3586. showTips(i18n("updateSucc"));
  3587. updateP.innerHTML=i18n("passSec", 0);
  3588. updateP.title=i18n("update");
  3589. },(rule,err)=>{
  3590. showTips("Update "+rule.url+" rules fail!");
  3591. });
  3592. showTips(i18n("beginUpdate"));
  3593. };
  3594. configCon.insertBefore(updateP, insertPos);
  3595. if(ruleUrls){
  3596. ruleUrls.forEach(ruleUrl=>{
  3597. var rulebar=new Rulebar();
  3598. rulebar.init(ruleUrl);
  3599. });
  3600. }
  3601. let customUrlsTitle=document.createElement("h2");
  3602. customUrlsTitle.innerHTML=i18n("customUrls");
  3603. configCon.insertBefore(customUrlsTitle, insertPos);
  3604. let customUrlsInput=document.createElement("textarea");
  3605. customUrlsInput.style.width="100%";
  3606. customUrlsInput.placeholder="http://wedata.net/databases/AutoPagerize/items_all.json";
  3607. customUrlsInput.spellcheck=false;
  3608. configCon.insertBefore(customUrlsInput, insertPos);
  3609.  
  3610. let btns=document.createElement("div");
  3611. btns.style.display="flex";
  3612. configCon.insertBefore(btns, insertPos);
  3613. let upBtnImg=document.createElement("div");
  3614. upBtnImg.style.width="50%";
  3615. let upBtnImgTitle=document.createElement("h2");
  3616. upBtnImgTitle.style.whiteSpace="nowrap";
  3617. upBtnImgTitle.style.overflow="auto";
  3618. upBtnImgTitle.innerHTML=i18n("upBtnImg");
  3619. upBtnImg.appendChild(upBtnImgTitle);
  3620. let upBtnImgInput=document.createElement("input");
  3621. upBtnImgInput.style.width="100%";
  3622. upBtnImgInput.placeholder="data:image/png;base64,UpBtn";
  3623. upBtnImgInput.value=rulesData.upBtnImg||'';
  3624. upBtnImgInput.spellcheck=false;
  3625. upBtnImg.appendChild(upBtnImgInput);
  3626. btns.appendChild(upBtnImg);
  3627.  
  3628. let downBtnImg=document.createElement("div");
  3629. downBtnImg.style.width="50%";
  3630. let downBtnImgTitle=document.createElement("h2");
  3631. downBtnImgTitle.style.whiteSpace="nowrap";
  3632. downBtnImgTitle.style.overflow="auto";
  3633. downBtnImgTitle.innerHTML=i18n("downBtnImg");
  3634. downBtnImg.appendChild(downBtnImgTitle);
  3635. let downBtnImgInput=document.createElement("input");
  3636. downBtnImgInput.style.width="100%";
  3637. downBtnImgInput.placeholder="data:image/png;base64,DownBtn";
  3638. downBtnImgInput.value=rulesData.downBtnImg||'';
  3639. downBtnImgInput.spellcheck=false;
  3640. downBtnImg.appendChild(downBtnImgInput);
  3641. btns.appendChild(downBtnImg);
  3642.  
  3643. let otherBtns=document.createElement("div");
  3644. otherBtns.style.display="flex";
  3645. configCon.insertBefore(otherBtns, insertPos);
  3646. let loadingText=document.createElement("div");
  3647. loadingText.style.width="100%";
  3648. let loadingTextTitle=document.createElement("h2");
  3649. loadingTextTitle.style.whiteSpace="nowrap";
  3650. loadingTextTitle.style.overflow="auto";
  3651. loadingTextTitle.innerHTML=i18n("loadingTextTitle");
  3652. loadingText.appendChild(loadingTextTitle);
  3653. let loadingTextInput=document.createElement("input");
  3654. loadingTextInput.value=rulesData.loadingText||'';
  3655. loadingTextInput.placeholder=i18n("loadingText");
  3656. loadingTextInput.style.width="100%";
  3657. loadingTextInput.style.margin="0";
  3658. loadingTextInput.spellcheck=false;
  3659. loadingText.appendChild(loadingTextInput);
  3660. otherBtns.appendChild(loadingText);
  3661.  
  3662. let opacity=document.createElement("div");
  3663. let opacityTitle=document.createElement("h2");
  3664. opacityTitle.style.whiteSpace="nowrap";
  3665. opacityTitle.style.overflow="visible";
  3666. opacityTitle.innerHTML=i18n("opacity");
  3667. opacity.appendChild(opacityTitle);
  3668. let opacityInput=document.createElement("input");
  3669. opacityInput.value=rulesData.opacity*100;
  3670. opacityInput.type="number";
  3671. opacityInput.style.width="110px";
  3672. opacityInput.style.margin="0";
  3673. opacityInput.placeholder=i18n("opacityPlaceholder");
  3674. opacityInput.spellcheck=false;
  3675. opacity.appendChild(opacityInput);
  3676. otherBtns.appendChild(opacity);
  3677.  
  3678. let pageElementCss=document.createElement("div");
  3679. pageElementCss.style.marginBottom="30px";
  3680. let pageElementCssTitle=document.createElement("h2");
  3681. pageElementCssTitle.innerHTML=i18n("pageElementCss");
  3682. pageElementCss.appendChild(pageElementCssTitle);
  3683. let pageElementCssInput=document.createElement("input");
  3684. pageElementCssInput.value=rulesData.pageElementCss||'';
  3685. pageElementCssInput.style.width="100%";
  3686. pageElementCssInput.style.margin="0";
  3687. pageElementCssInput.placeholder="font-size: xx-large;";
  3688. pageElementCssInput.spellcheck=false;
  3689. pageElementCss.appendChild(pageElementCssInput);
  3690. configCon.insertBefore(pageElementCss, insertPos);
  3691.  
  3692. let customCss=document.createElement("div");
  3693. customCss.style.marginBottom="50px";
  3694. let customCssTitle=document.createElement("h2");
  3695. customCssTitle.innerHTML=i18n("customCss");
  3696. customCss.appendChild(customCssTitle);
  3697. let customCssInput=document.createElement("textarea");
  3698. customCssInput.value=rulesData.customCss||'';
  3699. customCssInput.style.width="100%";
  3700. customCssInput.style.margin="0";
  3701. customCssInput.placeholder=".pagetual{\n}";
  3702. customCssInput.spellcheck=false;
  3703. customCss.appendChild(customCssInput);
  3704. configCon.insertBefore(customCss, insertPos);
  3705.  
  3706. let configTable=document.createElement("table");
  3707. configTable.style.width="100%";
  3708. let configTbody=document.createElement("tbody");
  3709. configTbody.style.width="100%";
  3710. configTbody.style.display="inline-table";
  3711. configTable.appendChild(configTbody);
  3712. configCon.insertBefore(configTable, insertPos);
  3713. function createCheckbox(innerText, val, tag, parentCheck, otherType) {
  3714. if (typeof val == 'undefined') val = "";
  3715. let title=document.createElement(tag || "h3");
  3716. title.innerHTML = innerText;
  3717. title.style.overflowWrap = "normal";
  3718. let input = document.createElement("input");
  3719. if (otherType === 'key') {
  3720. input.type = 'text';
  3721. input.setAttribute('readOnly', 'readonly');
  3722. input.addEventListener("keydown", e => {
  3723. if (e.key === 'Escape' || e.key === 'Backspace') input.value = '';
  3724. else input.value = e.key;
  3725. e.stopPropagation();
  3726. e.preventDefault();
  3727. });
  3728. } else {
  3729. input.type = otherType || "checkbox";
  3730. }
  3731. input.style.width = "30px";
  3732. input.style.height = "20px";
  3733. input.style.float = "left";
  3734. input.style.margin = "5px";
  3735. input.value = val;
  3736. input.checked = val;
  3737. let td = document.createElement("td");
  3738. td.appendChild(input);
  3739. if (parentCheck) {
  3740. title.style.margin = "0";
  3741. td.appendChild(title);
  3742. let parent = parentCheck.parentNode.nextElementSibling;
  3743. let tr = parent.querySelector("tr");
  3744. if (!tr) {
  3745. tr = document.createElement("tr");
  3746. parent.appendChild(tr);
  3747. }
  3748. tr.appendChild(td);
  3749. if (!parentCheck.checked) {
  3750. td.style.display = "none";
  3751. }
  3752. parentCheck.addEventListener("click", e => {
  3753. td.style.display = parentCheck.checked ? "" : "none";
  3754. });
  3755. } else {
  3756. let tr = document.createElement("tr");
  3757. tr.appendChild(td);
  3758. td = document.createElement("td");
  3759. td.appendChild(title);
  3760. tr.appendChild(td);
  3761. configTable.children[0].appendChild(tr);
  3762. }
  3763. return input;
  3764. }
  3765.  
  3766. let enableWhiteListInput=createCheckbox(i18n("autoRun"), rulesData.enableWhiteList!=true);
  3767. let enableDebugInput=createCheckbox(i18n("enableDebug"), rulesData.enableDebug!=false);
  3768. let enableHistoryInput=createCheckbox(i18n("enableHistory"), rulesData.enableHistory===true);
  3769. let enableHistoryAfterInsertInput=createCheckbox(i18n("enableHistoryAfterInsert"), rulesData.enableHistoryAfterInsert===true);
  3770. let openInNewTabInput=createCheckbox(i18n("openInNewTab"), rulesData.openInNewTab!=false);
  3771. let hideLoadingIconInput=createCheckbox(i18n("hideLoadingIcon"), rulesData.hideLoadingIcon!=false);
  3772. let initRunInput=createCheckbox(i18n("initRun"), rulesData.initRun!=false);
  3773. let autoLoadNumInput=createCheckbox(i18n("autoLoadNum"), rulesData.autoLoadNum, "h4", initRunInput, "number");
  3774. let preloadInput=createCheckbox(i18n("preload"), rulesData.preload!=false);
  3775. let rateInput=createCheckbox(i18n("turnRate"), rulesData.rate, "h4", preloadInput, "number");
  3776. let dbClick2StopInput=createCheckbox(i18n("dbClick2Stop"), rulesData.dbClick2Stop);
  3777. let manualModeInput=createCheckbox(i18n("manualMode"), rulesData.manualMode);
  3778. let clickModeInput=createCheckbox(i18n("clickMode"), rulesData.clickMode);
  3779. let pageBarMenuInput=createCheckbox(i18n("pageBarMenu"), rulesData.pageBarMenu);
  3780. let arrowToScrollInput=createCheckbox(i18n("arrowToScroll"), rulesData.arrowToScroll);
  3781. let sideControllerInput=createCheckbox(i18n("sideController"), rulesData.sideController);
  3782.  
  3783. let hideBarInput = createCheckbox(i18n("hideBar"), rulesData.hideBar && !rulesData.hideBarButNoStop, "h4", dbClick2StopInput, 'radio');
  3784. hideBarInput.name = 'hideBar';
  3785. let hideBarButNoStopInput = createCheckbox(i18n("hideBarButNoStop"), rulesData.hideBarButNoStop, "h4", dbClick2StopInput, 'radio');
  3786. hideBarButNoStopInput.name = 'hideBar';
  3787. hideBarInput.addEventListener('mouseup', e => {
  3788. if (hideBarInput.checked) {
  3789. setTimeout(() => {hideBarInput.checked = false}, 0);
  3790. }
  3791. });
  3792. hideBarButNoStopInput.addEventListener('mouseup', e => {
  3793. if (hideBarButNoStopInput.checked) {
  3794. setTimeout(() => {hideBarButNoStopInput.checked = false}, 0);
  3795. }
  3796. });
  3797.  
  3798. let dbClick2StopCtrlInput=createCheckbox(i18n("dbClick2StopCtrl"), rulesData.dbClick2StopCtrl, "h4", dbClick2StopInput);
  3799. let dbClick2StopAltInput=createCheckbox(i18n("dbClick2StopAlt"), rulesData.dbClick2StopAlt, "h4", dbClick2StopInput);
  3800. let dbClick2StopShiftInput=createCheckbox(i18n("dbClick2StopShift"), rulesData.dbClick2StopShift, "h4", dbClick2StopInput);
  3801. let dbClick2StopMetaInput=createCheckbox(i18n("dbClick2StopMeta"), rulesData.dbClick2StopMeta, "h4", dbClick2StopInput);
  3802. let dbClick2StopKeyInput=createCheckbox(i18n("dbClick2StopKey"), rulesData.dbClick2StopKey, "h4", dbClick2StopInput, "key");
  3803.  
  3804. let customRulesTitle=document.createElement("h2");
  3805. customRulesTitle.innerHTML=i18n("customRules");
  3806. configCon.insertBefore(customRulesTitle, insertPos);
  3807. let customRulesInput=document.createElement("textarea");
  3808. customRulesInput.spellcheck=false;
  3809. configCon.insertBefore(customRulesInput, insertPos);
  3810. if(rulesData.editTemp){
  3811. if(!ruleParser.customRules){
  3812. ruleParser.customRules=[];
  3813. }
  3814. for(let i in ruleParser.customRules){
  3815. if(ruleParser.customRules[i].url==rulesData.editTemp.url){
  3816. ruleParser.customRules.splice(i, 1);
  3817. break;
  3818. }
  3819. }
  3820. ruleParser.customRules.unshift(rulesData.editTemp);
  3821. rulesData.editTemp=null;
  3822. storage.setItem("rulesData", rulesData);
  3823. customRulesInput.previousElementSibling.scrollIntoView();
  3824. }
  3825. customRulesInput.style.width="100%";
  3826. customRulesInput.style.height="800px";
  3827. 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]`;
  3828. customRulesInput.value=getFormatJSON(ruleParser.customRules);
  3829. let blacklistInput=document.createElement("textarea");
  3830. blacklistInput.style.width="100%";
  3831. blacklistInput.style.height="500px";
  3832. blacklistInput.style.display="none";
  3833. blacklistInput.spellcheck=false;
  3834. blacklistInput.placeholder="http://*.xxx.com/*/y";
  3835. blacklistInput.value=rulesData.blacklist?rulesData.blacklist.join("\n"):"";
  3836. let blacklistBtn=document.createElement("button");
  3837. blacklistBtn.innerText=i18n("editBlacklist");
  3838. blacklistBtn.style.width="100%";
  3839. blacklistBtn.onclick=e=>{
  3840. blacklistInput.style.display=blacklistInput.style.display=="none"?"":"none";
  3841. };
  3842. configCon.insertBefore(blacklistBtn, insertPos);
  3843. configCon.insertBefore(blacklistInput, insertPos);
  3844. let saveBtn=document.createElement("button");
  3845. saveBtn.innerHTML=i18n("save");
  3846. saveBtn.style.width="100%";
  3847. saveBtn.style.position="fixed";
  3848. saveBtn.style.zIndex="999";
  3849. saveBtn.style.bottom=0;
  3850. saveBtn.style.left=0;
  3851. saveBtn.style.fontSize="x-large";
  3852. configCon.insertBefore(saveBtn, insertPos);
  3853. saveBtn.onclick=e=>{
  3854. try{
  3855. storage.setItem("hpRules", []);
  3856. storage.setItem("smartRules", []);
  3857. if(customRulesInput.value==""){
  3858. storage.setItem("customRules", "");
  3859. }else{
  3860. let customRules=JSON.parse(customRulesInput.value);
  3861. if(Array && Array.isArray && !Array.isArray(customRules)){
  3862. showTips("Rules must be a Array!");
  3863. return;
  3864. }
  3865. debug(customRules);
  3866. storage.setItem("customRules", customRules);
  3867. customRulesInput.value=JSON.stringify(customRules, null, 4);
  3868. }
  3869. }catch(e){
  3870. debug(e);
  3871. showTips("JSON error, check again!");
  3872. return;
  3873. }
  3874. rulesData.opacity = opacityInput.value / 100;
  3875. rulesData.blacklist = blacklistInput.value ? blacklistInput.value.split("\n") : "";
  3876. rulesData.hideBar = hideBarInput.checked;
  3877. rulesData.hideBarButNoStop = hideBarButNoStopInput.checked;
  3878. rulesData.dbClick2Stop = dbClick2StopInput.checked;
  3879. rulesData.enableWhiteList = !enableWhiteListInput.checked;
  3880. rulesData.enableDebug = enableDebugInput.checked;
  3881. rulesData.enableHistory = enableHistoryInput.checked;
  3882. rulesData.enableHistoryAfterInsert = enableHistoryAfterInsertInput.checked;
  3883. rulesData.openInNewTab = openInNewTabInput.checked;
  3884. rulesData.hideLoadingIcon = hideLoadingIconInput.checked;
  3885. rulesData.initRun = initRunInput.checked;
  3886. rulesData.autoLoadNum = autoLoadNumInput.value !== "0" ? autoLoadNumInput.value : '';
  3887. rulesData.rate = rateInput.value;
  3888. rulesData.preload = preloadInput.checked;
  3889. rulesData.manualMode = manualModeInput.checked;
  3890. rulesData.clickMode = clickModeInput.checked;
  3891. rulesData.pageBarMenu = pageBarMenuInput.checked;
  3892. rulesData.arrowToScroll = arrowToScrollInput.checked;
  3893. if (rulesData.sideController != sideControllerInput.checked) {
  3894. rulesData.sideControllerPos = false;
  3895. }
  3896. rulesData.sideController = sideControllerInput.checked;
  3897. rulesData.pageElementCss = pageElementCssInput.value;
  3898. rulesData.customCss = customCssInput.value;
  3899. rulesData.upBtnImg = upBtnImgInput.value;
  3900. rulesData.downBtnImg = downBtnImgInput.value;
  3901. rulesData.loadingText = loadingTextInput.value;
  3902. rulesData.dbClick2StopCtrl = dbClick2StopCtrlInput.checked;
  3903. rulesData.dbClick2StopAlt = dbClick2StopAltInput.checked;
  3904. rulesData.dbClick2StopShift = dbClick2StopShiftInput.checked;
  3905. rulesData.dbClick2StopMeta = dbClick2StopMetaInput.checked;
  3906. rulesData.dbClick2StopKey = dbClick2StopKeyInput.value;
  3907. storage.setItem("rulesData", rulesData);
  3908. let customUrls = customUrlsInput.value.trim();
  3909. if (customUrls) {
  3910. customUrls = customUrls.split(/\n/);
  3911. for (let c = 0; c < customUrls.length; c++) {
  3912. let url;
  3913. if(/^0\s*\|/.test(customUrls[c])){
  3914. url=customUrls[c].replace(/^0\s*\|\s*/, "").trim();
  3915. if(!/^http/.test(url)){
  3916. showTips("Wrong url, check again!");
  3917. return;
  3918. }
  3919. }else{
  3920. url=customUrls[c].trim();
  3921. if(!/^http/.test(url)){
  3922. showTips("Wrong url, check again!");
  3923. return;
  3924. }
  3925. }
  3926. let maxId=1,hasUrl=false;
  3927. if(!rulesData.urls){
  3928. rulesData.urls=[];
  3929. }
  3930. ruleUrls.forEach(u=>{
  3931. if(maxId<u.id){
  3932. maxId=u.id;
  3933. }
  3934. if(u.url==url){
  3935. hasUrl=true;
  3936. }
  3937. });
  3938. if(hasUrl)break;
  3939. if(!rulesData.sort)rulesData.sort=[1];
  3940. rulesData.urls.push({id:maxId+1,url:url});
  3941. rulesData.sort.push(maxId+1);
  3942. storage.setItem("rulesData", rulesData);
  3943. }
  3944. }
  3945. showTips("The settings are saved, refresh to view");
  3946. //location.reload();
  3947. };
  3948. return true;
  3949. }
  3950.  
  3951. var inUpdate=false;
  3952. function updateRules(success,fail){
  3953. if(inUpdate)return;
  3954. inUpdate=true;
  3955. let ruleIndex=ruleUrls.length-1;
  3956. storage.setItem("hpRules", []);
  3957. storage.setItem("smartRules", []);
  3958. function addNextRule(){
  3959. if(ruleIndex<0){
  3960. let now=new Date().getTime();
  3961. storage.setItem("ruleLastUpdate", now);
  3962. storage.setItem("rules", ruleParser.rules);
  3963. inUpdate=false;
  3964. success();
  3965. }else{
  3966. let rule=ruleUrls[ruleIndex--];
  3967. ruleParser.addRuleByUrl(rule.url, rule.id, (json,err)=>{
  3968. if(!json){
  3969. fail(rule,err);
  3970. }
  3971. addNextRule();
  3972. })
  3973. }
  3974. }
  3975. addNextRule();
  3976. }
  3977.  
  3978. function objIsArr(obj) {
  3979. return obj &&
  3980. typeof obj === 'object' &&
  3981. typeof obj.length === 'number' &&
  3982. !(obj.propertyIsEnumerable('length'));
  3983. }
  3984.  
  3985. function isVisible(el, win) {
  3986. if(!el || !el.offsetParent)return false;
  3987. var loopable = true,
  3988. visible = el.tagName && win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  3989. while(loopable && visible) {
  3990. el = el.parentNode;
  3991.  
  3992. if(el && el.tagName && el.tagName!="BODY") {
  3993. visible = win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  3994. }else {
  3995. loopable = false;
  3996. }
  3997. }
  3998. return visible;
  3999. }
  4000.  
  4001. function getElementTop(ele) {
  4002. if (!ele) return 0;
  4003. var actualTop = ele.offsetTop;
  4004. var current = ele.offsetParent;
  4005. while (current) {
  4006. actualTop += current.offsetTop;
  4007. current = current.offsetParent;
  4008. }
  4009. return actualTop;
  4010. }
  4011.  
  4012. function getElementBottom(ele) {
  4013. return getElementTop(ele) + ele.offsetHeight;
  4014. }
  4015.  
  4016. function getFormatJSON(obj){
  4017. if(!objIsArr(obj) || obj.length === 0)return "";
  4018. return JSON.stringify(obj, null, 4);
  4019. let ret="[\n";
  4020. let len=obj.length,i=0,isLast;
  4021. obj.forEach(item=>{
  4022. ret+=" {\n";
  4023. let iLen=Object.keys(item).length,j=0;
  4024. for(let key in item){
  4025. isLast=(++j)==iLen;
  4026. let value=item[key];
  4027. if(objIsArr(value)){
  4028. let vstr="[",v=0,vIsLast=false;
  4029. value.forEach(vi=>{
  4030. vIsLast=(++v)==value.length;
  4031. vstr+="\""+vi.replace(/\\/g,"\\\\")+"\""+(vIsLast?"":",");
  4032. });
  4033. vstr+="]";
  4034. ret+=" \""+key+"\":"+vstr+""+(isLast?"":",")+"\n";
  4035. }else{
  4036. if(typeof value=="string"){
  4037. value=value.replace(/\\/g,"\\\\").replace(/"/g,"\\\"");
  4038. value="\""+value+"\"";
  4039. }
  4040. ret+=" \""+key+"\":"+value+""+(isLast?"":",")+"\n";
  4041. }
  4042. }
  4043. isLast=(++i)==len;
  4044. ret+=" }"+(isLast?"":",")+"\n";
  4045. });
  4046. ret+="]";
  4047. return ret;
  4048. }
  4049.  
  4050. function globMatch(first, second) {
  4051. if (first.length == 0 && second.length == 0){
  4052. return true;
  4053. }
  4054.  
  4055. if (first.length > 1 && first[0] == '*' &&
  4056. second.length == 0){
  4057. return false;
  4058. }
  4059.  
  4060. if ((first.length > 1 && first[0] == '?') ||
  4061. (first.length != 0 && second.length != 0 &&
  4062. first[0] == second[0])){
  4063. return globMatch(first.substring(1),
  4064. second.substring(1));
  4065. }
  4066.  
  4067. if (first.length > 0 && first[0] == '*'){
  4068. return globMatch(first.substring(1), second) ||
  4069. globMatch(first, second.substring(1));
  4070. }
  4071.  
  4072. return false;
  4073. }
  4074.  
  4075. function initRules(callback) {
  4076. /*0 wedata格式,1 pagetual格式*/
  4077. ruleUrls=[
  4078. {
  4079. id:1,
  4080. url:'http://wedata.net/databases/AutoPagerize/items_all.json',
  4081. type:0,
  4082. }
  4083. ];var i=0,j=0;
  4084.  
  4085. ruleParser.initSavedRules(()=>{
  4086. storage.getItem("rulesData", data=>{
  4087. if(data){
  4088. rulesData=data;
  4089. if(data.urls)ruleUrls=ruleUrls.concat(data.urls);
  4090. if(data.sort){
  4091. let urls=[];
  4092. data.sort.forEach(id=>{
  4093. for(let s=0;s<ruleUrls.length;s++){
  4094. if(id==ruleUrls[s].id){
  4095. urls.push(ruleUrls[s]);
  4096. break;
  4097. }
  4098. }
  4099. });
  4100. ruleUrls=urls;
  4101. }
  4102. }
  4103. let upBtnImg=rulesData.upBtnImg,downBtnImg=rulesData.downBtnImg;
  4104. if(upBtnImg && downBtnImg){
  4105. downSvgCSS=downSvgCSS.replace("transform: rotate(180deg);","");
  4106. }else if(upBtnImg && !downBtnImg){
  4107. downBtnImg=upBtnImg;
  4108. }else if(downBtnImg && !upBtnImg){
  4109. upBtnImg=downBtnImg;
  4110. }
  4111. if(upBtnImg){
  4112. upSvg=`<img class="pagetual" src="${upBtnImg}"/>`;
  4113. }
  4114. if(downBtnImg){
  4115. downSvg=`<img class="pagetual" src="${downBtnImg}"/>`;
  4116. }
  4117. setLoadingDiv(rulesData.loadingText || i18n("loadingText"));
  4118. if(typeof(rulesData.opacity)=="undefined"){
  4119. rulesData.opacity=0.3;
  4120. }
  4121. if(typeof(rulesData.hideBar)=="undefined"){
  4122. rulesData.hideBar=false;
  4123. }
  4124. if(typeof(rulesData.dbClick2Stop)=="undefined"){
  4125. rulesData.dbClick2Stop=true;
  4126. }
  4127. if(typeof(rulesData.enableWhiteList)=="undefined"){
  4128. rulesData.enableWhiteList=false;
  4129. }
  4130. if(typeof(rulesData.enableHistory)=="undefined"){
  4131. rulesData.enableHistory=false;
  4132. }
  4133. if(typeof(rulesData.openInNewTab)=="undefined"){
  4134. rulesData.openInNewTab=true;
  4135. }
  4136. if(typeof(rulesData.enableDebug)=="undefined"){
  4137. rulesData.enableDebug=true;
  4138. }
  4139. if(typeof(rulesData.initRun)=="undefined"){
  4140. rulesData.initRun=true;
  4141. }
  4142. if(typeof(rulesData.preload)=="undefined"){
  4143. rulesData.preload=true;
  4144. }
  4145. if(typeof(rulesData.manualMode)=="undefined"){
  4146. rulesData.manualMode=false;
  4147. }
  4148. if(typeof(rulesData.clickMode)=="undefined"){
  4149. rulesData.clickMode=false;
  4150. }
  4151. if(typeof(rulesData.pageBarMenu)=="undefined"){
  4152. rulesData.pageBarMenu=false;
  4153. }
  4154. if(typeof(rulesData.arrowToScroll)=="undefined"){
  4155. rulesData.arrowToScroll=false;
  4156. }
  4157. if(typeof(rulesData.hideLoadingIcon)=="undefined"){
  4158. rulesData.hideLoadingIcon=false;
  4159. }
  4160. if(rulesData.blacklist && rulesData.blacklist.length>0){
  4161. for(let b in rulesData.blacklist){
  4162. let curGlob=rulesData.blacklist[b];
  4163. if(globMatch(curGlob, location.href)){
  4164. return;
  4165. }
  4166. }
  4167. }
  4168. if(rulesData.autoLoadNum){
  4169. autoLoadNum=parseInt(rulesData.autoLoadNum);
  4170. }
  4171. enableDebug=rulesData.enableDebug;
  4172. storage.getItem("nextSwitch_"+location.host, i=>{
  4173. storage.getItem("forceState_"+location.host, v=>{
  4174. storage.getItem("ruleLastUpdate", date=>{
  4175. if(typeof(i)!=="undefined"){
  4176. nextIndex=i;
  4177. }
  4178. if(typeof(v)=="undefined"){
  4179. v=(rulesData.enableWhiteList?1:0);
  4180. }
  4181. forceState=v;
  4182. updateDate=date;
  4183. if(initConfig())return;
  4184. if(forceState==1)return;
  4185. let now=new Date().getTime();
  4186. if(!date || now-date>2*24*60*60*1000){
  4187. updateRules(()=>{
  4188. },(rule,err)=>{});
  4189. storage.setItem("ruleLastUpdate", now);
  4190. }
  4191. callback();
  4192. });
  4193. });
  4194. });
  4195. });
  4196. });
  4197. }
  4198.  
  4199. function requestDoc(url, callback){
  4200. let postParams = url.match(/#p{(.*)}$/);
  4201. if (postParams) {
  4202. postParams = postParams[1];
  4203. url = url.replace(/#p{.*/, "");
  4204. }
  4205. _GM_xmlhttpRequest({
  4206. url: url,
  4207. method: postParams ? 'POST' : 'GET',
  4208. data: postParams,
  4209. overrideMimeType: 'text/html;charset=' + (document.characterSet || document.charset || document.inputEncoding),
  4210. headers: {
  4211. 'Referer': location.href,
  4212. 'User-Agent': navigator.userAgent,
  4213. "Content-Type": (postParams ? "application/x-www-form-urlencoded" : "text/html") + ";charset=" + (document.characterSet || document.charset || document.inputEncoding),
  4214. },
  4215. timeout: 20000,
  4216. onload: function(res) {
  4217. var doc=null,response=res.response;
  4218. let preCode=ruleParser.curSiteRule.pageElementPre || ruleParser.curSiteRule.pagePre;
  4219. if(preCode){
  4220. try{
  4221. if (typeof _unsafeWindow.pagetualPagePre!='undefined') {
  4222. response = _unsafeWindow.pagetualPagePre(response);
  4223. } else if (preCode.length == 2) {
  4224. response = response.replace(new RegExp(preCode[0], "gi"), preCode[1]);
  4225. } else {
  4226. response = Function("response",'"use strict";' + preCode)(response);
  4227. }
  4228. }catch(e){
  4229. debug(e);
  4230. }
  4231. }
  4232. try {
  4233. doc=document.implementation.createHTMLDocument('');
  4234. doc.documentElement.innerHTML=response;
  4235. let base=doc.querySelector("base");
  4236. ruleParser.basePath=base?base.href:url;
  4237. }
  4238. catch (e) {
  4239. debug('parse error'+e.toString());
  4240. }
  4241. let pageElement=ruleParser.getPageElement(doc);
  4242. if(inCors && (!pageElement || pageElement.length==0)){
  4243. ruleParser.curSiteRule.pageElement=allOfBody;
  4244. pageElement=ruleParser.getPageElement(doc);
  4245. ruleParser.getInsert(true);
  4246. }
  4247. //只有1的話怕不是圖片哦
  4248. if(pageElement && (pageElement.length>1 || (pageElement.length==1 && pageElement[0].tagName!="IMG") )){
  4249. ruleParser.insertPage(doc, pageElement, url, callback, false);
  4250. if(ruleParser.curSiteRule.action==1){
  4251. requestFromIframe(url, (doc, eles)=>{
  4252. loadPageOver();
  4253. if(eles){
  4254. ruleParser.insertPage(doc, eles, url, callback, true);
  4255. }
  4256. });
  4257. }else ruleParser.curSiteRule.action=0;
  4258. }else if(ruleParser.curSiteRule.singleUrl || curPage==1){
  4259. ruleParser.curSiteRule.action=1;
  4260. requestFromIframe(url, (doc, eles)=>{
  4261. loadPageOver();
  4262. if(eles){
  4263. ruleParser.insertPage(doc, eles, url, callback, true);
  4264. }
  4265. });
  4266. }else{
  4267. debug("Stop as no page element");
  4268. isPause=true;
  4269. callback(false);
  4270. }
  4271. },
  4272. onerror: function(e){
  4273. debug(e, "NetError");
  4274. callback(false);
  4275. },
  4276. ontimeout: function(e){
  4277. debug(e, "NetTimeout");
  4278. callback(false);
  4279. }
  4280. });
  4281. }
  4282.  
  4283. function initPage(){
  4284. ruleParser.initPage(()=>{
  4285. if(ruleParser.curSiteRule.autoLoadNum){
  4286. autoLoadNum=ruleParser.curSiteRule.autoLoadNum;
  4287. }
  4288. if(ruleParser.curSiteRule.nextLink && Array && Array.isArray && Array.isArray(ruleParser.curSiteRule.nextLink)){
  4289. _GM_registerMenuCommand(i18n("nextSwitch"), ()=>{
  4290. NextSwitch.getInstance().start();
  4291. });
  4292. }
  4293. if(ruleParser.nextLinkHref){
  4294. let isJs=/^(javascript|#)/.test(ruleParser.nextLinkHref.replace(location.href,""));
  4295. if(!isJs){
  4296. let inForce=(forceState == 2 || forceState == 3);
  4297. _GM_registerMenuCommand(i18n(inForce?"cancelForceIframe":"forceIframe"), ()=>{
  4298. if(inForce){
  4299. storage.setItem("forceState_"+location.host, "");
  4300. }else{
  4301. let _state=ruleParser.curSiteRule.action>0 || confirm(i18n("forceAllBody"))?2:3;
  4302. storage.setItem("forceState_"+location.host, _state);
  4303. }
  4304. location.reload();
  4305. });
  4306. }
  4307. _GM_registerMenuCommand(i18n("loadNow"), ()=>{
  4308. let loadNum=window.prompt(i18n("loadConfirm"), "1");
  4309. if(loadNum==="" || loadNum===null)return;
  4310. autoLoadNum=Math.abs(parseInt(loadNum));
  4311. nextPage();
  4312. });
  4313. }
  4314. initListener();
  4315. let initRun = typeof ruleParser.curSiteRule.initRun == 'undefined' ? rulesData.initRun : ruleParser.curSiteRule.initRun;
  4316. if (initRun && initRun != 0 && initRun != '0') nextPage();
  4317. });
  4318. }
  4319.  
  4320. var pageBarStyle;
  4321. function initView(){
  4322. _GM_addStyle(`
  4323. .pagetual_pageBar{
  4324. -moz-transition:opacity 0.3s ease-in-out 0s;
  4325. -webkit-transition:opacity 0.3s ease-in-out 0s;
  4326. transition:opacity 0.3s ease-in-out 0s;
  4327. font-family: Arial,sans-serif !important;
  4328. }
  4329. .pagetual_pageBar.stop {
  4330. -webkit-filter: invert(100%);
  4331. filter: invert(100%);
  4332. opacity: 1!important;
  4333. }
  4334. .pagetual_pageBar.hide {
  4335. display: none!important;
  4336. }
  4337. .pagetual_pageBar:hover {
  4338. opacity: 1!important;
  4339. }
  4340. .pagetual_pageBar span {
  4341. vertical-align: super;
  4342. }
  4343. .pagetual_pageBar a::before,
  4344. .pagetual_pageBar a::after {
  4345. content: none;
  4346. }
  4347. .pagetual_pageBar a>span {
  4348. margin-top: 0!important;
  4349. pointer-events: none;
  4350. padding: unset;
  4351. opacity: 0;
  4352. -moz-transition:all 0.3s ease-in-out 0s;
  4353. -webkit-transition:all 0.3s ease-in-out 0s;
  4354. transition:all 0.3s ease-in-out 0s;
  4355. }
  4356. .pagetual_pageBar a>span:hover {
  4357. color: red;
  4358. }
  4359. .pagetual_pageBar a:hover>span {
  4360. opacity: 1;
  4361. }
  4362. .pagetual_pageBar span.prevScreen,
  4363. .pagetual_pageBar span.nextScreen {
  4364. display: block!important;
  4365. }
  4366. .pagetual_pageBar a:hover>span.prevScreen {
  4367. margin-top: -30px!important;
  4368. pointer-events: all;
  4369. }
  4370. .pagetual_pageBar a:hover>span.nextScreen {
  4371. margin-top: 30px!important;
  4372. pointer-events: all;
  4373. }
  4374. .pagetual_pageBar span>svg {
  4375. -moz-transition:transform 0.5s ease, opacity 0.3s ease;
  4376. -webkit-transition:transform 0.5s ease, opacity 0.3s ease;
  4377. transition:transform 0.5 ease, opacity 0.3s ease;
  4378. opacity: 0;
  4379. }
  4380. .pagetual_pageBar:hover span>svg {
  4381. opacity: 1;
  4382. }
  4383. .pagetual_pageBar span>svg.upSvg:hover {
  4384. transform: rotate(360deg) scale3d(1.2, 1.2, 1.2);
  4385. }
  4386. .pagetual_pageBar span>svg.downSvg:hover {
  4387. transform: rotate(540deg) scale3d(1.2, 1.2, 1.2)!important;
  4388. }
  4389. .pagetual_pageBar .pagetual_pageNum{
  4390. color: #55555f;
  4391. }
  4392. .pagetual_pageBar .pagetual_pageNum:hover{
  4393. color: #ff6464;
  4394. }
  4395. .pagetual_tipsWords{
  4396. font-size: 50px;
  4397. font-weight: bold;
  4398. font-family: "黑体", -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto",
  4399. "Oxygen", "Ubuntu", "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji",
  4400. "Segoe UI Emoji", "Segoe UI Symbol";
  4401. color: #ffffff;
  4402. min-height: 70px;
  4403. max-width: 80%;
  4404. line-height: 70px;
  4405. position: fixed;
  4406. left: 50%;
  4407. top: 10%;
  4408. margin-left: -99999px;
  4409. padding: 0 15px;
  4410. z-index: 999999999;
  4411. background-color: #000;
  4412. border: 1px solid #303030;
  4413. border-radius: 10px;
  4414. opacity: 0;
  4415. filter: alpha(opacity=65);
  4416. box-shadow: 5px 5px 20px 0px #000;
  4417. -moz-transition:opacity 0.3s ease-in-out 0s;
  4418. -webkit-transition:opacity 0.3s ease-in-out 0s;
  4419. transition:opacity 0.3s ease-in-out 0s;
  4420. pointer-events: none;
  4421. }
  4422. .pagetual_loading {
  4423. width: 50px;
  4424. height: 50px;
  4425. margin: 10px auto;
  4426. border-radius: 100%;
  4427. display: flex;
  4428. -webkit-animation: pagetual_loading_scaleout 1.0s infinite ease-in-out;
  4429. animation: pagetual_loading_scaleout 1.0s infinite ease-in-out;
  4430. }
  4431. @-webkit-keyframes pagetual_loading_scaleout {
  4432. 0% { -webkit-transform: scale(0.0) }
  4433. 100% {
  4434. -webkit-transform: scale(1.0);
  4435. opacity: 0;
  4436. }
  4437. }
  4438. @keyframes pagetual_loading_scaleout {
  4439. 0% {
  4440. transform: scale(0.0);
  4441. -webkit-transform: scale(0.0);
  4442. } 100% {
  4443. transform: scale(1.0);
  4444. -webkit-transform: scale(1.0);
  4445. opacity: 0;
  4446. }
  4447. }
  4448. .pagetual_loading_text {
  4449. white-space: nowrap;
  4450. -webkit-animation: pagetual_loading_opacity 2.6s infinite ease-in-out;
  4451. animation: pagetual_loading_opacity 2.6s infinite ease-in-out;
  4452. }
  4453. @-webkit-keyframes pagetual_loading_opacity {
  4454. 0% { opacity: 1 }
  4455. 50% { opacity: 0.2 }
  4456. 100% { opacity: 1 }
  4457. }
  4458. @keyframes pagetual_loading_opacity {
  4459. 0% { opacity: 1 }
  4460. 50% { opacity: 0.2 }
  4461. 100% { opacity: 1 }
  4462. }
  4463. `);
  4464. pageBarStyle=`text-indent: initial;vertical-align: super;line-height:1;opacity:${rulesData.opacity};display:${rulesData.opacity==0?"none":"inline-flex"};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!important;justify-content: center;`;
  4465. }
  4466. var loadingDiv=document.createElement("div");
  4467. loadingDiv.style.cssText="text-indent: initial;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;";
  4468.  
  4469. const 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; flex: 0;`;
  4470. function setLoadingDiv(loadingText){
  4471. loadingDiv.innerHTML=`<p class="pagetual_loading_text" style="${loadingCSS}display: inline-block;">${loadingText}</p>${rulesData.hideLoadingIcon ? "" : `<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"><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"></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"></path></svg></div>`}`;
  4472. }
  4473.  
  4474. var upSvg=`<svg width="30" height="30" class="upSvg pagetual" style="display:initial;position:relative;cursor: pointer;margin: 0 8px;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"><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"></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"></path></svg>`;
  4475. var upSvgCSS=`display:initial;position:relative;cursor: pointer;margin: 0 8px;width: 30px;height: 30px;vertical-align: middle;fill: currentColor;overflow: hidden;`;
  4476. var downSvg=`<svg width="30" height="30" class="downSvg pagetual" style="display:initial;position:relative;cursor: pointer;margin: 0 8px;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"><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"></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"></path></svg>`;
  4477. var downSvgCSS=`display:initial;position:relative;cursor: pointer;margin: 0 8px;width: 30px;height: 30px;vertical-align: middle;fill: currentColor;overflow: hidden;transform: rotate(180deg);`;
  4478.  
  4479. const initStyle=`text-indent: initial;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 5px;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;`;
  4480. const pageTextStyle=`text-indent: initial;padding: unset;border: none;background: unset!important;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;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;`;
  4481.  
  4482. var tipsWords=document.createElement("div");
  4483. tipsWords.className="pagetual_tipsWords";
  4484.  
  4485. var isPause = false, isHideBar = false, isLoading = false, curPage = 1, forceState = 0, bottomGap = 1000, autoLoadNum = -1, nextIndex = 0, stopScroll = false;
  4486.  
  4487. function changeStop(stop) {
  4488. isPause = stop;
  4489. [].forEach.call(document.querySelectorAll(".pagetual_pageBar,#pagetual-sideController"), bar => {
  4490. if (isPause) {
  4491. bar.classList.add("stop");
  4492. } else {
  4493. bar.classList.remove("stop");
  4494. }
  4495. });
  4496. }
  4497.  
  4498. function changeHideBar(hide) {
  4499. isHideBar = hide;
  4500. [].forEach.call(document.querySelectorAll(".pagetual_pageBar"), bar => {
  4501. if (isHideBar) {
  4502. bar.classList.add("hide");
  4503. } else {
  4504. bar.classList.remove("hide");
  4505. }
  4506. });
  4507. }
  4508.  
  4509. function isInViewPort(element) {
  4510. if(!document.body.contains(element))return false;
  4511. if(_unsafeWindow.getComputedStyle(element).display=="none")return false;
  4512. const viewWidth = window.innerWidth || document.documentElement.clientWidth;
  4513. const viewHeight = window.innerHeight || document.documentElement.clientHeight;
  4514. const {
  4515. top,
  4516. right,
  4517. bottom,
  4518. left,
  4519. } = element.getBoundingClientRect();
  4520.  
  4521. return (
  4522. top >= 0 &&
  4523. left >= 0 &&
  4524. right <= viewWidth + 1 &&
  4525. bottom <= viewHeight * 2
  4526. );
  4527. }
  4528.  
  4529. function getPageBar() {
  4530. let preBar = null, nextBar = null;
  4531. let pageBars = [].slice.call(document.querySelectorAll(".pagetual_pageBar"));
  4532. for (let i = 0; i < pageBars.length; i++) {
  4533. let pageBar = pageBars[i];
  4534. if (!pageBar || !document.body.contains(pageBar)) continue;
  4535. let {
  4536. top,
  4537. right,
  4538. bottom,
  4539. left,
  4540. } = pageBar.getBoundingClientRect();
  4541. if (top > 500) {
  4542. nextBar = pageBar;
  4543. preBar = (i - 1 >= 0 ? pageBars[i - 1] : null);
  4544. if (pageBar && document.body.contains(pageBar)) {
  4545. let {
  4546. top,
  4547. right,
  4548. bottom,
  4549. left,
  4550. } = pageBar.getBoundingClientRect();
  4551. if (top < -500) {
  4552. preBar = pageBar;
  4553. } else preBar = (i - 2 >= 0 ? pageBars[i - 2] : null);
  4554. }
  4555. break;
  4556. }
  4557. }
  4558. if (!nextBar) preBar = pageBars[pageBars.length - 2];
  4559. return {preBar: preBar, nextBar: nextBar};
  4560. }
  4561.  
  4562. var urlChanged=false;
  4563. var _wr = function(type) {
  4564. var orig = history[type];
  4565. return function() {
  4566. var rv = orig.apply(this, arguments);
  4567. var e = new Event(type);
  4568. e.arguments = arguments;
  4569. window.dispatchEvent(e);
  4570. return rv;
  4571. };
  4572. };
  4573. var changeHandler = e => {
  4574. urlChanged = true;
  4575. isPause = true;
  4576. setTimeout(() => {
  4577. lastActiveUrl = location.href;
  4578. if (guidePage.test(location.href)) {
  4579. setTimeout(() => {
  4580. if(typeof JSONEditor !== 'undefined'){
  4581. createEdit();
  4582. }else{
  4583. window.onload = e => {
  4584. createEdit();
  4585. }
  4586. }
  4587. }, 500);
  4588. } else if (location.href == configPage[0]) {
  4589. location.reload();
  4590. } else if (!ruleParser.ruleMatch(ruleParser.curSiteRule)) {
  4591. initPage();
  4592. }
  4593. if (!ruleParser.nextLinkHref) isLoading = false;
  4594. },1);
  4595. };
  4596. history.pushState = _wr('pushState');
  4597. window.addEventListener('pushState', changeHandler);
  4598.  
  4599. function initListener(){
  4600. let loadmoreBtn,loading=true,lastScroll=0,checkLoadMoreTimes=0;
  4601. if (ruleParser.curSiteRule.loadMore) {
  4602. loading=false;
  4603. } else {
  4604. let checkLoadMore=setInterval(()=>{
  4605. loadmoreBtn=getLoadMore(document);
  4606. if(loadmoreBtn && isVisible(loadmoreBtn, _unsafeWindow)){
  4607. loading=false;
  4608. clearInterval(checkLoadMore);
  4609. }else if(checkLoadMoreTimes++>30){
  4610. clearInterval(checkLoadMore);
  4611. }
  4612. },300);
  4613. }
  4614. let clickMode = typeof ruleParser.curSiteRule.clickMode == 'undefined' ? rulesData.clickMode : ruleParser.curSiteRule.clickMode;
  4615. let clickNext = async () => {
  4616. let nextLink = ruleParser.nextLinkHref;
  4617. if (!nextLink) return;
  4618. let isJs = /^(javascript|#)/.test(nextLink.replace(location.href, ""));
  4619. if (isJs) {
  4620. let nextBtn = await ruleParser.getNextLink(document);
  4621. if (nextBtn) emuClick(nextBtn);
  4622. } else {
  4623. window.location.href = nextLink;
  4624. }
  4625. };
  4626. let checkScrollReach=()=>{
  4627. let scrolly=window.scrollY;
  4628. let windowHeight=window.innerHeight || document.documentElement.clientHeight;
  4629. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  4630. if(clickMode){
  4631. if(scrollH-scrolly-windowHeight<10){
  4632. clickNext();
  4633. }
  4634. }else if(scrollH-scrolly-windowHeight<bottomGap){
  4635. nextPage();
  4636. }
  4637. };
  4638. let scrollHandler = e=>{
  4639. if(urlChanged && !isLoading){
  4640. ruleParser.initPage(()=>{
  4641. if(ruleParser.nextLinkHref){
  4642. initView();
  4643. }
  4644. isPause=false;
  4645. });
  4646. urlChanged=false;
  4647. }
  4648. if(isPause)return;
  4649. if(!loading){
  4650. if(ruleParser.curSiteRule.loadMore || !loadmoreBtn || !document.body.contains(loadmoreBtn)){
  4651. loadmoreBtn=getLoadMore(document);
  4652. }
  4653. if(loadmoreBtn){
  4654. if(isInViewPort(loadmoreBtn)){
  4655. emuClick(loadmoreBtn);
  4656. loading=true;
  4657. setTimeout(()=>{loading=false},200);
  4658. }
  4659. }else{
  4660. loading=true;
  4661. setTimeout(()=>{loading=false},200);
  4662. }
  4663. }
  4664. if(!isLoading && !stopScroll){
  4665. checkScrollReach();
  4666. }
  4667. if(ruleParser.curSiteRule.lockScroll){
  4668. let curScroll=document.body.scrollTop||document.documentElement.scrollTop;
  4669. if(isLoading && Math.abs(lastScroll-curScroll)>350){
  4670. document.body.scrollTop=lastScroll;
  4671. document.documentElement.scrollTop=lastScroll;
  4672. }else{
  4673. lastScroll=curScroll;
  4674. }
  4675. }
  4676. };
  4677. document.addEventListener('dblclick', e=>{
  4678. if(forceState==1 || e.target.tagName=='INPUT' || e.target.tagName=='TEXTAREA') return;
  4679. if(!rulesData.dbClick2StopKey){
  4680. if((rulesData.dbClick2StopCtrl && !e.ctrlKey) ||
  4681. (rulesData.dbClick2StopAlt && !e.altKey) ||
  4682. (rulesData.dbClick2StopShift && !e.shiftKey) ||
  4683. (rulesData.dbClick2StopMeta && !e.metaKey)){
  4684. return;
  4685. }
  4686. }
  4687. if(e.target.tagName !== "BODY" && e.target.className !== 'pagetual_pageBar'){
  4688. let selStr=document.getSelection().toString();
  4689. if(selStr && selStr.trim()){
  4690. return;
  4691. }
  4692. }
  4693. if(rulesData.dbClick2Stop && (ruleParser.nextLinkHref || loadmoreBtn)){
  4694. setTimeout(()=>{
  4695. if (rulesData.hideBarButNoStop || rulesData.hideBar) {
  4696. changeHideBar(!isHideBar);
  4697. }
  4698. if (!rulesData.hideBarButNoStop) {
  4699. changeStop(!isPause);
  4700. showTips(i18n(isPause?"disable":"enable"));
  4701. }
  4702. if(!isPause){
  4703. checkScrollReach();
  4704. }
  4705. },10);
  4706. }
  4707. });
  4708. if(rulesData.dbClick2StopKey){
  4709. document.addEventListener('keydown', e=>{
  4710. if((rulesData.dbClick2StopCtrl && !e.ctrlKey) ||
  4711. (rulesData.dbClick2StopAlt && !e.altKey) ||
  4712. (rulesData.dbClick2StopShift && !e.shiftKey) ||
  4713. (rulesData.dbClick2StopMeta && !e.metaKey)){
  4714. return;
  4715. }
  4716. if (document.activeElement &&
  4717. (document.activeElement.tagName == 'INPUT' ||
  4718. document.activeElement.tagName == 'TEXTAREA')) {
  4719. return;
  4720. }
  4721. var key = e.key.toLowerCase();
  4722. if(rulesData.dbClick2StopKey.toLowerCase()==key){
  4723. forceState=(forceState==1?0:1);
  4724. showTips(i18n(forceState==1?"disableSiteTips":"enableSiteTips"));
  4725. if(!ruleParser.curSiteRule.url) {
  4726. storage.setItem("forceState_"+location.host, forceState);
  4727. location.reload();
  4728. }
  4729. }
  4730. });
  4731. }
  4732. if (ruleParser.curSiteRule.listenHashChange) {
  4733. window.addEventListener('hashchange', () => {
  4734. urlChanged = true;
  4735. isPause = true;
  4736. if (!ruleParser.nextLinkHref) isLoading = false;
  4737. }, false);
  4738. }
  4739. let manualMode = typeof ruleParser.curSiteRule.manualMode == 'undefined' ? rulesData.manualMode : ruleParser.curSiteRule.manualMode;
  4740. if (manualMode) {
  4741. document.addEventListener('keydown', e => {
  4742. if (document.activeElement &&
  4743. (document.activeElement.tagName == 'INPUT' ||
  4744. document.activeElement.tagName == 'TEXTAREA' ||
  4745. document.activeElement.contentEditable == 'true')) {
  4746. return;
  4747. }
  4748. if(e.keyCode == 39){
  4749. clickNext();
  4750. }
  4751. });
  4752. document.addEventListener('pagetual.next', function() {
  4753. clickNext();
  4754. }, false);
  4755. return;
  4756. }
  4757. if (rulesData.arrowToScroll) {
  4758. document.addEventListener('keyup', e => {
  4759. if (document.activeElement &&
  4760. (document.activeElement.tagName == 'INPUT' ||
  4761. document.activeElement.tagName == 'TEXTAREA' ||
  4762. document.activeElement.contentEditable == 'true')) {
  4763. return;
  4764. }
  4765. if (e.keyCode == 39) {
  4766. let nextPageBar=getPageBar().nextBar;
  4767. if (nextPageBar) {
  4768. scrollToPageBar(nextPageBar);
  4769. } else {
  4770. let scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
  4771. window.scrollTo({ top: scrollTop + (window.innerHeight || document.documentElement.clientHeight), behavior: 'smooth'});
  4772. }
  4773. } else if (e.keyCode == 37) {
  4774. let prePageBar = getPageBar().preBar;
  4775. if (prePageBar) {
  4776. scrollToPageBar(prePageBar);
  4777. } else {
  4778. let scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
  4779. window.scrollTo({ top: scrollTop - (window.innerHeight || document.documentElement.clientHeight), behavior: 'smooth'});
  4780. }
  4781. }
  4782. });
  4783. }
  4784. if (!ruleParser.curSiteRule.wheel) {
  4785. document.addEventListener('scroll', scrollHandler, true);
  4786. }
  4787. document.addEventListener('wheel', scrollHandler, true);
  4788. }
  4789.  
  4790. function showTips(content, wordColor, backColor){
  4791. document.body.appendChild(tipsWords);
  4792. tipsWords.style.opacity=0.8;
  4793. tipsWords.innerText=content;
  4794. tipsWords.style.marginLeft=-tipsWords.offsetWidth/2+"px";
  4795. tipsWords.style.color=wordColor||0xFFFFFF;
  4796. tipsWords.style.backgroundColor=backColor||0x000;
  4797. setTimeout(()=>{tipsWords.style.opacity=0},1000);
  4798. }
  4799.  
  4800. function getLoadMore(doc) {
  4801. if (ruleParser.curSiteRule.loadMore === "") return null;
  4802. let btnSel = ruleParser.curSiteRule.loadMore || ".LoadMore,.load-more,.button-show-more,button[data-testid='more-results-button']", loadmoreBtn;
  4803. if (btnSel) {
  4804. loadmoreBtn = getElement(btnSel, doc);
  4805. }
  4806. if (!loadmoreBtn) {
  4807. let buttons = doc.querySelectorAll("input,button,a,div[onclick]"), loadmoreReg = /^\s*(加载更多|加載更多|load\s*more|もっと読み込む)\s*$/i;
  4808. for (let i = 0; i < buttons.length; i++) {
  4809. let button = buttons[i];
  4810. if (button.innerText.length > 20) continue;
  4811. if (button && loadmoreReg.test(button.innerText)) {
  4812. loadmoreBtn = button;
  4813. break;
  4814. }
  4815. }
  4816. }
  4817. if (loadmoreBtn && !ruleParser.curSiteRule.loadMore && loadmoreBtn.dataset.ajax !== "true") {
  4818. let href = loadmoreBtn.getAttribute("href");
  4819. if (href && href != "/" && !/^(javascript|#)/.test(href.replace(location.href,""))) {
  4820. loadmoreBtn = null;
  4821. }
  4822. }
  4823. return loadmoreBtn;
  4824. }
  4825.  
  4826. function scrollToPageBar(bar){
  4827. let yOffset = -20;
  4828. if (typeof ruleParser.curSiteRule.pageBarTop !== 'undefined') {
  4829. yOffset = -ruleParser.curSiteRule.pageBarTop;
  4830. }
  4831. const y = bar.getBoundingClientRect().top + window.pageYOffset + yOffset;
  4832. window.scrollTo({ top: y, behavior: 'smooth'});
  4833. }
  4834.  
  4835. const pageNumReg=/[&\/\?](p=|page[=\/_-]?)\d+|[_-]\d+\./;
  4836. function createPageBar(url) {
  4837. SideController.setup();
  4838. url = url.replace(/#p{.*/, "");
  4839. if (rulesData.opacity == 0 || ruleParser.curSiteRule.pageBar === 0) return null;
  4840. let insert=ruleParser.getInsert();
  4841. if(!insert || !insert.parentNode)return;
  4842. curPage++;
  4843. let example=ruleParser.curSiteRule.insertPos==2?insert.children[0]:(insert.parentNode.children[parseInt(insert.parentNode.children.length/2)]||insert);
  4844. if (example.className=="pagetual_pageBar") {
  4845. example=example.previousElementSibling;
  4846. }
  4847. if(!example || !example.parentNode)example=insert;
  4848. let exampleStyle = _unsafeWindow.getComputedStyle(example);
  4849. let inTable, inLi;
  4850. if (forceState == 2) {
  4851. inTable = inLi = false;
  4852. } else {
  4853. inTable=example.parentNode.tagName=="TABLE" ||
  4854. example.parentNode.tagName=="TBODY" ||
  4855. example.tagName=="TR" ||
  4856. example.tagName=="TBODY" ||
  4857. exampleStyle.display=="table-row" ||
  4858. (example.previousElementSibling && example.previousElementSibling.tagName=="TR") ||
  4859. (example.previousElementSibling && example.previousElementSibling.tagName=="TBODY");
  4860. inLi=example.tagName=="LI" || (example.previousElementSibling && example.previousElementSibling.tagName=="LI");
  4861. }
  4862. let pageBar=document.createElement(inTable?"tr":(inLi?"li":"div"));
  4863. let upSpan=document.createElement("span");
  4864. let downSpan=document.createElement("span");
  4865. let pageText=document.createElement("a");
  4866. let pageNum;
  4867. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  4868. pageBar.className=isHideBar?"pagetual_pageBar hide":"pagetual_pageBar";
  4869. pageBar.id="pagetual_pageBar"+curPage;
  4870. pageBar.setAttribute("translate", "no");
  4871. if(isPause){
  4872. pageBar.classList.add("stop");
  4873. }
  4874. pageBar.style.cssText=pageBarStyle;
  4875. pageBar.title=i18n(isPause?"enable":"disable");
  4876. upSpan.innerHTML=upSvg;
  4877. upSpan.children[0].style.cssText=upSvgCSS;
  4878. upSpan.title=i18n("toTop");
  4879. downSpan.innerHTML=downSvg;
  4880. downSpan.children[0].style.cssText=downSvgCSS;
  4881. downSpan.title=i18n("toBottom");
  4882. upSpan.style.cssText=initStyle;
  4883. downSpan.style.cssText=initStyle;
  4884. pageText.href=url;
  4885. pageText.style.cssText=pageTextStyle;
  4886. pageText.title=i18n("current");
  4887. if(rulesData.openInNewTab)pageText.target="_blank";
  4888. pageBar.appendChild(upSpan);
  4889. pageBar.appendChild(pageText);
  4890. if(rulesData.pageBarMenu){
  4891. pageText.addEventListener("click", e=>{
  4892. e.stopPropagation();
  4893. if (e.ctrlKey || e.altKey || e.shiftKey || e.metaKey) return;
  4894. e.preventDefault();
  4895. Picker.getInstance().start();
  4896. });
  4897. }
  4898. let touched = false;
  4899. let touchBodyHandler = e => {
  4900. touched = false;
  4901. document.body.removeEventListener('touchstart', touchBodyHandler);
  4902. };
  4903. pageText.addEventListener("touchstart", e => {
  4904. if (touched) return;
  4905. touched = true;
  4906. pageText.style.pointerEvents = 'none';
  4907. setTimeout(() => {
  4908. pageText.style.pointerEvents = 'all';
  4909. }, 250);
  4910. document.body.addEventListener("touchstart", touchBodyHandler);
  4911. });
  4912. if(ruleParser.nextTitle){
  4913. pageText.innerHTML=ruleParser.nextTitle+" ";
  4914. pageText.title=ruleParser.nextTitle;
  4915. }
  4916. if(ruleParser.curSiteRule.pageNum || pageNumReg.test(url)){
  4917. pageText.innerHTML+="Page ";
  4918. pageNum=document.createElement("span");
  4919. pageNum.innerHTML=ruleParser.getPageNumFromUrl(url);
  4920. pageNum.className="pagetual_pageNum";
  4921. pageNum.title=i18n("inputPageNum");
  4922. pageNum.style.cssText=pageTextStyle;
  4923. pageNum.style.cursor="pointer";
  4924. pageNum.style.color="";
  4925. pageNum.style.marginLeft="5px";
  4926. pageNum.addEventListener("click", e=>{
  4927. let pageInput=prompt(i18n("inputPageNum"), "1");
  4928. if(pageInput){
  4929. let pageLink=ruleParser.getLinkByPage(url, pageInput);
  4930. if(pageLink){
  4931. _GM_openInTab(pageLink,{active:true});
  4932. }
  4933. }
  4934. e.preventDefault();
  4935. e.stopPropagation();
  4936. });
  4937. pageBar.appendChild(pageNum);
  4938. }else{
  4939. pageText.innerHTML+="Page "+curPage;
  4940. }
  4941. let preBtn=document.createElement("span");
  4942. preBtn.innerHTML="∧";
  4943. preBtn.title="Prev page";
  4944. preBtn.className="prevScreen";
  4945. preBtn.style.cssText="display: none;text-align: center;right: unset; float: left; margin-top: -30px; width: 40px; background: rgba(240, 240, 240, 0.8); position: absolute; border-radius: 20px 20px 0 0; box-shadow: rgb(0 0 0 / 50%) 0px -5px 5px;z-index:9999999";
  4946. let nextBtn=document.createElement("span");
  4947. nextBtn.innerHTML="∨";
  4948. nextBtn.title="Next page";
  4949. nextBtn.className="nextScreen";
  4950. nextBtn.style.cssText="display: none;text-align: center;right: unset; float: left; margin-top: 30px; width: 40px; background: rgba(240, 240, 240, 0.8); position: absolute; border-radius: 0 0 20px 20px; box-shadow: rgb(0 0 0 / 50%) 0px 5px 5px;z-index:9999999";
  4951. let localPage=curPage;
  4952. preBtn.addEventListener("click", e=>{
  4953. e.stopPropagation();
  4954. e.preventDefault();
  4955. let prePageBar = document.querySelector("#pagetual_pageBar"+(localPage-1));
  4956. if (prePageBar) {
  4957. scrollToPageBar(prePageBar);
  4958. } else {
  4959. let scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
  4960. window.scrollTo({ top: scrollTop - (window.innerHeight || document.documentElement.clientHeight), behavior: 'smooth'});
  4961. }
  4962. });
  4963. nextBtn.addEventListener("click", e=>{
  4964. e.stopPropagation();
  4965. e.preventDefault();
  4966. let nextPageBar=document.querySelector("#pagetual_pageBar"+(localPage+1));
  4967. if (nextPageBar) {
  4968. scrollToPageBar(nextPageBar);
  4969. } else {
  4970. let nextEle = pageBar.parentNode.children[pageBar.parentNode.children.length - 1];
  4971. if (nextEle) scrollToPageBar(nextEle);
  4972. else {
  4973. scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  4974. window.scrollTo({ top: scrollH || 9999999, behavior: 'smooth'});
  4975. }
  4976. }
  4977. });
  4978. pageText.insertBefore(preBtn, pageText.firstChild);
  4979. pageText.insertBefore(nextBtn, pageText.firstChild);
  4980. pageBar.appendChild(downSpan);
  4981. if (forceState == 2) {
  4982. pageBar.style.width = "99%";
  4983. } else {
  4984. let parentStyle=_unsafeWindow.getComputedStyle(example.parentNode);
  4985. let parentWidth=example.parentNode.offsetWidth||parseInt(parentStyle.width);
  4986. pageBar.style.width=parentWidth-parseInt(parentStyle.paddingLeft)-parseInt(parentStyle.paddingRight)-10+"px";
  4987. pageBar.style.margin='10px 5px';
  4988. if(parentStyle.display=="grid" || parentStyle.display=="inline-grid"){
  4989. pageBar.style.gridColumnStart=1;
  4990. pageBar.style.gridColumnEnd=1+parseInt(example.parentNode.offsetWidth/example.offsetWidth);
  4991. }
  4992. if(inTable){
  4993. example=(example.tagName=="TR" || example.tagName=="TBODY")?example:example.previousElementSibling;
  4994. if(example.tagName=="TBODY")example=example.querySelector("tr");
  4995. let preTr=example;
  4996. while(preTr && preTr.children.length==0)preTr=preTr.previousElementSibling;
  4997. if(preTr)example=preTr;
  4998. let tdNum=0;
  4999. if (exampleStyle.display=="table-row") {
  5000. [].forEach.call(example.children, el=>{
  5001. tdNum+=el.colSpan||1;
  5002. });
  5003. } else {
  5004. [].forEach.call(example.children, el=>{
  5005. if(el.tagName=="TD" || el.tagName=="TH"){
  5006. tdNum+=el.colSpan||1;
  5007. }
  5008. });
  5009. }
  5010. pageBar.style.display="table-row";
  5011. pageBar.style.backgroundColor="unset";
  5012. pageBar.style.lineHeight="20px";
  5013. pageBar.style.boxShadow="";
  5014. pageBar.style.height="35px";
  5015. let td=document.createElement("td");
  5016. td.colSpan=tdNum||1;
  5017. let inTd=document.createElement("div");
  5018. inTd.style.backgroundColor="rgb(240 240 240 / 80%)";
  5019. inTd.style.borderRadius="20px";
  5020. inTd.style.padding="0 0";
  5021. inTd.style.margin="0";
  5022. inTd.style.lineHeight="20px";
  5023. inTd.style.textAlign="center";
  5024. inTd.style.boxShadow="rgb(0 0 0 / 67%) 0px 0px 10px 0px";
  5025. inTd.appendChild(upSpan);
  5026. inTd.appendChild(pageText);
  5027. if(pageNum)inTd.appendChild(pageNum);
  5028. inTd.appendChild(downSpan);
  5029. td.appendChild(inTd);
  5030. pageBar.appendChild(td);
  5031. }else if(inLi){
  5032. example=example.tagName=="LI"?example:example.previousElementSibling;
  5033. pageBar.style.display=getComputedStyle(example).display;
  5034. pageBar.style.backgroundColor="unset";
  5035. pageBar.style.lineHeight="20px";
  5036. pageBar.style.boxShadow="";
  5037. pageBar.style.height="35px";
  5038. let td=document.createElement("td");
  5039. td.colSpan=example.children.length;
  5040. td.style.width='100%';
  5041. let inTd=document.createElement("div");
  5042. inTd.style.backgroundColor="rgb(240 240 240 / 80%)";
  5043. inTd.style.borderRadius="20px";
  5044. inTd.style.margin="0"
  5045. inTd.style.padding="0 0";
  5046. inTd.style.textAlign="center";
  5047. inTd.style.minWidth="150px";
  5048. inTd.appendChild(upSpan);
  5049. inTd.appendChild(pageText);
  5050. inTd.style.width='calc(100% - 20px)';
  5051. inTd.style.boxShadow="rgb(0 0 0 / 67%) 0px 0px 10px 0px";
  5052. if(pageNum)inTd.appendChild(pageNum);
  5053. inTd.appendChild(downSpan);
  5054. if (pageBar.style.display === 'table-row') {
  5055. td.appendChild(inTd);
  5056. pageBar.appendChild(td);
  5057. } else {
  5058. inTd.style.width='100%';
  5059. pageBar.appendChild(inTd);
  5060. }
  5061. }
  5062. }
  5063.  
  5064. upSpan.addEventListener("click", e=>{
  5065. document.body.scrollTop=0;
  5066. document.documentElement.scrollTop=0;
  5067. e.preventDefault();
  5068. e.stopPropagation();
  5069. });
  5070. downSpan.addEventListener("click", e=>{
  5071. changeStop(true);
  5072. pageBar.title = i18n(isPause ? "enable" : "disable");
  5073. scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  5074. document.body.scrollTop = scrollH || 9999999;
  5075. document.documentElement.scrollTop = scrollH || 9999999;
  5076. e.preventDefault();
  5077. e.stopPropagation();
  5078. });
  5079. pageBar.addEventListener("click", e=>{
  5080. changeStop(!isPause);
  5081. pageBar.title=i18n(isPause?"enable":"disable");
  5082. });
  5083. ruleParser.insertElement(pageBar);
  5084. if(ruleParser.curSiteRule.pageBar && ruleParser.curSiteRule.pageBar !== 0){
  5085. try{
  5086. ((typeof _unsafeWindow.pagetualPageBar=='undefined') ? Function("pageBar",'"use strict";' + ruleParser.curSiteRule.pageBar) : _unsafeWindow.pagetualPageBar)(pageBar);
  5087. }catch(e){
  5088. debug(e);
  5089. }
  5090. }
  5091.  
  5092. let posEle=pageBar.nextElementSibling||pageBar;
  5093. while(posEle && !posEle.offsetParent){
  5094. posEle=posEle.previousElementSibling||posEle.parentNode;
  5095. }
  5096. if(posEle){
  5097. let actualTop = getElementTop(posEle);
  5098. bottomGap=scrollH-actualTop+(window.innerHeight||document.documentElement.clientHeight)*(ruleParser.curSiteRule.rate||rulesData.rate||1);
  5099. if(bottomGap<100)bottomGap=100;
  5100. }else{
  5101. bottomGap=1000;
  5102. }
  5103. return pageBar;
  5104. }
  5105.  
  5106. function emuClick(btn){
  5107. let orgHref=btn.getAttribute('href');
  5108. if(orgHref && orgHref != "#"){
  5109. btn.setAttribute('href', orgHref.replace(/#$/,""));
  5110. }
  5111. if(!PointerEvent)return btn.click();
  5112. let eventParam={
  5113. isTrusted: true,
  5114. altKey: false,
  5115. azimuthAngle: 0,
  5116. bubbles: true,
  5117. button: 0,
  5118. buttons: 0,
  5119. clientX: 1,
  5120. clientY: 1,
  5121. cancelBubble: false,
  5122. cancelable: true,
  5123. composed: true,
  5124. ctrlKey: false,
  5125. defaultPrevented: false,
  5126. detail: 1,
  5127. eventPhase: 2,
  5128. fromElement: null,
  5129. height: 1,
  5130. isPrimary: false,
  5131. metaKey: false,
  5132. pointerId: 1,
  5133. pointerType: "mouse",
  5134. pressure: 0,
  5135. relatedTarget: null,
  5136. returnValue: true,
  5137. shiftKey: false,
  5138. toElement: null,
  5139. twist: 0,
  5140. which: 1
  5141. };
  5142. let mouseEvent = new PointerEvent("mousedown",eventParam);
  5143. btn.dispatchEvent(mouseEvent);
  5144. mouseEvent = new PointerEvent("mouseup",eventParam);
  5145. btn.dispatchEvent(mouseEvent);
  5146. let dispatchTouchEvent = (ele, type) => {
  5147. let touchEvent;
  5148. try {
  5149. touchEvent = document.createEvent('TouchEvent')
  5150. touchEvent.initTouchEvent(type, true, true)
  5151. } catch (err) {
  5152. try {
  5153. touchEvent = document.createEvent('UIEvent')
  5154. touchEvent.initUIEvent(type, true, true)
  5155. } catch (err) {
  5156. touchEvent = document.createEvent('Event')
  5157. touchEvent.initEvent(type, true, true)
  5158. }
  5159. }
  5160. touchEvent.targetTouches = [{
  5161. pageX: 1,
  5162. pageY: 1,
  5163. clientX: 1,
  5164. clientY: 1,
  5165. target: btn
  5166. }];
  5167. touchEvent.touches = [{
  5168. pageX: 1,
  5169. pageY: 1,
  5170. clientX: 1,
  5171. clientY: 1,
  5172. target: btn
  5173. }];
  5174. touchEvent.changedTouches = [{
  5175. pageX: 1,
  5176. pageY: 1,
  5177. clientX: 1,
  5178. clientY: 1,
  5179. target: btn
  5180. }];
  5181. ele.dispatchEvent(touchEvent);
  5182. }
  5183. dispatchTouchEvent(btn, "touchstart");
  5184. dispatchTouchEvent(btn, "touchend");
  5185.  
  5186. btn.click();
  5187. if(orgHref && orgHref != "#"){
  5188. setTimeout(()=>btn.setAttribute('href', orgHref),0);
  5189. }
  5190. }
  5191.  
  5192. var failFromIframe=0;
  5193. var inCors=false;
  5194. var checkRemoveIntv;
  5195. function requestFromIframe(url, callback){
  5196. url = url.indexOf('=') == -1 ? url.replace(/#[^#]*/,"") : url;
  5197. let iframe = document.createElement('iframe');
  5198. iframe.name = 'pagetual-iframe';
  5199. iframe.width = '100%';
  5200. iframe.height = '1000';
  5201. iframe.frameBorder = '0';
  5202. if(ruleParser.curSiteRule.sandbox!=false){
  5203. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  5204. }
  5205. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;flex:0;opacity:0!important;pointer-events:none!important;position:fixed;top:0px;left:0px;z-index:-2147483647;';
  5206. let waitTime=100,checkEval;
  5207. if(ruleParser.curSiteRule.waitElement){
  5208. checkEval = doc => {
  5209. return ruleParser.waitElement(doc);
  5210. };
  5211. }else if(ruleParser.curSiteRule.wait){
  5212. if(isNaN(ruleParser.curSiteRule.wait)){
  5213. try{
  5214. checkEval=(typeof _unsafeWindow.pagetualWait=='undefined') ? Function("doc",'"use strict";' + ruleParser.curSiteRule.wait) : _unsafeWindow.pagetualWait;
  5215. }catch(e){
  5216. debug(e);
  5217. }
  5218. }else{
  5219. waitTime=ruleParser.curSiteRule.wait;
  5220. }
  5221. }
  5222. if (checkRemoveIntv) clearInterval(checkRemoveIntv);
  5223. checkRemoveIntv = setInterval(() => {
  5224. if (!iframe || !document.body.contains(iframe)) {
  5225. clearInterval(checkRemoveIntv);
  5226. loadPageOver();
  5227. }
  5228. }, 500);
  5229. let loadedHandler = e => {
  5230. if(e.data != 'pagetual-iframe:DOMLoaded' && e.type != 'load')return;
  5231. clearInterval(checkRemoveIntv);
  5232. window.removeEventListener('message', loadedHandler, false);
  5233. iframe.removeEventListener('load', loadedHandler, false);
  5234. let tryTimes=0;
  5235. function checkIframe(){
  5236. if (urlChanged || isPause) {
  5237. return callback(false, false);
  5238. }
  5239. try{
  5240. let doc=iframe.contentDocument || iframe.contentWindow.document;
  5241. let base=doc.querySelector("base");
  5242. ruleParser.basePath=base?base.href:url;
  5243. let eles=ruleParser.getPageElement(doc, iframe.contentWindow);
  5244. if(checkEval && !checkEval(doc)){
  5245. setTimeout(()=>{
  5246. checkIframe();
  5247. },waitTime);
  5248. return;
  5249. }else if(eles && eles.length>0){
  5250. callback(doc, eles);
  5251. }else if(tryTimes++ < 100){
  5252. setTimeout(()=>{
  5253. checkIframe();
  5254. },waitTime);
  5255. return;
  5256. }else{
  5257. if(failFromIframe++ > 2){
  5258. failFromIframe=0;
  5259. debug("Stop as failFromIframe");
  5260. isPause=true;
  5261. callback(false, false);
  5262. }else{
  5263. callback(false, false);
  5264. }
  5265. }
  5266. }catch(e){
  5267. debug("Stop as cors");
  5268. inCors=true;
  5269. if (forceState === 3) {
  5270. isPause=true;
  5271. }
  5272. if(!ruleParser.curSiteRule.pageElement){
  5273. ruleParser.curSiteRule.pageElement=allOfBody;
  5274. ruleParser.getInsert(true);
  5275. }
  5276. ruleParser.curSiteRule.action=0;
  5277. ruleParser.nextLinkHref=url;
  5278. callback(false, false);
  5279. nextPage();
  5280. }
  5281. document.body.removeChild(iframe);
  5282. }
  5283. setTimeout(()=>{
  5284. checkIframe();
  5285. },waitTime);
  5286. };
  5287. window.addEventListener('message', loadedHandler, false);
  5288. iframe.addEventListener('load', loadedHandler, false);
  5289. iframe.src=url;
  5290. document.body.appendChild(iframe);
  5291. }
  5292.  
  5293. var emuIframe,lastActiveUrl;
  5294. function emuPage(callback){
  5295. let orgPage=null,orgContent=null,preContent=null,iframeDoc,times=0,loadmoreBtn,pageEle,nextLink,loadmoreEnd=false,waitTimes=10,changed=false;
  5296. function returnFalse(log){
  5297. debug(log);
  5298. isPause=true;
  5299. callback(false, false);
  5300. if(emuIframe && emuIframe.parentNode){
  5301. emuIframe.parentNode.removeChild(emuIframe);
  5302. emuIframe=null;
  5303. }
  5304. }
  5305. async function checkPage(){
  5306. if(isPause)return loadPageOver();
  5307. try{
  5308. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  5309. }catch(e){
  5310. returnFalse("Stop as cors");
  5311. return;
  5312. }
  5313.  
  5314. let waitTime=200,checkEval;
  5315. if(ruleParser.curSiteRule.waitElement){
  5316. checkEval = doc => {
  5317. return ruleParser.waitElement(doc);
  5318. };
  5319. }else if(ruleParser.curSiteRule.wait){
  5320. if(isNaN(ruleParser.curSiteRule.wait)){
  5321. try{
  5322. checkEval=(typeof _unsafeWindow.pagetualWait=='undefined') ? Function("doc", '"use strict";' + ruleParser.curSiteRule.wait) : _unsafeWindow.pagetualWait;
  5323. }catch(e){
  5324. debug(e);
  5325. }
  5326. }else{
  5327. waitTime=ruleParser.curSiteRule.wait;
  5328. }
  5329. }
  5330.  
  5331. if(!orgPage){
  5332. if(!loadmoreEnd){
  5333. loadmoreBtn=getLoadMore(iframeDoc);
  5334. if(loadmoreBtn && isVisible(loadmoreBtn, iframeDoc.defaultView)){
  5335. emuClick(loadmoreBtn);
  5336. let intv=setInterval(()=>{
  5337. loadmoreBtn=getLoadMore(iframeDoc);
  5338. if(!loadmoreBtn || !document.body.contains(loadmoreBtn) || !isVisible(loadmoreBtn, iframeDoc.defaultView)){
  5339. clearInterval(intv);
  5340. loadmoreEnd=true;
  5341. setTimeout(()=>{
  5342. checkPage();
  5343. },500);
  5344. }else if(isInViewPort(loadmoreBtn)){
  5345. emuClick(loadmoreBtn);
  5346. }
  5347. },200);
  5348. return;
  5349. }else{
  5350. loadmoreEnd=true;
  5351. }
  5352. }
  5353. if(checkEval && !checkEval(iframeDoc)){
  5354. waitTimes=10;
  5355. setTimeout(()=>{
  5356. checkPage();
  5357. },waitTime);
  5358. return;
  5359. }else {
  5360. nextLink = await ruleParser.getNextLink(iframeDoc);
  5361. pageEle = ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true);
  5362. if (!pageEle || pageEle.length==0 || !nextLink) {
  5363. if (waitTimes-- > 0) {
  5364. setTimeout(() => {
  5365. checkPage();
  5366. }, waitTime);
  5367. return;
  5368. }
  5369. }
  5370. }
  5371. orgPage=pageEle;
  5372. if(!orgPage || orgPage.length==0){
  5373. returnFalse("Stop as no page when emu");
  5374. return;
  5375. }
  5376. if(orgPage[0].tagName=="UL")orgPage=orgPage[0].children;
  5377. if(nextLink){
  5378. orgPage=orgPage[parseInt(orgPage.length/2)];
  5379. if(orgPage.tagName=="IMG"){
  5380. if (!ruleParser.curSiteRule.lazyImgSrc) ruleParser.curSiteRule.lazyImgSrc = "0";
  5381. if (orgPage.src) {
  5382. orgContent = orgPage.src;
  5383. } else {
  5384. setTimeout(()=>{
  5385. checkPage();
  5386. },500);
  5387. return;
  5388. }
  5389. }else{
  5390. orgContent=orgPage.innerHTML;
  5391. }
  5392. preContent=orgContent;
  5393. if(!isVisible(nextLink, iframeDoc.defaultView)){
  5394. returnFalse("Stop as next hide when emu");
  5395. }else{
  5396. emuClick(nextLink);
  5397. setTimeout(()=>{
  5398. checkPage();
  5399. },500);
  5400. }
  5401. }else{
  5402. returnFalse("Stop as no next when emu");
  5403. }
  5404. return;
  5405. }
  5406. nextLink = nextLink || await ruleParser.getNextLink(iframeDoc);
  5407. if(!nextLink){
  5408. if(waitTimes-->0){
  5409. setTimeout(()=>{
  5410. checkPage();
  5411. },waitTime);
  5412. return;
  5413. }
  5414. }
  5415. if(times++ > 200){
  5416. returnFalse("Stop as timeout when emu");
  5417. return;
  5418. }
  5419. let eles=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true),checkItem;
  5420. if(eles && eles.length>0){
  5421. checkItem=eles;
  5422. if(eles[0].tagName=="UL")checkItem=eles[0].children;
  5423. checkItem=checkItem[parseInt(checkItem.length/2)];
  5424. }
  5425. if(!checkItem || (checkEval && !checkEval(iframeDoc))){
  5426. setTimeout(()=>{
  5427. checkPage();
  5428. },waitTime);
  5429. }else{
  5430. let checkInner;
  5431. if (checkItem.tagName == "IMG") {
  5432. if (checkItem.src) {
  5433. checkInner = checkItem.src;
  5434. } else {
  5435. setTimeout(() => {
  5436. checkPage();
  5437. }, waitTime);
  5438. return;
  5439. }
  5440. }else{
  5441. checkInner=checkItem.innerHTML;
  5442. }
  5443. if(orgPage!=checkItem || checkInner!=preContent){
  5444. changed=true;
  5445. orgPage=checkItem;
  5446. preContent=checkInner;
  5447. setTimeout(()=>{
  5448. checkPage();
  5449. },waitTime);
  5450. }else if(changed){
  5451. times = 0;
  5452. if (orgContent == preContent) {
  5453. returnFalse("Stop as same content");
  5454. } else {
  5455. callback(iframeDoc, eles);
  5456. }
  5457. }else{
  5458. if (times % 5 === 1) {
  5459. emuClick(nextLink);
  5460. }
  5461. setTimeout(()=>{
  5462. checkPage();
  5463. },waitTime);
  5464. }
  5465. }
  5466. }
  5467. if(!emuIframe){
  5468. let loaded=false;
  5469. emuIframe = document.createElement('iframe');
  5470. emuIframe.name = 'pagetual-iframe';
  5471. if(ruleParser.curSiteRule.sandbox!=false){
  5472. emuIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  5473. }
  5474. emuIframe.width = '100%';
  5475. emuIframe.height = '100';
  5476. emuIframe.frameBorder = '0';
  5477. emuIframe.style.cssText = 'margin:0!important;padding:0!important;flex:0;opacity:0!important;pointer-events:none!important;position:fixed;top:0px;left:0px;z-index:-2147483647;';
  5478. emuIframe.addEventListener("load", e => {
  5479. setTimeout(() => {
  5480. try {
  5481. iframeDoc = emuIframe.contentDocument || emuIframe.contentWindow.document;
  5482. } catch(e) {
  5483. returnFalse("Stop as cors");
  5484. return;
  5485. }
  5486. let code = ruleParser.curSiteRule.init;
  5487. if (code) {
  5488. try {
  5489. Function('doc','win','iframe','"use strict";' + code)(iframeDoc, iframeDoc.defaultView, emuIframe);
  5490. } catch(e) {
  5491. debug(e);
  5492. }
  5493. }
  5494. if (loaded) return;
  5495. loaded = true;
  5496. checkPage();
  5497. },500);
  5498. });
  5499. if (!lastActiveUrl) lastActiveUrl=location.href;
  5500. emuIframe.src = lastActiveUrl;
  5501. document.body.appendChild(emuIframe);
  5502. }else{
  5503. if (emuIframe.src != lastActiveUrl) emuIframe.src = lastActiveUrl;
  5504. checkPage();
  5505. }
  5506. }
  5507.  
  5508. var scrollToResizeInited = false;
  5509. var resizePool = [];
  5510. var scrollingToResize = false;
  5511.  
  5512. function scrollToResize(e) {
  5513. if (scrollingToResize) return;
  5514. else {
  5515. scrollingToResize = true;
  5516. let fitWidth = ruleParser.curSiteRule.fitWidth !== false;
  5517. let resizeHandler = () => {
  5518. resizePool.forEach(resizeArr => {
  5519. let iframe = resizeArr[1]();
  5520. let frameDoc = resizeArr[2]();
  5521. if(ruleParser.curSiteRule.singleUrl || forceState === 2){
  5522. iframe.style.height = (frameDoc.body.scrollHeight || frameDoc.body.offsetHeight) + "px";
  5523. iframe.style.minHeight = iframe.style.height;
  5524. iframe.style.width = "100%";
  5525. frameDoc.documentElement.scrollTop = 0;
  5526. frameDoc.documentElement.scrollLeft = 0;
  5527. }else{
  5528. let pageEle = resizeArr[0]();
  5529. if(pageEle){
  5530. let targetElement = pageEle[0];
  5531. if (!targetElement) return;
  5532. if(pageEle.length > 1){
  5533. targetElement = targetElement.parentNode;
  5534. }
  5535. let scrollHeight = targetElement.scrollHeight || targetElement.offsetHeight;
  5536. if(parseInt(iframe.style.height)==scrollHeight) return;
  5537. iframe.style.height=(scrollHeight+1)+"px";
  5538. let scrollTop = 0, scrollLeft = 0;
  5539. frameDoc.body.scrollTop = 0;
  5540. frameDoc.body.scrollLeft = 0;
  5541. while(targetElement && targetElement.offsetParent){
  5542. targetElement.offsetParent.scrollTop = targetElement.offsetTop;
  5543. if(targetElement.offsetParent.scrollTop == 0){
  5544. scrollTop += targetElement.offsetTop;
  5545. }
  5546. if(fitWidth){
  5547. targetElement.offsetParent.scrollLeft = targetElement.offsetLeft;
  5548. if(targetElement.offsetParent.scrollLeft == 0){
  5549. scrollLeft += targetElement.offsetLeft;
  5550. }
  5551. }
  5552. targetElement = targetElement.offsetParent;
  5553. }
  5554. frameDoc.documentElement.scrollTop = scrollTop;
  5555. frameDoc.documentElement.scrollLeft = scrollLeft;
  5556. if (frameDoc.documentElement.scrollTop == 0 && frameDoc.documentElement.scrollLeft == 0) {
  5557. frameDoc.body.scrollTop += scrollTop;
  5558. frameDoc.body.scrollLeft += scrollLeft;
  5559. }
  5560. if(!fitWidth && iframe.style.marginLeft == '0px'){
  5561. iframe.style.width = "100vw";
  5562. iframe.style.marginLeft = -iframe.getBoundingClientRect().left + "px";
  5563. }
  5564. }
  5565. }
  5566. });
  5567. };
  5568. setTimeout(() => {
  5569. scrollingToResize = false;
  5570. resizeHandler();
  5571. }, 200);
  5572. resizeHandler();
  5573. }
  5574. }
  5575.  
  5576. function forceIframe(url, callback){
  5577. url = url.indexOf('=') == -1 ? url.replace(/#[^#]*/,"") : url;
  5578. let curIframe = document.createElement('iframe'),iframeDoc,isloaded=false,inAction=true;
  5579. let loadedHandler = ()=>{
  5580. inAction=false;
  5581. if(isloaded)return;
  5582. isloaded=true;
  5583. ruleParser.insertPage(iframeDoc, [], url, null, true);
  5584. callback(curIframe, true);
  5585. let getIframe = () => {
  5586. return curIframe;
  5587. };
  5588. let getFrameDoc = () => {
  5589. return iframeDoc;
  5590. };
  5591. if(ruleParser.curSiteRule.singleUrl){
  5592. resizePool.push([() => {}, getIframe, getFrameDoc]);
  5593. }else{
  5594. let pageElement = ruleParser.getPageElement(iframeDoc,iframeDoc.defaultView);
  5595. let getPageEle = () => {
  5596. if (!pageElement || pageElement.length===0) {
  5597. pageElement = ruleParser.getPageElement(iframeDoc,iframeDoc.defaultView);
  5598. }
  5599. return pageElement;
  5600. };
  5601. resizePool.push([getPageEle, getIframe, getFrameDoc]);
  5602. }
  5603. scrollToResize();
  5604. };
  5605. curIframe.name = 'pagetual-iframe';
  5606. curIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  5607. curIframe.frameBorder = '0';
  5608. curIframe.scrolling="no";
  5609. curIframe.style.cssText = 'display: block; visibility: visible; float: none; clear: both; width: 100%; height: 0; background: initial; border: 0px; border-radius: 0px; margin: 0px; padding: 0px; z-index: 2147483647;';
  5610. curIframe.addEventListener("load", e=>{
  5611. try{
  5612. iframeDoc=curIframe.contentDocument || curIframe.contentWindow.document;
  5613. }catch(e){
  5614. debug("Stop as cors");
  5615. isPause=true;
  5616. callback(false, false);
  5617. return;
  5618. }
  5619. let css=ruleParser.curSiteRule.css || rulesData.customCss;
  5620. if(css){
  5621. css = css.replace(/^inIframe:/, "");
  5622. let styleEle=iframeDoc.createElement("style");
  5623. styleEle.innerHTML=css;
  5624. iframeDoc.head.appendChild(styleEle);
  5625. }
  5626. loadedHandler();
  5627. let code=ruleParser.curSiteRule.init;
  5628. if(code){
  5629. try{
  5630. Function('doc','win','iframe','"use strict";' + code)(iframeDoc,iframeDoc.defaultView,curIframe);
  5631. }catch(e){
  5632. debug(e);
  5633. }
  5634. }
  5635. });
  5636. let checkTimes=0,findPageEle=false;
  5637. let forceRefresh=e=>{
  5638. if(inAction || !iframeDoc)return;
  5639. inAction=true;
  5640. let foundNext=()=>{
  5641. document.removeEventListener("scroll", forceRefresh);
  5642. }
  5643. setTimeout(async () => {
  5644. inAction=false;
  5645. if(!ruleParser.nextLinkHref){
  5646. checkTimes++;
  5647. await ruleParser.getNextLink(iframeDoc);
  5648. if(ruleParser.nextLinkHref){
  5649. foundNext();
  5650. }else if(checkTimes>=10){
  5651. foundNext();
  5652. }else if(checkTimes>=3 && !findPageEle){
  5653. let pageElement = ruleParser.getPageElement(iframeDoc,iframeDoc.defaultView);
  5654. if(!pageElement){
  5655. inAction=true;
  5656. curIframe.contentWindow.location.reload();
  5657. }else{
  5658. findPageEle=true;
  5659. }
  5660. }
  5661. }else{
  5662. foundNext();
  5663. }
  5664. },50);
  5665. };
  5666. document.addEventListener("scroll", forceRefresh);
  5667. curIframe.src=url;
  5668. let insert=ruleParser.getInsert();
  5669. if(ruleParser.curSiteRule.singleUrl || forceState==2){
  5670. document.body.appendChild(loadingDiv);
  5671. document.body.appendChild(curIframe);
  5672. }else{
  5673. ruleParser.insertElement(curIframe);
  5674. }
  5675.  
  5676. if (!scrollToResizeInited) {
  5677. scrollToResizeInited = true;
  5678. document.addEventListener("scroll", scrollToResize);
  5679. }
  5680. return curIframe;
  5681. }
  5682.  
  5683. function loadPageOver(){
  5684. isLoading = false;
  5685. stopScroll = true;
  5686. setTimeout(() => {stopScroll = false}, 500);
  5687. if(loadingDiv.parentNode){
  5688. loadingDiv.parentNode.removeChild(loadingDiv);
  5689. }
  5690. }
  5691.  
  5692. var tryTimes = 0;
  5693.  
  5694. async function nextPage(){
  5695. if(typeof ruleParser.curSiteRule.manualMode=='undefined' ? rulesData.manualMode : ruleParser.curSiteRule.manualMode)return;
  5696. if(typeof ruleParser.curSiteRule.clickMode=='undefined' ? rulesData.clickMode : ruleParser.curSiteRule.clickMode)return;
  5697. if(isPause || isLoading || forceState==1)return;
  5698. if(ruleParser.curSiteRule.delay){
  5699. try{
  5700. let checkDelay=((typeof _unsafeWindow.pagetualDelay=='undefined') ? Function('"use strict";' + ruleParser.curSiteRule.delay) : _unsafeWindow.pagetualDelay)();
  5701. if(!checkDelay)return;
  5702. }catch(e){
  5703. debug(e);
  5704. }
  5705. }
  5706. if(ruleParser.curSiteRule.pageElementCss || ruleParser.curSiteRule.pageElementStyle || rulesData.pageElementCss){
  5707. ruleParser.getPageElement(document, _unsafeWindow);
  5708. }
  5709. let nextLink = ruleParser.nextLinkHref;
  5710. if (!nextLink) {
  5711. if (curPage == 1) {
  5712. await ruleParser.getNextLink(document);
  5713. nextLink = ruleParser.nextLinkHref;
  5714. }
  5715. if (!nextLink) {
  5716. isLoading = true;
  5717. if (curPage == 1 && (ruleParser.curSiteRule.pinUrl || tryTimes++ <= 10)) {
  5718. setTimeout(() => {isLoading = false}, 500);
  5719. }
  5720. return;
  5721. }
  5722. }
  5723. let pvGallery=document.querySelector("span.pv-gallery-container");
  5724. if(pvGallery && pvGallery.style.display!="none")return;
  5725. let insert=ruleParser.getInsert();
  5726. if (insert) {
  5727. if (curPage == 1) {
  5728. /*window.postMessage({
  5729. insert: geneSelector(ruleParser.curSiteRule.insertPos == 2 ? insert : insert.parentNode, true),
  5730. command: 'pagetual.insert'
  5731. }, '*');*/
  5732. }
  5733. let isJs = ruleParser.curSiteRule.action == 3 || /^(javascript|#)/.test(nextLink.replace(location.href,""));
  5734. if(!isJs){
  5735. emuIframe=null;
  5736. lastActiveUrl=nextLink;
  5737. if(location.protocol=="https:" && /^http:/.test(nextLink)){
  5738. nextLink=nextLink.replace(/^http/,"https");
  5739. }
  5740. }
  5741. isLoading=true;
  5742. ruleParser.insertElement(loadingDiv);
  5743. let parent=loadingDiv.parentNode;
  5744. if(parent.tagName=="TBODY"){
  5745. parent=parent.parentNode;
  5746. }
  5747. if(parent.tagName=="TABLE"){
  5748. parent.parentNode.appendChild(loadingDiv);
  5749. }
  5750. loadingDiv.style.cssText=loadingCSS;
  5751. if (curPage == 1 && isJs && ruleParser.curSiteRule.singleUrl) {
  5752. loadingDiv.style.display = "none";
  5753. }
  5754. let sleep=ruleParser.curSiteRule.sleep||0;
  5755. setTimeout(()=>{
  5756. if(ruleParser.curSiteRule.pageElementByJs){
  5757. var over=ele=>{
  5758. loadPageOver();
  5759. if (urlChanged || isPause) return;
  5760. if (ele) {
  5761. createPageBar(nextLink);
  5762. ruleParser.insertPage(null, ele, nextLink, null, true);
  5763. if(autoLoadNum>=0){
  5764. if(autoLoadNum!=0 && --autoLoadNum==0){
  5765. autoLoadNum=-1;
  5766. }else{
  5767. setTimeout(() => nextPage(), 1);
  5768. }
  5769. }
  5770. }else{
  5771. debug("Stop as no page when get by js");
  5772. isPause=true;
  5773. }
  5774. };
  5775. try{
  5776. ((typeof _unsafeWindow.pagetualPageElementByJs=='undefined') ? Function("over",'"use strict";' + ruleParser.curSiteRule.pageElementByJs) : _unsafeWindow.pagetualPageElementByJs)(over);
  5777. }catch(e){
  5778. debug(e);
  5779. }
  5780. }else if((forceState==2||ruleParser.curSiteRule.action==2) && !isJs){
  5781. forceIframe(nextLink, (iframe, eles)=>{
  5782. loadPageOver();
  5783. if (urlChanged || isPause) return;
  5784. let pageBar = createPageBar(nextLink);
  5785. if (pageBar) iframe.parentNode.insertBefore(pageBar, iframe);
  5786. if (autoLoadNum >= 0) {
  5787. if (autoLoadNum != 0 && --autoLoadNum == 0) {
  5788. autoLoadNum=-1;
  5789. } else {
  5790. setTimeout(() => nextPage(), 1);
  5791. }
  5792. }
  5793. });
  5794. }else if((forceState==3||ruleParser.curSiteRule.action==1) && !isJs){
  5795. requestFromIframe(nextLink, (doc, eles)=>{
  5796. loadPageOver();
  5797. if (urlChanged || isPause) return;
  5798. if (eles) {
  5799. ruleParser.insertPage(doc, eles, nextLink, ()=>{
  5800. createPageBar(nextLink);
  5801. }, true);
  5802. if(autoLoadNum>=0){
  5803. if(autoLoadNum!=0 && --autoLoadNum==0){
  5804. autoLoadNum=-1;
  5805. }else{
  5806. setTimeout(() => nextPage(), 1);
  5807. }
  5808. }
  5809. }
  5810. });
  5811. }else{
  5812. if(!isJs){
  5813. requestDoc(nextLink, (eles)=>{
  5814. loadPageOver();
  5815. if (urlChanged || isPause) return;
  5816. if (eles) {
  5817. createPageBar(nextLink);
  5818. if(autoLoadNum>=0){
  5819. if(autoLoadNum!=0 && --autoLoadNum==0){
  5820. autoLoadNum=-1;
  5821. }else{
  5822. setTimeout(() => nextPage(), 1);
  5823. }
  5824. }
  5825. }
  5826. });
  5827. }else{
  5828. emuPage((doc, eles)=>{
  5829. loadPageOver();
  5830. if (urlChanged || isPause) return;
  5831. if (eles) {
  5832. ruleParser.insertPage(doc, eles, "", ()=>{
  5833. createPageBar(nextLink);
  5834. }, true);
  5835. if(autoLoadNum>=0){
  5836. if(autoLoadNum!=0 && --autoLoadNum==0){
  5837. autoLoadNum=-1;
  5838. }else{
  5839. setTimeout(() => nextPage(), 1);
  5840. }
  5841. }
  5842. }
  5843. });
  5844. }
  5845. }
  5846. },sleep);
  5847. }
  5848. }
  5849.  
  5850. function init(){
  5851. initRules(()=>{
  5852. initPage();
  5853. });
  5854. }
  5855.  
  5856. function visibilitychangeHandler(){
  5857. document.removeEventListener('visibilitychange', visibilitychangeHandler);
  5858. init();
  5859. }
  5860.  
  5861. setTimeout(()=>{
  5862. if (document.hidden) {
  5863. document.addEventListener('visibilitychange', visibilitychangeHandler);
  5864. } else {
  5865. init();
  5866. }
  5867. },100);
  5868. })();