东方永页机

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

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

  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.27
  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){
  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")||
  1512. body.querySelector("[title=next]")||
  1513. body.querySelector("a#linkNext")||
  1514. body.querySelector("a[class*=page__next]");
  1515. if(!next){
  1516. let nexts=body.querySelectorAll("a.next");
  1517. for(i=0;i<nexts.length;i++){
  1518. if(nexts[i].style.display!=="none" &&
  1519. nexts[i].parentNode.style.display!=="none" &&
  1520. !/^\s*([上前首尾]|previous)/i.test(nexts[i].innerText.trim())){
  1521. next=nexts[i];
  1522. break;
  1523. }
  1524. }
  1525. }
  1526. if(next && (!next.href || /^(javascript|#)/.test(next.href.replace(location.href,"")))){
  1527. jsNext=next;
  1528. next=null;
  1529. }
  1530. if(!next){
  1531. next=body.querySelectorAll("[aria-label='Next page']");
  1532. if(next && next.length==1){
  1533. next=next[0];
  1534. if(!next.href || /^(javascript|#)/.test(next.href.replace(location.href,""))){
  1535. if(!jsNext)jsNext=next;
  1536. next=null;
  1537. }
  1538. }else{
  1539. next=null;
  1540. }
  1541. }
  1542. if(!next){
  1543. next=body.querySelectorAll("[aria-label='Next']");
  1544. if(next && next.length==1){
  1545. next=next[0];
  1546. if(!next.href || /^(javascript|#)/.test(next.href.replace(location.href,""))){
  1547. if(!jsNext)jsNext=next;
  1548. next=null;
  1549. }
  1550. }else{
  1551. next=null;
  1552. }
  1553. }
  1554. if(next && nextTextReg2.test(next.innerText.trim())){
  1555. next2=next;
  1556. next=null;
  1557. }
  1558. if(!next){
  1559. next=body.querySelector("a.curr+a");
  1560. }
  1561. if(!next){
  1562. next=body.querySelector("div.wp-pagenavi>span.current+a,div.page-nav>span.current+a,div.article-paging>span+a");
  1563. }
  1564. if(!next){
  1565. let pageDiv=body.querySelector("div.pages>ul");
  1566. if(pageDiv){
  1567. cur=pageDiv.querySelector("li>b");
  1568. if(cur)next=cur.parentNode.nextElementSibling;
  1569. if(next)next=next.querySelector("a");
  1570. }
  1571. }
  1572. if(!next){
  1573. next=body.querySelector(".number>ul>li.active+li>a");
  1574. }
  1575. if(!next){
  1576. next=body.querySelector(".pages>a[href='javascript:;']+a");
  1577. if(next && (next.href=="javascript:;" || next.getAttribute("href")=="#"))next=null;
  1578. }
  1579. if(!next){
  1580. let pageDiv=body.querySelector(".pagination");
  1581. if(pageDiv){
  1582. cur=pageDiv.querySelector("[class*=current]");
  1583. if(cur)next=cur.parentNode.nextElementSibling;
  1584. if(next)next=next.querySelector("a");
  1585. }
  1586. }
  1587. if(!next){
  1588. let aTags=body.querySelectorAll("a,button,[type='button']");
  1589. for(i=aTags.length-1;i>=0;i--){
  1590. if(next1 && next2 && next3 && next4)break;
  1591. let aTag=aTags[i];
  1592. if(aTag.innerText){
  1593. if(aTag.innerText=="§")continue;
  1594. if(aTag.innerText.trim().length>80)continue;
  1595. }
  1596. if(aTag.style.display=="none")continue;
  1597. if(aTag.href && /next$/i.test(aTag.href))continue;
  1598. if(aTag.className){
  1599. if(/slick|slide|gallery/i.test(aTag.className))continue;
  1600. if(aTag.classList && aTag.classList.contains('disabled'))continue;
  1601. }
  1602. if(aTag.parentNode){
  1603. if(aTag.parentNode.className && /slick|slide|gallery/i.test(aTag.parentNode.className))continue;
  1604. if(aTag.parentNode.classList && aTag.parentNode.classList.contains('disabled'))continue;
  1605. if(aTag.parentNode.tagName == "BLOCKQUOTE")continue;
  1606. }
  1607. let innerText = (aTag.innerText||aTag.value||aTag.title||'').trim().replace(/(\n.*| )/g, '');
  1608. let isJs = !aTag.href || /^(javascript|#)/.test(aTag.href.replace(location.href,""));
  1609. if(innerText && innerText.length<=25){
  1610. if(!next1){
  1611. if(nextTextReg1.test(innerText)){
  1612. if(isJs){
  1613. if(!nextJs1)nextJs1=aTag;
  1614. }else{
  1615. next1=aTag;
  1616. }
  1617. }
  1618. }
  1619. if(!next2){
  1620. if(nextTextReg2.test(innerText) || /nextpage/i.test(aTag.className) || innerText=="»" || innerText==">>"){
  1621. if(isJs){
  1622. if(!nextJs2)nextJs2=aTag;
  1623. }else{
  1624. next2=aTag;
  1625. }
  1626. }
  1627. }
  1628. if(!next3){
  1629. if(innerText=="Next" || innerText=="next" || innerText=="&gt;" || innerText=="▶" || innerText==">" || innerText=="›" || innerText=="→"){
  1630. if(isJs){
  1631. if(!nextJs3)nextJs3=aTag;
  1632. }else{
  1633. next3=aTag;
  1634. }
  1635. }
  1636. }
  1637. }
  1638. if (isJs) continue;
  1639. if (!next4) {
  1640. let prevEle = aTag.previousElementSibling;
  1641. if (prevEle && (prevEle.tagName == 'B' || prevEle.tagName == 'SPAN' || prevEle.tagName == 'STRONG')) {
  1642. if (/^\d+$/.test(aTag.innerText.trim()) && /^\d+$/.test(prevEle.innerText.trim()) && parseInt(aTag.innerText) == parseInt(prevEle.innerText) + 1) {
  1643. next4 = aTag;
  1644. }
  1645. }
  1646. }
  1647. if (!next4 && aTag.href.length < 250) {
  1648. let _aHref = aTag.href.replace("?&", "?").replace("index.php?", "?");
  1649. let _aHrefTrim = _aHref;
  1650. if (preStr) _aHrefTrim = _aHrefTrim.replace(preStr, "");
  1651. if (afterStr) _aHrefTrim = _aHrefTrim.replace(afterStr, "");
  1652. if ((preStr || afterStr) && pageNum < 999 && _aHrefTrim == pageNum + 1) {
  1653. next4 = aTag;
  1654. } else if (this.curUrl != aTag.href) {
  1655. _aHref = _aHref.replace(/\.s?html?$/i, "");
  1656. let pageTwoReg = /^[\/\?&]?[_-]?(p|page)?=?\/?2(\/|\?|&|$)/i;
  1657. if (_aHref.indexOf(_url) != -1 && pageTwoReg.test(_aHref.replace(_url, ""))) {
  1658. let curHref = aTag.getAttribute("href");
  1659. let pageOne = curHref.replace(/\/2(\/|\?|&|$)/,"/1$1");
  1660. if (pageOne == curHref) pageOne = null;
  1661. else pageOne = body.querySelector(`a[href='${pageOne}']`);
  1662. if (!pageOne || pageOne.className != curHref.className) next4 = aTag;
  1663. }
  1664. }
  1665. }
  1666. }
  1667. if(next3){
  1668. let eles=getAllElements(`//a[text()='${next3.innerText}']`, curPage);
  1669. if(eles.length>2)next3=null;
  1670. }
  1671. if(nextJs3){
  1672. let eles=getAllElements(`//a[text()='${nextJs3.innerText}']`, curPage);
  1673. if(eles.length>2)nextJs3=null;
  1674. }
  1675. }
  1676. if (!next) next = next1 || next4 || next3 || next2;
  1677. if (!next && (this.initGetPage || doc != document)) {
  1678. this.initGetPage = false;
  1679. next = jsNext || nextJs1 || nextJs3 || nextJs2;
  1680. if (next && next.parentNode.className.indexOf('tab') != -1) next = null;
  1681. }
  1682. if (next && next.classList && next.classList.contains("results-more")) next=null;
  1683. return {next:next, canSave:canSave};
  1684. }
  1685.  
  1686. canonicalUri(src) {
  1687. if (!src) {
  1688. return "";
  1689. }
  1690. if (src.charAt(0) == "#") return this.curUrl + src;
  1691. if (src.charAt(0) == "?") return this.curUrl.replace(/^([^\?#]+).*/, "$1" + src);
  1692. let origin = location.protocol + '//' + location.host;
  1693. let url = this.basePath || origin;
  1694. url = url.replace(/(\?|#).*/, "");
  1695. if (/https?:\/\/[^\/]+$/.test(url)) url = url + '/';
  1696. if (url.indexOf("http") !== 0) url = origin + url;
  1697. var root_page = /^[^\?#]*\//.exec(url)[0],
  1698. root_domain = /^\w+\:\/\/\/?[^\/]+/.exec(root_page)[0],
  1699. absolute_regex = /^\w+\:\/\//;
  1700. this.updateUrl = false;
  1701. while (src.indexOf("../") === 0) {
  1702. src = src.substr(3);
  1703. root_page = root_page.replace(/\/[^\/]+\/$/, "/");
  1704. this.updateUrl = true;
  1705. }
  1706. src = src.replace(/\.\//, "");
  1707. if (/^\/\/\/?/.test(src)) {
  1708. src = location.protocol + src;
  1709. }
  1710. return (absolute_regex.test(src) ? src : ((src.charAt(0) == "/" ? root_domain : root_page) + src));
  1711. }
  1712.  
  1713. getLinkByPage(url, pageNum) {
  1714. if(!url)return;
  1715. if(this.curSiteRule.pageNum){
  1716. let result=this.curSiteRule.pageNum;
  1717. let strMatch=result.match(/\{.*?}/);
  1718. if(!strMatch)return null;
  1719. let urlReg=new RegExp("("+result.replace(strMatch[0], ")\\d+(")+")","i");
  1720. let code=strMatch[0].replace(/^{/,"").replace(/}$/,"").replace(/\$p/g,pageNum);
  1721. if(code==pageNum){
  1722. result=url.replace(urlReg,"$1"+code+"$2");
  1723. }else{
  1724. try{
  1725. code=Function('"use strict";return ' + code)();
  1726. result=url.replace(urlReg,"$1"+code+"$2");
  1727. }catch(e){
  1728. debug(e);
  1729. }
  1730. }
  1731. if(result!=url){
  1732. return result;
  1733. }
  1734. }
  1735. return url.replace(/([&\/\?](p=|page[=\/_-]?))\d+/i, "$1"+pageNum).replace(/([_-])\d+\./i, "$1"+pageNum+".");
  1736. }
  1737.  
  1738. getPageNumFromUrl(url) {
  1739. if(!url)return curPage;
  1740. if(this.curSiteRule.pageNum){
  1741. let result=this.curSiteRule.pageNum;
  1742. let strMatch=result.match(/\{.*?}/);
  1743. if(!strMatch)return null;
  1744. let urlReg=new RegExp(".*"+result.replace(strMatch[0], "(\\d+)")+".*","i");
  1745. let curShowNum=url.replace(urlReg,"$1");
  1746. if (curShowNum!=url){
  1747. let code=strMatch[0].replace(/^{/,"").replace(/}$/,"");
  1748. if(code=="$p"){
  1749. return curShowNum;
  1750. }else{
  1751. try{
  1752. let page1=Function('"use strict";return ' + code.replace("$p", "0"))();
  1753. let page2=Function('"use strict";return ' + code.replace("$p", "1"))();
  1754. let numGap=page2-page1;
  1755. return (curShowNum - page1) / numGap;
  1756. }catch(e){
  1757. debug(e);
  1758. }
  1759. }
  1760. } else {
  1761. return curPage;
  1762. }
  1763. }
  1764. let pageNum=url.replace(/.*[&\/\?](p=|page[=\/_-]?)(\d+).*/i, "$2");
  1765. return pageNum==url?curPage:pageNum;
  1766. }
  1767.  
  1768. async getNextLink(doc) {
  1769. let nextLink = null, page, href;
  1770. let getNextLinkByForm = (form, n) => {
  1771. let params = [];
  1772. let formData = new FormData(form);
  1773. for (let [key, value] of formData) {
  1774. if (n && /^(p|page)$/i.test(key)) {
  1775. params.push(key + '=' + n);
  1776. } else {
  1777. params.push(key + '=' + encodeURIComponent(value));
  1778. }
  1779. }
  1780. params = params.join('&');
  1781. return form.action + (form.action.indexOf('?') == -1 ? '?' : '&') + params + (form.method == 'post' ? '#p{' + params + '}' : '');
  1782. };
  1783. if (this.curSiteRule.pageElementByJs) {
  1784. this.nextLinkHref = "#";
  1785. return true;
  1786. } else if (this.curSiteRule.nextLinkByJs) {
  1787. try {
  1788. let over = _url => {
  1789. };
  1790. let targetUrl = await ((typeof _unsafeWindow.pagetualNextLinkByJs == 'undefined') ? new AsyncFunction("doc", '"use strict";' + this.curSiteRule.nextLinkByJs) : _unsafeWindow.pagetualNextLinkByJs)(doc);
  1791. if (targetUrl) nextLink = {href: targetUrl};
  1792. } catch(e) {
  1793. debug(e);
  1794. }
  1795. } else if (this.curSiteRule.nextLinkByUrl) {
  1796. let targetUrl = this.curUrl.replace(new RegExp(this.curSiteRule.nextLinkByUrl[0], "i"), this.curSiteRule.nextLinkByUrl[1]);
  1797. if (targetUrl != this.curUrl) {
  1798. let includeSel = this.curSiteRule.nextLinkByUrl[2];
  1799. let excludeSel = this.curSiteRule.nextLinkByUrl[3];
  1800. if (includeSel) {
  1801. includeSel = includeSel.trim();
  1802. if (!getElement(includeSel, doc)) {
  1803. this.nextLinkHref=false;
  1804. return null;
  1805. }
  1806. }
  1807. if (excludeSel) {
  1808. excludeSel = excludeSel.trim();
  1809. if (getElement(excludeSel, doc)) {
  1810. this.nextLinkHref=false;
  1811. return null;
  1812. }
  1813. }
  1814. let reps = targetUrl.match(/{.*?}/g);
  1815. if (reps) {
  1816. reps.forEach(rep => {
  1817. let code = rep.replace("{","").replace("}", "").replace(/\(\)/g, "0");
  1818. let result = code.match(/^(\d*)\+1$/);
  1819. if (result) {
  1820. result = parseInt(result[1] || 1) + 1;
  1821. } else {
  1822. try {
  1823. result = Function('"use strict";return ' + code)();
  1824. } catch(e) {
  1825. debug(e);
  1826. }
  1827. }
  1828. targetUrl = targetUrl.replace(rep, result);
  1829. });
  1830. }
  1831. }
  1832. nextLink = {href: targetUrl};
  1833. } else if (this.curSiteRule.nextLink) {
  1834. let nextLinkSel = this.curSiteRule.nextLink;
  1835. if (nextLinkSel != "0" && nextLinkSel != 0) {
  1836. if (Array && Array.isArray && Array.isArray(nextLinkSel)) {
  1837. nextLink = getElement(nextLinkSel[nextIndex], doc);
  1838. } else nextLink = getElement(nextLinkSel, doc);
  1839. }
  1840. if (nextLink && (this.curSiteRule.action == 0 || this.curSiteRule.action == 1 || this.curSiteRule.action == 2)) {
  1841. let form = doc.querySelector('#search-form');
  1842. if (!nextLink.href && nextLink.hasAttribute("onclick") && form) {
  1843. if (/^\d+$/.test(nextLink.innerText)) {
  1844. nextLink.href = getNextLinkByForm(form, nextLink.innerText);
  1845. }
  1846. } else if (nextLink.tagName == "INPUT" || nextLink.type == "submit") {
  1847. form = nextLink.parentNode;
  1848. while (form) {
  1849. if (form.tagName == "FORM") break;
  1850. else form = form.parentNode;
  1851. }
  1852. if (form) {
  1853. nextLink.href = getNextLinkByForm(form);
  1854. }
  1855. }
  1856. if (nextLink.href && this.curSiteRule.action != 0) {
  1857. nextLink.href = nextLink.href.replace(/#p{.*/, "");
  1858. }
  1859. }
  1860. }else{
  1861. page=this.getPage(doc);
  1862. nextLink=page.next;
  1863. if(nextLink){
  1864. if(nextLink.tagName=="INPUT" || nextLink.type=="submit"){
  1865. let form = nextLink.parentNode;
  1866. while (form) {
  1867. if (form.tagName == "FORM") break;
  1868. else form = form.parentNode;
  1869. }
  1870. if (form) {
  1871. nextLink.href = getNextLinkByForm(form);
  1872. }
  1873. }
  1874. let parent = nextLink;
  1875. while (parent && parent.tagName !== "BODY") {
  1876. if (parent.hasAttribute("disabled")) {
  1877. this.nextLinkHref = false;
  1878. return null;
  1879. }
  1880. if (parent.className && parent.classList) {
  1881. if (parent.classList.contains("noClick") || parent.classList.contains("no-pages")) {
  1882. this.nextLinkHref = false;
  1883. return null;
  1884. }
  1885. }
  1886. if (parent.style.display === "none") {
  1887. this.nextLinkHref = false;
  1888. return null;
  1889. }
  1890. parent = parent.parentNode;
  1891. }
  1892. if(doc==document){
  1893. if((!nextLink.href || /^(javascript|#)/.test(nextLink.href.replace(location.href,""))) && !isVisible(nextLink, _unsafeWindow)){
  1894. this.nextLinkHref=false;
  1895. return null;
  1896. }else{
  1897. let nextLinkCs=_unsafeWindow.getComputedStyle(nextLink);
  1898. if(nextLinkCs.cursor=="not-allowed"){
  1899. this.nextLinkHref=false;
  1900. return null;
  1901. }
  1902. this.initNext=nextLink;
  1903. }
  1904. }
  1905. let form=doc.querySelector('#search-form');
  1906. if(!nextLink.href && nextLink.hasAttribute("onclick") && form){
  1907. if(form && /^\d+$/.test(nextLink.innerText)){
  1908. href=getNextLinkByForm(form, nextLink.innerText);
  1909. }
  1910. }
  1911. }
  1912. }
  1913. if (nextLink) {
  1914. if (this.curSiteRule.stopSign) {
  1915. if (Array && Array.isArray && Array.isArray(this.curSiteRule.stopSign)) {
  1916. let includeSel = this.curSiteRule.stopSign[0];
  1917. let excludeSel = this.curSiteRule.stopSign[1];
  1918. let curSign = this.curSiteRule.stopSign[2];
  1919. let maxSign = this.curSiteRule.stopSign[3];
  1920. if (Array && Array.isArray && Array.isArray(includeSel) && !curSign) {
  1921. curSign = includeSel;
  1922. includeSel = false;
  1923. }
  1924. if (Array && Array.isArray && Array.isArray(excludeSel) && !maxSign) {
  1925. maxSign = excludeSel;
  1926. excludeSel = false;
  1927. }
  1928. if (includeSel) {
  1929. includeSel = includeSel.trim();
  1930. if (!getElement(includeSel, doc)) {
  1931. this.nextLinkHref=false;
  1932. return null;
  1933. }
  1934. }
  1935. if (excludeSel) {
  1936. excludeSel = excludeSel.trim();
  1937. if (getElement(excludeSel, doc)) {
  1938. this.nextLinkHref=false;
  1939. return null;
  1940. }
  1941. }
  1942. if (curSign && maxSign) {
  1943. let currentEle = getElement(curSign[0], doc);
  1944. let maxEle = getElement(maxSign[0], doc);
  1945. if (currentEle && maxEle) {
  1946. let currentSignNum, maxSignNum;
  1947. if (/\(.*\)/.test(curSign[1])) {
  1948. currentSignNum = currentEle.innerText.match(new RegExp(curSign[1]));
  1949. if (currentSignNum) currentSignNum = currentSignNum[1];
  1950. } else if (currentEle.getAttribute) {
  1951. currentSignNum = currentEle.getAttribute(curSign[1]);
  1952. }
  1953. if (/\(.*\)/.test(maxSign[1])) {
  1954. maxSignNum = maxEle.innerText.match(new RegExp(maxSign[1]));
  1955. if (maxSignNum) maxSignNum = maxSignNum[1];
  1956. } else if (maxEle.getAttribute) {
  1957. maxSignNum = maxEle.getAttribute(maxSign[1]);
  1958. }
  1959. if (currentSignNum && maxSignNum && currentSignNum == maxSignNum) {
  1960. this.nextLinkHref = false;
  1961. return null;
  1962. }
  1963. }
  1964. }
  1965. } else {
  1966. try {
  1967. let stopSign = ((typeof _unsafeWindow.stopSign == 'undefined') ? Function("doc", "nextLink", '"use strict";' + this.curSiteRule.stopSign) : _unsafeWindow.stopSign)(doc, nextLink);
  1968. if (stopSign) {
  1969. this.nextLinkHref = false;
  1970. return null;
  1971. }
  1972. } catch(e) {
  1973. debug(e);
  1974. }
  1975. }
  1976. }
  1977. if (this.curSiteRule.action == 3) {
  1978. if (doc == document) debug(nextLink, 'Next link');
  1979. this.nextLinkHref = '#';
  1980. } else {
  1981. let needUrl = (this.curSiteRule.action == 0 || this.curSiteRule.action == 1 || this.curSiteRule.action == 2);
  1982. if (!href) href = nextLink.href;
  1983. if (href && nextLink.getAttribute) {
  1984. let _href = nextLink.getAttribute("href");
  1985. if (_href) {
  1986. if (_href.charAt(0) == "#" || _href == "?"){
  1987. href = "#";
  1988. } else {
  1989. href = _href;
  1990. }
  1991. }
  1992. }
  1993.  
  1994. if(needUrl && (href===""||href===null)){
  1995. this.nextLinkHref=false;
  1996. }else if(needUrl && /^(javascript:|#)/.test(href)){
  1997. this.nextLinkHref=false;
  1998. }else{
  1999. this.nextLinkHref=(href && !/^(javascript:|#)/.test(href))?this.canonicalUri(href):"#";
  2000. if(this.nextLinkHref!="#" && (this.nextLinkHref==this.curUrl || this.nextLinkHref==this.curUrl+"#" || this.nextLinkHref==this.oldUrl || this.nextLinkHref==this.oldUrl+"#")){
  2001. this.nextLinkHref=false;
  2002. }else if(doc==document)debug(nextLink, 'Next link');
  2003. }
  2004. }
  2005. }else{
  2006. this.nextLinkHref=false;
  2007. }
  2008. this.preload();
  2009. return nextLink;
  2010. }
  2011.  
  2012. preload(){
  2013. if(!rulesData.preload)return;
  2014. if(!this.nextLinkHref || this.nextLinkHref=="#")return;
  2015. let self=this;
  2016. _GM_xmlhttpRequest({
  2017. url: this.nextLinkHref,
  2018. method: 'GET',
  2019. overrideMimeType: 'text/html;charset=' + (document.characterSet || document.charset || document.inputEncoding),
  2020. headers: {
  2021. 'Referer': location.href
  2022. },
  2023. timeout: 10000,
  2024. onload: function(res) {
  2025. var doc=null;
  2026. try {
  2027. doc=document.implementation.createHTMLDocument('');
  2028. doc.documentElement.innerHTML=res.response;
  2029. var body = doc.body;
  2030. if (body && body.firstChild) {
  2031. self.lazyImgAction(body.children);
  2032. }
  2033. if(!self.preloadDiv){
  2034. self.preloadDiv = document.createElement('div');
  2035. self.preloadDiv.id = "pagetual-preload";
  2036. self.preloadDiv.style.cssText = 'display:none!important;';
  2037. document.body.appendChild(self.preloadDiv);
  2038. self.checkedImgs={};
  2039. }
  2040. [].forEach.call(doc.images, i=>{
  2041. let iSrc=i.src;
  2042. if(iSrc && !self.checkedImgs[iSrc]){
  2043. self.checkedImgs[iSrc] = true;
  2044. let img = document.createElement('img');
  2045. img.src = iSrc;
  2046. self.preloadDiv.appendChild(img);
  2047. }
  2048. });
  2049. }
  2050. catch (e) {
  2051. return;
  2052. }
  2053. }
  2054. });
  2055. }
  2056.  
  2057. getInsert(refresh) {
  2058. if(refresh){
  2059. this.insert=null;
  2060. }
  2061. if(this.insert && document.documentElement.contains(this.insert)){
  2062. return this.insert;
  2063. }
  2064. if (this.curSiteRule.insert) {
  2065. let insertSel = this.curSiteRule.insert;
  2066. if (Array && Array.isArray && Array.isArray(insertSel)) {
  2067. insertSel = insertSel[nextIndex < insertSel.length ? nextIndex : 0];
  2068. }
  2069. this.insert=getElement(insertSel, document);
  2070. } else {
  2071. let pageElement = this.getPageElement(document, _unsafeWindow);
  2072. if (this.curSiteRule.singleUrl && this.nextLinkHref == "#" && this.curSiteRule.pageElement === 'body') {
  2073. debug("Stop as jsNext & whole body");
  2074. isPause = true;
  2075. return null;
  2076. }
  2077. if (pageElement && pageElement.length > 0) {
  2078. var pELast = pageElement[pageElement.length - 1];
  2079. this.insert = pELast.nextSibling ? pELast.nextSibling : pELast.parentNode.appendChild(document.createTextNode(' '));
  2080. }
  2081. }
  2082. return this.insert;
  2083. }
  2084.  
  2085. pageInit(doc,eles){
  2086. let code=this.curSiteRule.pageInit;
  2087. if(code){
  2088. let initFunc=((typeof _unsafeWindow.pagetualPageInit=='undefined') ? Function("doc", "eles", '"use strict";' + code) : _unsafeWindow.pagetualPageInit);
  2089. let checkInit=(resolve)=>{
  2090. try{
  2091. if(initFunc(doc, eles)===false){
  2092. setTimeout(()=>{
  2093. checkInit(resolve);
  2094. },100);
  2095. } else {
  2096. resolve(true);
  2097. }
  2098. }catch(e){
  2099. resolve(false);
  2100. debug(e);
  2101. }
  2102. };
  2103. return new Promise((resolve) => {
  2104. checkInit(function(e) {
  2105. resolve(e)
  2106. });
  2107. })
  2108. }
  2109. }
  2110.  
  2111. pageAction(doc,eles){
  2112. let code=this.curSiteRule.pageAction;
  2113. if(code){
  2114. try{
  2115. ((typeof _unsafeWindow.pagetualPageAction=='undefined') ? Function("doc", "eles", '"use strict";' + code) : _unsafeWindow.pagetualPageAction)(doc, eles);
  2116. }catch(e){
  2117. debug(e);
  2118. }
  2119. }
  2120. this.openInNewTab(eles);
  2121. this.replaceElement(doc);
  2122. }
  2123.  
  2124. openInNewTab(eles){
  2125. if(rulesData.openInNewTab){
  2126. [].forEach.call(eles, ele=>{
  2127. if(ele.tagName=="A" && ele.href && !/^(mailto:|javascript:)|#/.test(ele.href)){
  2128. ele.setAttribute('target', '_blank');
  2129. }else{
  2130. [].forEach.call(ele.querySelectorAll('a[href]:not([href^="mailto:"]):not([href^="javascript:"]):not([href^="#"])'), a=>{
  2131. a.setAttribute('target', '_blank');
  2132. if (a.getAttribute('onclick') == 'atarget(this)') {
  2133. a.removeAttribute('onclick');
  2134. }
  2135. });
  2136. }
  2137. });
  2138. }
  2139. }
  2140.  
  2141. lazyImgAction(eles) {
  2142. if (!eles || eles.length == 0) return;
  2143. let lazyImgSrc = this.curSiteRule.lazyImgSrc;
  2144. if (lazyImgSrc === 0 || lazyImgSrc === '0') return;
  2145. let setLazyImg = img => {
  2146. let realSrc;
  2147. if (lazyImgSrc) {
  2148. if (!Array.isArray(lazyImgSrc)) {
  2149. lazyImgSrc = [lazyImgSrc];
  2150. }
  2151. realSrc = img.getAttribute(lazyImgSrc[0]);
  2152. if (lazyImgSrc.length == 2) {
  2153. let removeProps = lazyImgSrc[1].split(",");
  2154. removeProps.forEach(prop => {
  2155. img.removeAttribute(prop.trim());
  2156. });
  2157. }
  2158. }
  2159. if (!realSrc) {
  2160. if (img.getAttribute("_src") && !img.src) {
  2161. realSrc = img.getAttribute("_src");
  2162. } else if (img.dataset) {
  2163. if (img.dataset.original) {
  2164. realSrc = img.dataset.original;
  2165. } else if (img.dataset.lazySrc) {
  2166. realSrc = img.dataset.lazySrc;
  2167. } else if (img.dataset.lazy) {
  2168. realSrc = img.dataset.lazy;
  2169. } else if (img.dataset.src) {
  2170. realSrc = img.dataset.src;
  2171. } else if (img.dataset.origFile) {
  2172. realSrc = img.dataset.origFile;
  2173. }
  2174. }
  2175. if (!realSrc && img._lazyrias && img._lazyrias.srcset) {
  2176. realSrc = img._lazyrias.srcset[img._lazyrias.srcset.length - 1];
  2177. }
  2178. if (realSrc) {
  2179. img.removeAttribute("srcset");
  2180. } else if (img.srcset) {
  2181. var srcs = img.srcset.split(/[xw],/), largeSize = 0;
  2182. srcs.forEach(srci => {
  2183. let srcInfo = srci.trim().split(" "), curSize = parseInt(srcInfo[1]);
  2184. if (srcInfo[1] && curSize > largeSize) {
  2185. largeSize = curSize;
  2186. realSrc = srcInfo[0];
  2187. }
  2188. });
  2189. }
  2190. }
  2191. if (realSrc) {
  2192. img.src = realSrc;
  2193. if (img.style.display == "none") {
  2194. img.style.display = "";
  2195. }
  2196. if (img.style.visibility == "hidden") {
  2197. img.style.visibility = "";
  2198. }
  2199. if (img.style.opacity == 0) {
  2200. img.style.opacity = "";
  2201. }
  2202. }
  2203. };
  2204. [].forEach.call(eles, ele=>{
  2205. if(ele.tagName=="IMG"){
  2206. setLazyImg(ele);
  2207. }else{
  2208. [].forEach.call(ele.querySelectorAll("img"), img=>{
  2209. setLazyImg(img);
  2210. });
  2211. [].forEach.call(ele.querySelectorAll("div[data-src][data-thumb]"), div=>{
  2212. div.style.setProperty("background-image", "url("+div.dataset.src+")", "important");
  2213. });
  2214. }
  2215. if(ele.tagName=="A" && ele.classList.contains("lazyload")){
  2216. if(ele.dataset.original){
  2217. ele.style.backgroundImage='url("'+ele.dataset.original+'")';
  2218. }
  2219. }else{
  2220. [].forEach.call(ele.querySelectorAll("a.lazyload"), a=>{
  2221. if(a.dataset.original){
  2222. a.style.backgroundImage='url("'+a.dataset.original+'")';
  2223. }
  2224. });
  2225. }
  2226. });
  2227. }
  2228.  
  2229. initPage(callback){
  2230. let self=this;
  2231. curPage=1;
  2232. //if(this.curSiteRule.url && !this.curSiteRule.singleUrl)return;
  2233. this.curSiteRule={};
  2234. this.pageDoc=document;
  2235. this.nextLinkHref=null;
  2236. this.curUrl=location.href;
  2237. let base=document.querySelector("base");
  2238. this.basePath=base?base.href:location.href;
  2239. this.getRule(async () => {
  2240. if(self.curSiteRule.enable==0){
  2241. debug("Stop as rule disable");
  2242. isPause=true;
  2243. return;
  2244. }
  2245. //若是再亂匹配就不緩存wedata,或者只在找完本地規則之後再考慮wedata的緩存
  2246. if (self.curSiteRule.singleUrl) {
  2247. self.curSiteRule.pageElement = "";
  2248. self.smartRules = self.smartRules.filter(item => {return item && item.url != self.curSiteRule.url});
  2249. self.smartRules.unshift(self.curSiteRule);
  2250. if (self.smartRules.length > 100) {
  2251. self.smartRules.pop();
  2252. }
  2253. storage.setItem("smartRules", self.smartRules);
  2254. } else if (self.curSiteRule && self.curSiteRule.url.length > 13) {
  2255. self.hpRules = self.hpRules.filter(item => {return item && item.url != self.curSiteRule.url});
  2256. self.hpRules.unshift(self.curSiteRule);
  2257. if (self.hpRules.length > 30) {
  2258. self.hpRules.pop();
  2259. }
  2260. storage.setItem("hpRules", self.hpRules);
  2261. }
  2262. let css=self.curSiteRule.css || rulesData.customCss;
  2263. if(css && !/^inIframe:/.test(css)){
  2264. _GM_addStyle(css);
  2265. }
  2266. let autoClick=self.curSiteRule.autoClick;
  2267. if(autoClick){
  2268. let autoClickBtn;
  2269. autoClickBtn=getElement(autoClick, document);
  2270. if(autoClickBtn){
  2271. emuClick(autoClickBtn);
  2272. }
  2273. }
  2274. let code=self.curSiteRule.init;
  2275. if(code){
  2276. try{
  2277. ((typeof _unsafeWindow.pagetualInit=='undefined') ? Function('doc','win','iframe','"use strict";' + code) : _unsafeWindow.pagetualInit)(null,null,null);
  2278. }catch(e){
  2279. debug(e);
  2280. }
  2281. }
  2282. await self.getNextLink(document);
  2283. self.refreshByClick();
  2284. callback();
  2285. });
  2286. }
  2287.  
  2288. insertElement(ele) {
  2289. this.getInsert();
  2290. if(this.curSiteRule.insertPos==2){
  2291. this.insert.appendChild(ele);
  2292. }else{
  2293. this.insert.parentNode.insertBefore(ele, this.insert);
  2294. }
  2295. }
  2296.  
  2297. async insertPage(doc, eles, url, callback, tried) {
  2298. this.oldUrl=this.curUrl;
  2299. let oldTitle=this.pageDoc.title;
  2300. this.pageDoc=doc;
  2301. this.curUrl=url;
  2302. let nextLink=await this.getNextLink(doc);
  2303. this.nextTitle="";
  2304. if(this.curSiteRule.pageBarText){
  2305. if(this.curSiteRule.pageBarText==1 || this.curSiteRule.pageBarText==true){
  2306. this.nextTitle=doc.title;
  2307. }else{
  2308. try{
  2309. this.nextTitle=((typeof _unsafeWindow.pagetualPageBarText=='undefined') ? Function("doc",'"use strict";' + this.curSiteRule.pageBarText) : _unsafeWindow.pagetualPageBarText)(doc);
  2310. }catch(e){
  2311. debug(e);
  2312. }
  2313. }
  2314. }
  2315. if(curPage==1 && !tried && !nextLink && this.curSiteRule.singleUrl && this.curSiteRule.pageElement && this.curSiteRule.action!=0){
  2316. this.curSiteRule.action=1;
  2317. this.curUrl=location.href;
  2318. return false;
  2319. }
  2320. if(callback)callback(eles);
  2321. this.getInsert();
  2322. var self=this,newEles=[];
  2323. if(!eles || eles.length==0 || !self.insert || !self.insert.parentNode){
  2324. }else{
  2325. isLoading=true;
  2326. await this.pageInit(doc, eles);
  2327. let curScroll=document.body.scrollTop||document.documentElement.scrollTop;
  2328. [].forEach.call(eles, ele=>{
  2329. let newEle=ele.cloneNode(true);
  2330. let oldCanvass=ele.querySelectorAll("canvas");
  2331. let newCanvass=newEle.querySelectorAll("canvas");
  2332. if(self.updateUrl){
  2333. [].forEach.call(newEle.querySelectorAll("img"), img=>{
  2334. if (img.getAttribute("src")) img.src=self.canonicalUri(img.getAttribute("src"));
  2335. });
  2336. [].forEach.call(newEle.querySelectorAll("a"), a=>{
  2337. if (a.getAttribute("href")) a.href = self.canonicalUri(a.getAttribute("href"));
  2338. });
  2339. }
  2340. for(let i=0;i<oldCanvass.length;i++){
  2341. let oldCanvas=oldCanvass[i];
  2342. let newCanvas=newCanvass[i];
  2343. newCanvas.getContext('2d').drawImage(oldCanvas, 0, 0);
  2344. }
  2345. self.insertElement(newEle);
  2346. newEles.push(newEle);
  2347. });
  2348. document.body.scrollTop=curScroll;
  2349. document.documentElement.scrollTop=curScroll;
  2350. }
  2351. this.pageAction(doc, newEles);
  2352. let enableHistory = this.curSiteRule.history;
  2353. let enableHistoryAfterInsert = false;
  2354. if (enableHistory == 1) {
  2355. enableHistory = true;
  2356. } else if (enableHistory == 2) {
  2357. enableHistory = true;
  2358. enableHistoryAfterInsert = true;
  2359. } else if (enableHistory == 0) {
  2360. enableHistory = false;
  2361. } else {
  2362. enableHistory = rulesData.enableHistory;
  2363. enableHistoryAfterInsert = rulesData.enableHistoryAfterInsert;
  2364. }
  2365. if (enableHistory) {
  2366. let historyUrl = enableHistoryAfterInsert ? this.curUrl : this.oldUrl;
  2367. if(historyUrl != location.href) {
  2368. let isJs=/^(javascript|#)/.test(historyUrl.replace(location.href, ""));
  2369. if(!isJs){
  2370. let historyTitle = enableHistoryAfterInsert ? doc.title : oldTitle;
  2371. _unsafeWindow.history.replaceState(undefined, historyTitle, historyUrl);
  2372. document.title = historyTitle;
  2373. }
  2374. }
  2375. }
  2376. isLoading = false;
  2377. return true;
  2378. }
  2379. }
  2380. var ruleParser = new RuleParser();
  2381.  
  2382. class SideController {
  2383. static controller;
  2384. constructor() {
  2385. this.init();
  2386. }
  2387.  
  2388. static getInstance() {
  2389. if (!SideController.controller) {
  2390. SideController.controller = new SideController();
  2391. }
  2392. return SideController.controller;
  2393. }
  2394.  
  2395. static setup() {
  2396. if (!rulesData.sideController) return;
  2397. SideController.getInstance().addToStage();
  2398. }
  2399.  
  2400. init() {
  2401. let self = this;
  2402. let cssText = `
  2403. #pagetual-sideController {
  2404. position: fixed;
  2405. top: calc(50% - 75px);
  2406. left: calc(99% - 45px);
  2407. width: 40px;
  2408. border-radius: 20px;
  2409. box-shadow: rgb(0 0 0) 0px 0px 10px;
  2410. text-align: center;
  2411. font-weight: bold;
  2412. font-style: normal;
  2413. font-size: 20px!important;
  2414. background: white!important;
  2415. color: black!important;
  2416. user-select: none;
  2417. z-index: 2147483647!important;
  2418. padding: 0!important;
  2419. }
  2420. #pagetual-sideController.stop {
  2421. -webkit-filter: invert(100%);
  2422. filter: invert(100%);
  2423. }
  2424. .pagetual-sideController-btn {
  2425. padding: 5px 0;
  2426. cursor: pointer;
  2427. transition: transform .15s ease-in-out;
  2428. }
  2429. .pagetual-sideController-btn:hover {
  2430. transform: scale(1.5);
  2431. color: red;
  2432. }
  2433. `;
  2434. _GM_addStyle(cssText);
  2435. let frame = document.createElement("div");
  2436. frame.id = "pagetual-sideController";
  2437. frame.innerHTML = createHTML(`
  2438. <div id="pagetual-sideController-top" class="pagetual-sideController-btn">⊼</div>
  2439. <div>
  2440. <div id="pagetual-sideController-pre" class="pagetual-sideController-btn">∧</div>
  2441. <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>
  2442. <div id="pagetual-sideController-next" class="pagetual-sideController-btn">∨</div>
  2443. </div>
  2444. <div id="pagetual-sideController-bottom" class="pagetual-sideController-btn">⊻</div>
  2445. `);
  2446. let top = frame.querySelector("#pagetual-sideController-top");
  2447. let pre = frame.querySelector("#pagetual-sideController-pre");
  2448. let move = frame.querySelector("#pagetual-sideController-move");
  2449. let next = frame.querySelector("#pagetual-sideController-next");
  2450. let bottom = frame.querySelector("#pagetual-sideController-bottom");
  2451.  
  2452. frame.addEventListener("dblclick", e => {
  2453. e.preventDefault();
  2454. e.stopPropagation();
  2455. }, true);
  2456.  
  2457. pre.addEventListener("click", e => {
  2458. let prePageBar = getPageBar().preBar;
  2459. if (prePageBar) {
  2460. scrollToPageBar(prePageBar);
  2461. } else {
  2462. let scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
  2463. window.scrollTo({ top: scrollTop - (window.innerHeight || document.documentElement.clientHeight), behavior: 'smooth'});
  2464. }
  2465. }, true);
  2466.  
  2467. next.addEventListener("click", e => {
  2468. let nextPageBar=getPageBar().nextBar;
  2469. if (nextPageBar) {
  2470. scrollToPageBar(nextPageBar);
  2471. } else {
  2472. let scrollH = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  2473. window.scrollTo({ top: (scrollH || 9999999), behavior: 'smooth'});
  2474. }
  2475. }, true);
  2476.  
  2477. top.addEventListener("click", e => {
  2478. document.body.scrollTop=0;
  2479. document.documentElement.scrollTop=0;
  2480. e.preventDefault();
  2481. e.stopPropagation();
  2482. }, true);
  2483.  
  2484. bottom.addEventListener("click", e => {
  2485. changeStop(true);
  2486. let scrollH = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  2487. document.body.scrollTop = scrollH || 9999999;
  2488. document.documentElement.scrollTop = scrollH || 9999999;
  2489. e.preventDefault();
  2490. e.stopPropagation();
  2491. frame.classList.add("stop");
  2492. }, true);
  2493.  
  2494. let initX, initY, moving = false;
  2495. move.addEventListener("click", e => {
  2496. if (!moving) {
  2497. changeStop(!isPause);
  2498. if (isPause) {
  2499. frame.classList.add("stop");
  2500. } else {
  2501. frame.classList.remove("stop");
  2502. }
  2503. }
  2504. }, true);
  2505.  
  2506. let mouseMoveHandler = e => {
  2507. if (moving) {
  2508. let windowHeight=window.innerHeight || document.documentElement.clientHeight;
  2509. let windowWidth=window.innerWidth || document.documentElement.clientWidth;
  2510. initX = parseInt(e.clientX / windowWidth * 100);
  2511. initY = parseInt(e.clientY / windowHeight * 100);
  2512. this.frame.style.top = `calc(${initY}% - 70px)`;
  2513. this.frame.style.left = `calc(${initX}% - 5px)`;
  2514. } else if (Math.abs(e.clientX - initX) + Math.abs(e.clientY - initY) > 20) {
  2515. moving = true;
  2516. }
  2517. };
  2518. let mouseUpHandler = e => {
  2519. document.removeEventListener("mousemove", mouseMoveHandler, true);
  2520. document.removeEventListener("mouseup", mouseUpHandler, true);
  2521. if (moving) {
  2522. rulesData.sideControllerPos = {x: initX, y: initY};
  2523. storage.setItem("rulesData", rulesData);
  2524. }
  2525. };
  2526.  
  2527. move.addEventListener("mousedown", e => {
  2528. initX = e.clientX;
  2529. initY = e.clientY;
  2530. moving = false;
  2531. document.addEventListener("mousemove", mouseMoveHandler, true);
  2532. document.addEventListener("mouseup", mouseUpHandler, true);
  2533. }, true);
  2534.  
  2535. this.frame = frame;
  2536. if (rulesData.sideControllerPos) {
  2537. this.frame.style.top = `calc(${rulesData.sideControllerPos.y}% - 70px)`;
  2538. this.frame.style.left = `calc(${rulesData.sideControllerPos.x}% - 5px)`;
  2539. }
  2540. }
  2541.  
  2542. addToStage() {
  2543. document.body.appendChild(this.frame);
  2544. }
  2545. }
  2546.  
  2547. class NextSwitch {
  2548. static nextSwitch;
  2549. constructor() {
  2550. this.init();
  2551. }
  2552.  
  2553. static getInstance() {
  2554. if (!NextSwitch.nextSwitch) {
  2555. NextSwitch.nextSwitch = new NextSwitch();
  2556. }
  2557. return NextSwitch.nextSwitch;
  2558. }
  2559.  
  2560. init() {
  2561. let self = this;
  2562. let cssText = `
  2563. #pagetual-nextSwitch {
  2564. position: fixed;
  2565. top: 10px;
  2566. left: calc(50% - 160px);
  2567. background: aliceblue;
  2568. padding: 10px;
  2569. border-radius: 5px;
  2570. text-align: center;
  2571. opacity: 0.95;
  2572. color: #161616;
  2573. z-index: 2147483647;
  2574. font-size: 16px;
  2575. box-shadow: rgb(0 0 0) 0px 0px 10px;
  2576. }
  2577. #pagetual-nextSwitch>.title {
  2578. margin: -5px 45px 10px 45px;
  2579. font-size: 20px;
  2580. font-weight: bold;
  2581. border-bottom: 1px solid black;
  2582. user-select: none;
  2583. color: orangered;
  2584. }
  2585. #pagetual-nextSwitch>.group {
  2586. display: flex;
  2587. flex-direction: column;
  2588. }
  2589. #pagetual-nextSwitch>.group>span {
  2590. color: #161616;
  2591. cursor: pointer;
  2592. margin: 3px;
  2593. font-size: larger;
  2594. }
  2595. #pagetual-nextSwitch>.group>span:hover {
  2596. color: red;
  2597. }
  2598. #pagetual-nextSwitch>.group>span.current {
  2599. border: 2px dotted red;
  2600. border-radius: 10px;
  2601. }
  2602. #pagetual-nextSwitch>.closeSwitch {
  2603. position: absolute;
  2604. top: 3px;
  2605. right: 10px;
  2606. background: none;
  2607. border: none;
  2608. vertical-align: top;
  2609. transition: transform .15s ease-in-out;
  2610. float: right;
  2611. cursor: pointer;
  2612. }
  2613. #pagetual-nextSwitch svg {
  2614. width: 30px;
  2615. height: 30px;
  2616. vertical-align: middle;
  2617. fill: #161616;
  2618. overflow: hidden;
  2619. }
  2620. #pagetual-nextSwitch button:hover {
  2621. transform: scale(1.2);
  2622. }
  2623. `;
  2624. _GM_addStyle(cssText);
  2625. let frame = document.createElement("div");
  2626. frame.id = "pagetual-nextSwitch";
  2627. frame.innerHTML = createHTML(`
  2628. <div class="title">${i18n("nextSwitch")}</div>
  2629. <button type="button" class="closeSwitch">
  2630. <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2754">
  2631. <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">
  2632. </path>
  2633. </svg>
  2634. </button>
  2635. <div class="group"></div>
  2636. `);
  2637. let group = frame.querySelector(".group");
  2638. let closeBtn = frame.querySelector(".closeSwitch");
  2639. closeBtn.addEventListener("click", e => {
  2640. self.close();
  2641. }, true);
  2642. this.frame = frame;
  2643. let currentSpan;
  2644. ruleParser.curSiteRule.nextLink.forEach((link, i) => {
  2645. let span = document.createElement("span");
  2646. let target = getElement(link, document);
  2647. let index = "<b>" + (i + 1) + "</b>: ";
  2648. if (target) {
  2649. let targetInner = target.innerText.trim();
  2650. span.innerHTML = index + (targetInner || link);
  2651. } else {
  2652. span.innerHTML = index + "Not Found";
  2653. }
  2654. span.title = link;
  2655. span.addEventListener("click", e => {
  2656. if (currentSpan) currentSpan.classList.remove("current");
  2657. span.classList.add("current");
  2658. currentSpan = span;
  2659. nextIndex = i;
  2660. storage.setItem("nextSwitch_" + location.host, nextIndex === 0 ? "" : nextIndex);
  2661. ruleParser.curUrl += "#pagetual";
  2662. ruleParser.oldUrl = ruleParser.curUrl;
  2663. autoLoadNum = -1;
  2664. if (!ruleParser.nextLinkHref) {
  2665. isLoading = false;
  2666. }
  2667. ruleParser.getNextLink(ruleParser.pageDoc || document);
  2668. self.close();
  2669. }, true);
  2670. if (i == nextIndex) {
  2671. span.classList.add("current");
  2672. currentSpan = span;
  2673. }
  2674. group.appendChild(span);
  2675. });
  2676. }
  2677.  
  2678. start() {
  2679. document.documentElement.appendChild(this.frame);
  2680. }
  2681.  
  2682. close() {
  2683. if (this.frame.parentNode) this.frame.parentNode.removeChild(this.frame);
  2684. }
  2685. }
  2686.  
  2687. class Picker {
  2688. static picker;
  2689. constructor() {
  2690. this.init();
  2691. }
  2692.  
  2693. static getInstance() {
  2694. if (!Picker.picker) {
  2695. Picker.picker = new Picker();
  2696. }
  2697. return Picker.picker;
  2698. }
  2699.  
  2700. init() {
  2701. let self = this;
  2702. this.signList = [];
  2703. let cssText = `
  2704. body.pagetual-picker,
  2705. body.pagetual-picker *:hover,
  2706. body.pagetual-picker a:hover {
  2707. cursor: crosshair !important;
  2708. }
  2709. #pagetual-picker {
  2710. position: fixed;
  2711. top: 10px;
  2712. left: calc(50% - 178px);
  2713. background: aliceblue;
  2714. padding: 10px;
  2715. border-radius: 5px;
  2716. text-align: center;
  2717. opacity: 0.95;
  2718. color: #161616;
  2719. z-index: 2147483647;
  2720. font-size: 16px;
  2721. box-shadow: rgb(0 0 0) 0px 0px 10px;
  2722. }
  2723. #pagetual-picker * {
  2724. margin: 0;
  2725. padding: 0;
  2726. }
  2727. #pagetual-picker>.title {
  2728. margin: -5px 45px 10px 45px;
  2729. font-size: 20px;
  2730. font-weight: bold;
  2731. cursor: move;
  2732. border-bottom: 1px solid black;
  2733. user-select: none;
  2734. color: orangered;
  2735. font-family: Times New Roman;
  2736. }
  2737. #pagetual-picker button {
  2738. background: none;
  2739. border: none;
  2740. vertical-align: top;
  2741. transition: transform .15s ease-in-out;
  2742. float: right;
  2743. cursor: pointer;
  2744. }
  2745. #pagetual-picker button:hover {
  2746. transform: scale(1.2);
  2747. }
  2748. #pagetual-picker>.closePicker {
  2749. position: absolute;
  2750. top: 3px;
  2751. right: 10px;
  2752. }
  2753. #pagetual-picker>.logoToHome {
  2754. position: absolute;
  2755. top: 3px;
  2756. left: 10px;
  2757. }
  2758. #pagetual-picker .selector{
  2759. display: inline-block;
  2760. width: 290px;
  2761. height: 20px;
  2762. max-width: calc(65vw - 50px);
  2763. padding: 6px 12px;
  2764. font-size: 16px;
  2765. font-weight: 400;
  2766. line-height: 1.5;
  2767. color: #495057;
  2768. background-color: #fff;
  2769. background-clip: padding-box;
  2770. border: 1px solid #ced4da;
  2771. border-radius: 4px;
  2772. transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;
  2773. box-sizing: content-box;
  2774. }
  2775. #pagetual-picker .selector:focus {
  2776. color: #495057;
  2777. background-color: #fff;
  2778. border-color: #80bdff;
  2779. outline: 0;
  2780. box-shadow: 0 0 0 3.2px rgb(0 123 255 / 25%);
  2781. }
  2782. #pagetual-picker [type=checkbox],
  2783. #pagetual-picker [type=radio] {
  2784. line-height: 20px;
  2785. height: 25px;
  2786. width: 25px;
  2787. margin-left: 5px;
  2788. vertical-align: middle;
  2789. appearance: auto;
  2790. display: inline-block;
  2791. }
  2792. #pagetual-picker label {
  2793. font-size: 18px;
  2794. line-height: 25px;
  2795. vertical-align: middle;
  2796. display: inline-block;
  2797. color: black;
  2798. }
  2799. #pagetual-picker .bottom {
  2800. text-align: left;
  2801. margin: 10px 0;
  2802. width: 100%;
  2803. }
  2804. #pagetual-picker .bottom>button {
  2805. float: right;
  2806. }
  2807. #pagetual-picker svg {
  2808. width: 30px;
  2809. height: 30px;
  2810. vertical-align: middle;
  2811. fill: #161616;
  2812. overflow: hidden;
  2813. }
  2814. #pagetual-picker .allpath {
  2815. font-size: 18px;
  2816. margin: 10px;
  2817. max-width: 350px;
  2818. word-break: break-all;
  2819. cursor: context-menu;
  2820. overflow: hidden;
  2821. max-height: 42px;
  2822. -moz-transition:max-height 1s ease-in;
  2823. -webkit-transition:max-height 1s ease-in;
  2824. transition:max-height 1s ease-in;
  2825. color: black;
  2826. }
  2827. #pagetual-picker .allpath:hover {
  2828. max-height: calc(100vh - 130px);
  2829. overflow: auto;
  2830. }
  2831. #pagetual-picker .allpath>span.path {
  2832. cursor: pointer;
  2833. }
  2834. #pagetual-picker .allpath>span.path:hover {
  2835. color: orangered;
  2836. }
  2837. #pagetual-picker .moreConfig {
  2838. display: flex;
  2839. justify-content: space-between;
  2840. border-top: 1px solid;
  2841. padding-top: 10px;
  2842. width: 100%;
  2843. }
  2844. #pagetual-picker .command {
  2845. width: 100%;
  2846. color: black!important;
  2847. text-align: center;
  2848. font-size: large;
  2849. margin-top: 10px;
  2850. }
  2851. #pagetual-picker .command:hover {
  2852. color: orangered;
  2853. }
  2854. `;
  2855. _GM_addStyle(cssText);
  2856. this.mainSignDiv = this.createSignDiv();
  2857. this.allSignDiv = [];
  2858. let frame = document.createElement("div");
  2859. frame.id = "pagetual-picker";
  2860. frame.innerHTML = createHTML(`
  2861. <button title="Pagetual" type="button" class="logoToHome">
  2862. <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>
  2863. </button>
  2864. <div class="title">${i18n("picker")}</div>
  2865. <button title="${i18n("closePicker")}" type="button" class="closePicker">
  2866. <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>
  2867. </button>
  2868. <div class="allpath" title="${i18n("switchSelector")}"></div>
  2869. <div>
  2870. <textarea class="selector" spellcheck="false" name="selector" placeholder="${i18n("pickerPlaceholder")}"></textarea>
  2871. <button id="check" title="${i18n("pickerCheck")}" type="button">
  2872. <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>
  2873. </button>
  2874. </div>
  2875. <div class="bottom">
  2876. <input name="xpath" id="checkbox_id" type="checkbox">
  2877. <label for="checkbox_id">XPath</label>
  2878. <button id="edit" title="${i18n("gotoEdit")}" type="button">
  2879. <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" style="color: orangered;fill: orangered;">
  2880. <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">
  2881. </path>
  2882. </svg>
  2883. </button>
  2884. </div>
  2885. <div class="moreConfig">
  2886. <div title="${i18n('forceStateIframe')}">
  2887. <input name="forceState" id="forceStateIframe" type="radio">
  2888. <label for="forceStateIframe">Iframe</label>
  2889. </div>
  2890. <div title="${i18n('forceStateDynamic')}">
  2891. <input name="forceState" id="forceStateDynamic" type="radio">
  2892. <label for="forceStateDynamic">Dynamic</label>
  2893. </div>
  2894. <div title="${i18n('forceStateDisable')}">
  2895. <input name="forceState" id="forceStateDisable" type="radio">
  2896. <label for="forceStateDisable">Disable</label>
  2897. </div>
  2898. </div>
  2899. <button id="nextSwitch" class="command" title="${i18n("nextSwitch")}" type="button">${i18n("nextSwitch")}</button>
  2900. <button id="loadNow" class="command" title="${i18n("loadNow")}" type="button">${i18n("loadNow")}</button>
  2901. `);
  2902. let forceStateIframe = frame.querySelector("#forceStateIframe");//forceState 1 禁用 2 强嵌 3 动态
  2903. let forceStateDynamic = frame.querySelector("#forceStateDynamic");
  2904. let forceStateDisable = frame.querySelector("#forceStateDisable");
  2905. let clickRadio = e => {
  2906. let radio = e.currentTarget.querySelector('input');
  2907. if (radio.checked) {
  2908. forceState = "";
  2909. } else {
  2910. switch (radio.id) {
  2911. case "forceStateIframe":
  2912. forceState = 2;
  2913. break;
  2914. case "forceStateDynamic":
  2915. forceState = 3;
  2916. break;
  2917. case "forceStateDisable":
  2918. forceState = 1;
  2919. break;
  2920. default:
  2921. return;
  2922. }
  2923. }
  2924. storage.setItem("forceState_"+location.host, forceState);
  2925. self.close();
  2926. location.reload();
  2927. };
  2928. forceStateIframe.parentNode.addEventListener("mousedown", clickRadio);
  2929. forceStateDynamic.parentNode.addEventListener("mousedown", clickRadio);
  2930. forceStateDisable.parentNode.addEventListener("mousedown", clickRadio);
  2931. if (forceState == 1) forceStateDisable.checked = true;
  2932. else if (forceState == 2) forceStateIframe.checked = true;
  2933. else if (forceState == 3) forceStateDynamic.checked = true;
  2934. let closeBtn = frame.querySelector(".closePicker");
  2935. let homeBtn = frame.querySelector(".logoToHome");
  2936. let title = frame.querySelector(".title");
  2937. let allpath = frame.querySelector(".allpath");
  2938. let selectorInput = frame.querySelector(".selector");
  2939. let xpath = frame.querySelector("#checkbox_id");
  2940. let checkBtn = frame.querySelector("#check");
  2941. let editBtn = frame.querySelector("#edit");
  2942. let nextSwitch = frame.querySelector("#nextSwitch");
  2943. let loadNow = frame.querySelector("#loadNow");
  2944. nextSwitch.addEventListener("click", e => {
  2945. self.close();
  2946. NextSwitch.getInstance().start();
  2947. }, true);
  2948. loadNow.addEventListener("click", e => {
  2949. self.close();
  2950. let loadNum=window.prompt(i18n("loadConfirm"), "1");
  2951. if(loadNum==="" || loadNum===null)return;
  2952. autoLoadNum=Math.abs(parseInt(loadNum));
  2953. nextPage();
  2954. }, true);
  2955. closeBtn.addEventListener("click", e => {
  2956. self.close();
  2957. }, true);
  2958. homeBtn.addEventListener("click", e => {
  2959. _GM_openInTab(configPage[0], {active: true});
  2960. }, true);
  2961. let moving = false;
  2962. let moveHanlder = e => {
  2963. frame.style.left = e.clientX - 200 + "px";
  2964. frame.style.top = e.clientY - 15 + "px";
  2965. e.stopPropagation();
  2966. e.preventDefault();
  2967. };
  2968. let upHanlder = e => {
  2969. moving = false;
  2970. document.removeEventListener("mousemove", moveHanlder, true);
  2971. title.removeEventListener("mouseup", upHanlder, true);
  2972. e.stopPropagation();
  2973. e.preventDefault();
  2974. };
  2975. title.addEventListener("mousedown", e => {
  2976. moving = true;
  2977. document.addEventListener("mousemove", moveHanlder, true);
  2978. title.addEventListener("mouseup", upHanlder, true);
  2979. });
  2980. frame.addEventListener("mouseenter", e => {
  2981. if (moving) return;
  2982. if (self.mainSignDiv.parentNode) self.mainSignDiv.parentNode.removeChild(self.mainSignDiv);
  2983. self.checkInputSelector();
  2984. });
  2985. frame.addEventListener("mouseleave", e => {
  2986. if (moving) return;
  2987. document.body.appendChild(self.mainSignDiv);
  2988. self.clearSigns();
  2989. });
  2990. checkBtn.addEventListener("click", e => {
  2991. self.checkInputSelector();
  2992. if (this.selectorInput.value) _GM_setClipboard(this.selectorInput.value);
  2993. });
  2994. xpath.addEventListener("click", e => {
  2995. if (!selectorInput.value) {
  2996. self.setSelectorDiv("");
  2997. return;
  2998. }
  2999. let element = getElement(selectorInput.value, document);
  3000. let selector = self.getSelectorFromEle(element);
  3001. self.setSelectorDiv(selector);
  3002. selectorInput.value = selector;
  3003. });
  3004. editBtn.addEventListener("click", e => {
  3005. let editTemp;
  3006. if (ruleParser.curSiteRule.url && !ruleParser.curSiteRule.singleUrl) {
  3007. editTemp = ruleParser.curSiteRule;
  3008. } else {
  3009. editTemp = {
  3010. name: document.title,
  3011. url: "^" + location.origin.replace(/^https?/, "https?").replace(/\./g,"\\.") + "/"
  3012. };
  3013. }
  3014. if (selectorInput.value) {
  3015. editTemp.pageElement = selectorInput.value;
  3016. }
  3017. delete editTemp.from;
  3018. delete editTemp.type;
  3019. delete editTemp.updatedAt;
  3020. rulesData.editTemp = editTemp;
  3021. storage.setItem("rulesData", rulesData);
  3022. _GM_openInTab(configPage[0], {active: true});
  3023. });
  3024. this.frame = frame;
  3025. this.xpath = xpath;
  3026. this.allpath = allpath;
  3027. this.selectorInput = selectorInput;
  3028. this.nextSwitch = nextSwitch;
  3029. this.loadNow = loadNow;
  3030. this.moveHandler = e => {
  3031. if (e.target === document) return;
  3032. self.adjustSignDiv(self.mainSignDiv, self.getTarget(e.target));
  3033. };
  3034. this.clickHandler = e => {
  3035. if (self.inPicker) {
  3036. e.stopPropagation();
  3037. e.preventDefault();
  3038. }
  3039. let target = self.getTarget(e.target);
  3040. let selector = self.getSelectorFromEle(target);
  3041. self.setSelectorDiv(selector);
  3042. selectorInput.value = selector;
  3043. };
  3044. }
  3045.  
  3046. getTarget(ele) {
  3047. while (ele.parentNode && (ele.scrollWidth === 0 || ele.scrollHeight === 0)) {
  3048. ele = ele.parentNode;
  3049. }
  3050. return ele;
  3051. }
  3052.  
  3053. close() {
  3054. this.clearSigns();
  3055. if (this.frame.parentNode) this.frame.parentNode.removeChild(this.frame);
  3056. if (this.mainSignDiv.parentNode) this.mainSignDiv.parentNode.removeChild(this.mainSignDiv);
  3057. document.body.classList.remove("pagetual-picker");
  3058. document.body.removeEventListener("mousemove", this.moveHandler, true);
  3059. document.body.removeEventListener("click", this.clickHandler, true);
  3060. this.inPicker = false;
  3061. }
  3062.  
  3063. setImportant(ele, prop, value) {
  3064. ele.style.setProperty(prop, value, "important");
  3065. }
  3066.  
  3067. createSignDiv() {
  3068. let signDiv = document.createElement("div");
  3069. this.setImportant(signDiv, "position", "absolute");
  3070. this.setImportant(signDiv, "pointer-events", "none");
  3071. this.setImportant(signDiv, "z-index", "2147483647");
  3072. this.setImportant(signDiv, "background", "rgba(120, 170, 210, 0.6)");
  3073. this.setImportant(signDiv, "transition", "all 0.15s ease-out");
  3074. this.setImportant(signDiv, "box-shadow", "rgb(0 0 0) 0px 0px 3px 0px");
  3075. return signDiv;
  3076. }
  3077.  
  3078. adjustSignDiv(div, target) {
  3079. let rect = target.getBoundingClientRect();
  3080. this.setImportant(div, "width", rect.width + "px");
  3081. this.setImportant(div, "height", rect.height + "px");
  3082. this.setImportant(div, "left", rect.left + window.scrollX + "px");
  3083. this.setImportant(div, "top", rect.top + window.scrollY + "px");
  3084. }
  3085.  
  3086. getSelectorFromEle(ele) {
  3087. return this.xpath.checked ? createXPathFromElement(ele) : geneSelector(ele, true);
  3088. }
  3089.  
  3090. setSelectorDiv(selector) {
  3091. let self = this;
  3092. this.allpath.innerHTML = createHTML("");
  3093. if (!selector) return;
  3094. if (this.xpath.checked) {
  3095. let span = document.createElement("span");
  3096. span.innerText = selector;
  3097. span.addEventListener("click", e => {
  3098. self.selectorInput.value = selector;
  3099. self.checkInputSelector();
  3100. }, true);
  3101. this.allpath.appendChild(span);
  3102. } else {
  3103. selector.split(">").forEach((item, index) => self.geneSelectorItem(item, index));
  3104. }
  3105. }
  3106.  
  3107. geneSelectorItem(item, index) {
  3108. let self = this;
  3109. item = item.trim();
  3110. if (!item) return;
  3111. if (index !== 0) {
  3112. let span = document.createElement("span");
  3113. span.innerText = " > ";
  3114. this.allpath.appendChild(span);
  3115. }
  3116. let span = document.createElement("span");
  3117. span.className = "path";
  3118. span.innerText = item;
  3119. span.addEventListener("click", e => {
  3120. let selector = "";
  3121. let target = e.target;
  3122. while (target) {
  3123. selector = target.innerText + selector;
  3124. target = target.previousElementSibling;
  3125. }
  3126. self.selectorInput.value = selector;
  3127. self.checkInputSelector();
  3128. }, true);
  3129. this.allpath.appendChild(span);
  3130. }
  3131.  
  3132. checkInputSelector() {
  3133. let self = this;
  3134. this.clearSigns();
  3135. if (!this.selectorInput.value) return;
  3136. let eles = getAllElements(this.selectorInput.value, document);
  3137. if (eles && eles.length > 0) {
  3138. eles.forEach(ele => {
  3139. let sign = self.createSignDiv();
  3140. document.body.appendChild(sign);
  3141. self.adjustSignDiv(sign, ele);
  3142. self.signList.push(sign);
  3143. });
  3144. }
  3145. }
  3146.  
  3147. clearSigns() {
  3148. this.signList.forEach(sign => {
  3149. if (sign.parentNode) sign.parentNode.removeChild(sign);
  3150. });
  3151. this.signList = [];
  3152. }
  3153.  
  3154. start() {
  3155. if (this.inPicker) return;
  3156. this.inPicker = true;
  3157. document.documentElement.appendChild(this.frame);
  3158. document.body.appendChild(this.mainSignDiv);
  3159. document.body.classList.add("pagetual-picker");
  3160.  
  3161. document.body.addEventListener("mousemove", this.moveHandler, true);
  3162. document.body.addEventListener("click", this.clickHandler, true);
  3163. this.xpath.checked = isXPath(ruleParser.curSiteRule.pageElement);
  3164.  
  3165. this.loadNow.style.display = ruleParser.nextLinkHref ? "block" : "none";
  3166. if (ruleParser.curSiteRule.nextLink && Array && Array.isArray && Array.isArray(ruleParser.curSiteRule.nextLink)) {
  3167. this.nextSwitch.style.display = "block";
  3168. } else {
  3169. this.nextSwitch.style.display = "none";
  3170. }
  3171.  
  3172. let pageElementSel=ruleParser.curSiteRule.pageElement || "";
  3173. if(Array && Array.isArray && Array.isArray(pageElementSel)){
  3174. pageElementSel=pageElementSel[nextIndex<pageElementSel.length?nextIndex:0];
  3175. }
  3176. this.setSelectorDiv(pageElementSel);
  3177. }
  3178. }
  3179.  
  3180. function createEdit(){
  3181. var options = {
  3182. mode: 'code',
  3183. modes: ['code', 'tree'],
  3184. templates: [
  3185. {
  3186. text: 'New site',
  3187. title: 'Insert a new site',
  3188. className: 'jsoneditor-type-object',
  3189. field: 'SiteTemplate',
  3190. value: {
  3191. 'name': 'Site name',
  3192. 'url': 'Site url'
  3193. }
  3194. }
  3195. ],
  3196. schema: {
  3197. "title": "Sites data",
  3198. "description": "Object containing site config",
  3199. "type": "array",
  3200. "items": {
  3201. "type": 'object',
  3202. "properties": {
  3203. "name": {
  3204. "title": "Site Name",
  3205. "description": "The site's name.",
  3206. "examples": [
  3207. "Google"
  3208. ],
  3209. "type": "string"
  3210. },
  3211. "url": {
  3212. "title": "Site Url",
  3213. "description": "The Regexp of site's url.",
  3214. "examples": [
  3215. "^https:\/\/yande\\.re\/"
  3216. ],
  3217. "type": "string"
  3218. }
  3219. },
  3220. "required": ["name", "url"]
  3221. }
  3222. }
  3223. };
  3224. var container = document.getElementById("jsoneditor");
  3225. container.style.height = '800px';
  3226. container.innerHTML = "";
  3227. var editor = new JSONEditor(container, options);
  3228. editor.set(ruleParser.customRules);
  3229. document.querySelector("#saveBtn").onclick=e=>{
  3230. try{
  3231. storage.setItem("hpRules", []);
  3232. storage.setItem("smartRules", []);
  3233. let customRules=editor.get();
  3234. if(!customRules){
  3235. storage.setItem("customRules", "");
  3236. }else{
  3237. if(Array && Array.isArray && !Array.isArray(customRules)){
  3238. showTips("Rules must be a Array!");
  3239. return;
  3240. }
  3241. debug(customRules);
  3242. storage.setItem("customRules", customRules);
  3243. }
  3244. }catch(e){
  3245. debug(e);
  3246. showTips("JSON error, check again!");
  3247. return;
  3248. }
  3249. showTips("Edit successfully");
  3250. };
  3251. }
  3252.  
  3253. function initConfig(){
  3254. initView();
  3255. try{
  3256. if(_unsafeWindow.initedPagetual){
  3257. if(ruleImportUrlReg.test(location.href)){
  3258. showTips(i18n('duplicate'));
  3259. }
  3260. return true;
  3261. }
  3262. _unsafeWindow.initedPagetual=true;
  3263. }catch(e){}
  3264. _GM_registerMenuCommand(i18n(forceState==1?"enable":"disableSite"), ()=>{
  3265. forceState=(forceState==1?0:1);
  3266. storage.setItem("forceState_"+location.host, forceState);
  3267. showTips(i18n(forceState==1?"disableSiteTips":"enableSiteTips"));
  3268. if(!ruleParser.curSiteRule.url) location.reload();
  3269. });
  3270. _GM_registerMenuCommand(i18n("update"), ()=>{
  3271. updateRules(()=>{
  3272. showTips(i18n("updateSucc"));
  3273. location.reload();
  3274. },(rule,err)=>{
  3275. showTips("Update "+rule.url+" rules fail!");
  3276. });
  3277. showTips(i18n("beginUpdate"));
  3278. });
  3279. if(guidePage.test(location.href)){
  3280. if(typeof JSONEditor !== 'undefined'){
  3281. createEdit();
  3282. }else{
  3283. window.onload = e => {
  3284. createEdit();
  3285. }
  3286. }
  3287. return true;
  3288. }
  3289. if(location.href.indexOf("PagetualGuide")!=-1) return true;
  3290. if(location.hostname==="pagetual.hoothin.com") return true;
  3291.  
  3292. var configCon,insertPos;
  3293. var noRules=!rulesData.urls || rulesData.urls.length===0;
  3294.  
  3295. let inConfig = false;
  3296. for (let i = 0; i < configPage.length; i++) {
  3297. if (configPage[i] == location.href) {
  3298. inConfig = true;
  3299. break;
  3300. }
  3301. }
  3302. if(ruleImportUrlReg.test(location.href) || inConfig){
  3303. let importing = false;
  3304. if(noRules){
  3305. setTimeout(() => {
  3306. if (!importing) showTips(i18n("firstAlert"));
  3307. }, 3000);
  3308. setTimeout(() => {
  3309. if (!importing) showTips(i18n("firstAlert"));
  3310. }, 6000);
  3311. showTips(i18n("firstAlert"));
  3312. }
  3313. let createImportBtn = () => {
  3314. let importBtn = document.createElement("button");
  3315. importBtn.innerText = i18n("import");
  3316. importBtn.style.marginTop = "100px";
  3317. importBtn.style.float = "right";
  3318. importBtn.style.position = "relative";
  3319. importBtn.style.display = "block";
  3320. importBtn.style.fontSize = "20px";
  3321. importBtn.addEventListener("click", e => {
  3322. let parentNode = importBtn.parentNode;
  3323. if (!parentNode) return;
  3324. parentNode.removeChild(importBtn);
  3325. try {
  3326. let rules=parentNode.innerText.trim();
  3327. let isContent=/['"]name['"]/i.test(rules);
  3328. if(isContent){
  3329. let ruleList=JSON.parse(`[${rules}]`);
  3330. for(let i in ruleList){
  3331. let hasRule = false;
  3332. let r = ruleList[i];
  3333. for(let j in ruleParser.customRules){
  3334. if(ruleParser.customRules[j].name == r.name){
  3335. ruleParser.customRules[j] = r;
  3336. hasRule = true;
  3337. break;
  3338. }
  3339. }
  3340. if(!hasRule)ruleParser.customRules.push(r);
  3341. }
  3342. storage.setItem("customRules", ruleParser.customRules);
  3343. storage.setItem("hpRules", []);
  3344. storage.setItem("smartRules", []);
  3345. showTips(i18n("importSucc"));
  3346. }else{
  3347. rules=rules.split("\n");
  3348. let diff=false;
  3349. for(let c=0;c<rules.length;c++){
  3350. let urlArr=rules[c].split("|"),url,type=1;
  3351. if(urlArr.length==1){
  3352. url=urlArr[0].trim();
  3353. if(!/^http/.test(url)){
  3354. showTips("Wrong url, check again!");
  3355. return;
  3356. }
  3357. }else if(urlArr.length==2){
  3358. type=urlArr[0].trim();
  3359. url=urlArr[1].trim();
  3360. if(!/^http/.test(url)){
  3361. showTips("Wrong url, check again!");
  3362. return;
  3363. }
  3364. }else{
  3365. break;
  3366. }
  3367. let maxId=0,hasUrl=false;
  3368. if(!rulesData.urls){
  3369. rulesData.urls=[];
  3370. maxId=1;
  3371. }else{
  3372. rulesData.urls.forEach(u=>{
  3373. if(maxId<u.id){
  3374. maxId=u.id;
  3375. }
  3376. if(u.url==url){
  3377. hasUrl=true;
  3378. }
  3379. });
  3380. if(hasUrl)break;
  3381. }
  3382. diff=true;
  3383. if(!rulesData.sort)rulesData.sort=[1];
  3384. rulesData.urls.push({id:maxId+1,url:url,type:type});
  3385. rulesData.sort.unshift(maxId+1);
  3386. }
  3387. if(!diff){
  3388. showTips("Already exists!");
  3389. return;
  3390. }
  3391. storage.setItem("rulesData", rulesData);
  3392.  
  3393. if(rulesData.urls)ruleUrls=ruleUrls.concat(rulesData.urls);
  3394. if(rulesData.sort){
  3395. let urls=[];
  3396. rulesData.sort.forEach(id=>{
  3397. for(let s=0;s<ruleUrls.length;s++){
  3398. if(id==ruleUrls[s].id){
  3399. urls.push(ruleUrls[s]);
  3400. break;
  3401. }
  3402. }
  3403. });
  3404. ruleUrls=urls;
  3405. }
  3406. updateRules(()=>{
  3407. showTips(i18n("updateSucc"));
  3408. location.reload();
  3409. },(rule,err)=>{
  3410. showTips("Update "+rule.url+" rules fail!");
  3411. });
  3412. importing = true;
  3413. showTips(i18n("beginUpdate"));
  3414. }
  3415. } catch (e) {
  3416. _GM_notification(e.toString());
  3417. }
  3418. });
  3419. return importBtn;
  3420. };
  3421. [].forEach.call(document.querySelectorAll('pre[name=pagetual],pre[name=user-content-pagetual]'), pre => {
  3422. let importBtn = createImportBtn();
  3423. let clientHeight = 35 - pre.clientHeight;
  3424. if (clientHeight > -20) clientHeight = -20;
  3425. importBtn.style.marginTop = `${clientHeight}px`;
  3426. pre.appendChild(importBtn);
  3427. });
  3428. document.addEventListener("mouseover", e => {
  3429. if (e.target.tagName === "PRE") {
  3430. let nameAttr=e.target.getAttribute("name");
  3431. if(nameAttr=="pagetual" || nameAttr=="user-content-pagetual"){
  3432. if (e.target.querySelector('button')) return;
  3433. let importBtn = createImportBtn();
  3434. let clientHeight = 35 - e.target.clientHeight;
  3435. if (clientHeight > -20) clientHeight = -20;
  3436. importBtn.style.marginTop = `${clientHeight}px`;
  3437. e.target.appendChild(importBtn);
  3438. }
  3439. }
  3440. });
  3441.  
  3442. if(inConfig){
  3443. _GM_addStyle(`
  3444. p>span:nth-child(1),p>span:nth-child(2),p>span:nth-child(3){
  3445. cursor: pointer;
  3446. user-select: none;
  3447. }
  3448. p>span:nth-child(1):hover,p>span:nth-child(2):hover,p>span:nth-child(3):hover{
  3449. color:red;
  3450. }
  3451. .updateDate{
  3452. cursor: pointer;
  3453. user-select: none;
  3454. }
  3455. .updateDate:hover{
  3456. color:red;
  3457. }
  3458. input[type=number]::-webkit-inner-spin-button,
  3459. input[type=number]::-webkit-outer-spin-button {
  3460. -webkit-appearance: none;
  3461. margin: 0;
  3462. }
  3463. input[type=number] {
  3464. -moz-appearance:textfield;
  3465. }
  3466. `);
  3467. document.querySelector("[name='user-content-click2import'],[name='click2import']").innerText=i18n("click2ImportRule")
  3468. configCon=document.querySelector(".markdown-body");
  3469. insertPos=configCon.querySelector("hr");
  3470.  
  3471. if(!noRules){
  3472. document.querySelector("pre[name='user-content-pagetual'],pre[name='pagetual']").style.display="none";
  3473. document.querySelector("p[name='user-content-click2import'],p[name='click2import']").style.display="none";
  3474. }
  3475. }else return true;
  3476. }else return false;
  3477. class Rulebar {
  3478. init(ruleUrl){
  3479. this.ruleUrl=ruleUrl;
  3480. this.item=document.createElement("p");
  3481. this.item.dataset.id=this.ruleUrl.id;
  3482. let url=document.createElement("span");
  3483. url.innerHTML=ruleUrl.url;
  3484. let up=document.createElement("span");
  3485. up.innerHTML="↑ ";
  3486. up.title=i18n("sortTitle");
  3487. let down=document.createElement("span");
  3488. down.innerHTML="↓ ";
  3489. down.title=i18n("sortTitle");
  3490. let del=document.createElement("span");
  3491. del.innerHTML="× ";
  3492. up.onclick=e=>{
  3493. this.moveUp();
  3494. };
  3495. down.onclick=e=>{
  3496. this.moveDown();
  3497. };
  3498. del.onclick=e=>{
  3499. this.del();
  3500. };
  3501. this.item.appendChild(up);
  3502. this.item.appendChild(down);
  3503. this.item.appendChild(del);
  3504. this.item.appendChild(url);
  3505. configCon.insertBefore(this.item, insertPos);
  3506. }
  3507. saveSort(){
  3508. let sort=[];
  3509. [].forEach.call(this.item.parentNode.querySelectorAll("p[data-id]"), i=>{
  3510. sort.push(i.dataset.id);
  3511. });
  3512. rulesData.sort=sort;
  3513. storage.setItem("rulesData", rulesData);
  3514. }
  3515. moveUp(){
  3516. let preE=this.item.previousElementSibling;
  3517. if(preE.tagName=="P" && preE.children.length>1){
  3518. this.item.parentNode.insertBefore(this.item,preE);
  3519. this.saveSort();
  3520. }
  3521. }
  3522. moveDown(){
  3523. let nextE=this.item.nextElementSibling;
  3524. if(nextE.tagName=="P" && nextE.children.length>1){
  3525. this.item.parentNode.insertBefore(nextE,this.item);
  3526. this.saveSort();
  3527. }
  3528. }
  3529. del(){
  3530. if(this.ruleUrl.id<2){
  3531. showTips(i18n("cantDel"));
  3532. }else if(window.confirm(i18n("confirmDel"))){
  3533. for(let u=0;u<rulesData.urls.length;u++){
  3534. if(this.ruleUrl.id==rulesData.urls[u].id){
  3535. rulesData.urls.splice(u,1);
  3536. break;
  3537. }
  3538. }
  3539. for(let u=0;u<ruleUrls.length;u++){
  3540. if(this.ruleUrl.id==ruleUrls[u].id){
  3541. ruleUrls.splice(u,1);
  3542. break;
  3543. }
  3544. }
  3545. for(let u=0;u<rulesData.sort.length;u++){
  3546. if(this.ruleUrl.id==rulesData.sort[u]){
  3547. rulesData.sort.splice(u,1);
  3548. break;
  3549. }
  3550. }
  3551. storage.setItem("rulesData", rulesData);
  3552. ruleParser.rules=ruleParser.rules.filter(item=>{return item.from!=this.ruleUrl.id});
  3553. storage.setItem("rules", ruleParser.rules);
  3554. this.item.parentNode.removeChild(this.item);
  3555. //location.reload();
  3556. }
  3557. }
  3558. }
  3559. let updateP=document.createElement("p"),i=0;
  3560. let now=new Date().getTime(),inUpdate=false;
  3561.  
  3562.  
  3563. let pastDate=(new Date(updateDate)).toString(),passStr;
  3564. let passTime=(now-updateDate)/1000;
  3565. if(isNaN(passTime)){
  3566. passStr=i18n("firstUpdate");
  3567. }else if(passTime<60){
  3568. passStr=i18n("passSec", parseInt(passTime))+" 👆 "+i18n("click2update");
  3569. }else if(passTime<60*60){
  3570. passStr=i18n("passMin", parseInt(passTime/60))+" 👆 "+i18n("click2update");
  3571. }else if(passTime<60*60*24){
  3572. passStr=i18n("passHour", parseInt(passTime/3600))+" 👆 "+i18n("click2update");
  3573. }else{
  3574. passStr=i18n("passDay", parseInt(passTime/86400))+" 👆 "+i18n("click2update");
  3575. }
  3576.  
  3577.  
  3578. updateP.className="updateDate";
  3579. updateP.innerHTML=passStr;
  3580. updateP.title=i18n("update")+" - "+pastDate;
  3581. updateP.onclick=e=>{
  3582. updateRules(()=>{
  3583. showTips(i18n("updateSucc"));
  3584. updateP.innerHTML=i18n("passSec", 0);
  3585. updateP.title=i18n("update");
  3586. },(rule,err)=>{
  3587. showTips("Update "+rule.url+" rules fail!");
  3588. });
  3589. showTips(i18n("beginUpdate"));
  3590. };
  3591. configCon.insertBefore(updateP, insertPos);
  3592. if(ruleUrls){
  3593. ruleUrls.forEach(ruleUrl=>{
  3594. var rulebar=new Rulebar();
  3595. rulebar.init(ruleUrl);
  3596. });
  3597. }
  3598. let customUrlsTitle=document.createElement("h2");
  3599. customUrlsTitle.innerHTML=i18n("customUrls");
  3600. configCon.insertBefore(customUrlsTitle, insertPos);
  3601. let customUrlsInput=document.createElement("textarea");
  3602. customUrlsInput.style.width="100%";
  3603. customUrlsInput.placeholder="http://wedata.net/databases/AutoPagerize/items_all.json";
  3604. customUrlsInput.spellcheck=false;
  3605. configCon.insertBefore(customUrlsInput, insertPos);
  3606.  
  3607. let btns=document.createElement("div");
  3608. btns.style.display="flex";
  3609. configCon.insertBefore(btns, insertPos);
  3610. let upBtnImg=document.createElement("div");
  3611. upBtnImg.style.width="50%";
  3612. let upBtnImgTitle=document.createElement("h2");
  3613. upBtnImgTitle.style.whiteSpace="nowrap";
  3614. upBtnImgTitle.style.overflow="auto";
  3615. upBtnImgTitle.innerHTML=i18n("upBtnImg");
  3616. upBtnImg.appendChild(upBtnImgTitle);
  3617. let upBtnImgInput=document.createElement("input");
  3618. upBtnImgInput.style.width="100%";
  3619. upBtnImgInput.placeholder="data:image/png;base64,UpBtn";
  3620. upBtnImgInput.value=rulesData.upBtnImg||'';
  3621. upBtnImgInput.spellcheck=false;
  3622. upBtnImg.appendChild(upBtnImgInput);
  3623. btns.appendChild(upBtnImg);
  3624.  
  3625. let downBtnImg=document.createElement("div");
  3626. downBtnImg.style.width="50%";
  3627. let downBtnImgTitle=document.createElement("h2");
  3628. downBtnImgTitle.style.whiteSpace="nowrap";
  3629. downBtnImgTitle.style.overflow="auto";
  3630. downBtnImgTitle.innerHTML=i18n("downBtnImg");
  3631. downBtnImg.appendChild(downBtnImgTitle);
  3632. let downBtnImgInput=document.createElement("input");
  3633. downBtnImgInput.style.width="100%";
  3634. downBtnImgInput.placeholder="data:image/png;base64,DownBtn";
  3635. downBtnImgInput.value=rulesData.downBtnImg||'';
  3636. downBtnImgInput.spellcheck=false;
  3637. downBtnImg.appendChild(downBtnImgInput);
  3638. btns.appendChild(downBtnImg);
  3639.  
  3640. let otherBtns=document.createElement("div");
  3641. otherBtns.style.display="flex";
  3642. configCon.insertBefore(otherBtns, insertPos);
  3643. let loadingText=document.createElement("div");
  3644. loadingText.style.width="100%";
  3645. let loadingTextTitle=document.createElement("h2");
  3646. loadingTextTitle.style.whiteSpace="nowrap";
  3647. loadingTextTitle.style.overflow="auto";
  3648. loadingTextTitle.innerHTML=i18n("loadingTextTitle");
  3649. loadingText.appendChild(loadingTextTitle);
  3650. let loadingTextInput=document.createElement("input");
  3651. loadingTextInput.value=rulesData.loadingText||'';
  3652. loadingTextInput.placeholder=i18n("loadingText");
  3653. loadingTextInput.style.width="100%";
  3654. loadingTextInput.style.margin="0";
  3655. loadingTextInput.spellcheck=false;
  3656. loadingText.appendChild(loadingTextInput);
  3657. otherBtns.appendChild(loadingText);
  3658.  
  3659. let opacity=document.createElement("div");
  3660. let opacityTitle=document.createElement("h2");
  3661. opacityTitle.style.whiteSpace="nowrap";
  3662. opacityTitle.style.overflow="visible";
  3663. opacityTitle.innerHTML=i18n("opacity");
  3664. opacity.appendChild(opacityTitle);
  3665. let opacityInput=document.createElement("input");
  3666. opacityInput.value=rulesData.opacity*100;
  3667. opacityInput.type="number";
  3668. opacityInput.style.width="110px";
  3669. opacityInput.style.margin="0";
  3670. opacityInput.placeholder=i18n("opacityPlaceholder");
  3671. opacityInput.spellcheck=false;
  3672. opacity.appendChild(opacityInput);
  3673. otherBtns.appendChild(opacity);
  3674.  
  3675. let pageElementCss=document.createElement("div");
  3676. pageElementCss.style.marginBottom="30px";
  3677. let pageElementCssTitle=document.createElement("h2");
  3678. pageElementCssTitle.innerHTML=i18n("pageElementCss");
  3679. pageElementCss.appendChild(pageElementCssTitle);
  3680. let pageElementCssInput=document.createElement("input");
  3681. pageElementCssInput.value=rulesData.pageElementCss||'';
  3682. pageElementCssInput.style.width="100%";
  3683. pageElementCssInput.style.margin="0";
  3684. pageElementCssInput.placeholder="font-size: xx-large;";
  3685. pageElementCssInput.spellcheck=false;
  3686. pageElementCss.appendChild(pageElementCssInput);
  3687. configCon.insertBefore(pageElementCss, insertPos);
  3688.  
  3689. let customCss=document.createElement("div");
  3690. customCss.style.marginBottom="50px";
  3691. let customCssTitle=document.createElement("h2");
  3692. customCssTitle.innerHTML=i18n("customCss");
  3693. customCss.appendChild(customCssTitle);
  3694. let customCssInput=document.createElement("textarea");
  3695. customCssInput.value=rulesData.customCss||'';
  3696. customCssInput.style.width="100%";
  3697. customCssInput.style.margin="0";
  3698. customCssInput.placeholder=".pagetual{\n}";
  3699. customCssInput.spellcheck=false;
  3700. customCss.appendChild(customCssInput);
  3701. configCon.insertBefore(customCss, insertPos);
  3702.  
  3703. let configTable=document.createElement("table");
  3704. configTable.style.width="100%";
  3705. let configTbody=document.createElement("tbody");
  3706. configTbody.style.width="100%";
  3707. configTbody.style.display="inline-table";
  3708. configTable.appendChild(configTbody);
  3709. configCon.insertBefore(configTable, insertPos);
  3710. function createCheckbox(innerText, val, tag, parentCheck, otherType) {
  3711. if (typeof val == 'undefined') val = "";
  3712. let title=document.createElement(tag || "h3");
  3713. title.innerHTML = innerText;
  3714. title.style.overflowWrap = "normal";
  3715. let input = document.createElement("input");
  3716. if (otherType === 'key') {
  3717. input.type = 'text';
  3718. input.setAttribute('readOnly', 'readonly');
  3719. input.addEventListener("keydown", e => {
  3720. if (e.key === 'Escape' || e.key === 'Backspace') input.value = '';
  3721. else input.value = e.key;
  3722. e.stopPropagation();
  3723. e.preventDefault();
  3724. });
  3725. } else {
  3726. input.type = otherType || "checkbox";
  3727. }
  3728. input.style.width = "30px";
  3729. input.style.height = "20px";
  3730. input.style.float = "left";
  3731. input.style.margin = "5px";
  3732. input.value = val;
  3733. input.checked = val;
  3734. let td = document.createElement("td");
  3735. td.appendChild(input);
  3736. if (parentCheck) {
  3737. title.style.margin = "0";
  3738. td.appendChild(title);
  3739. let parent = parentCheck.parentNode.nextElementSibling;
  3740. let tr = parent.querySelector("tr");
  3741. if (!tr) {
  3742. tr = document.createElement("tr");
  3743. parent.appendChild(tr);
  3744. }
  3745. tr.appendChild(td);
  3746. if (!parentCheck.checked) {
  3747. td.style.display = "none";
  3748. }
  3749. parentCheck.addEventListener("click", e => {
  3750. td.style.display = parentCheck.checked ? "" : "none";
  3751. });
  3752. } else {
  3753. let tr = document.createElement("tr");
  3754. tr.appendChild(td);
  3755. td = document.createElement("td");
  3756. td.appendChild(title);
  3757. tr.appendChild(td);
  3758. configTable.children[0].appendChild(tr);
  3759. }
  3760. return input;
  3761. }
  3762.  
  3763. let enableWhiteListInput=createCheckbox(i18n("autoRun"), rulesData.enableWhiteList!=true);
  3764. let enableDebugInput=createCheckbox(i18n("enableDebug"), rulesData.enableDebug!=false);
  3765. let enableHistoryInput=createCheckbox(i18n("enableHistory"), rulesData.enableHistory===true);
  3766. let enableHistoryAfterInsertInput=createCheckbox(i18n("enableHistoryAfterInsert"), rulesData.enableHistoryAfterInsert===true);
  3767. let openInNewTabInput=createCheckbox(i18n("openInNewTab"), rulesData.openInNewTab!=false);
  3768. let hideLoadingIconInput=createCheckbox(i18n("hideLoadingIcon"), rulesData.hideLoadingIcon!=false);
  3769. let initRunInput=createCheckbox(i18n("initRun"), rulesData.initRun!=false);
  3770. let autoLoadNumInput=createCheckbox(i18n("autoLoadNum"), rulesData.autoLoadNum, "h4", initRunInput, "number");
  3771. let preloadInput=createCheckbox(i18n("preload"), rulesData.preload!=false);
  3772. let rateInput=createCheckbox(i18n("turnRate"), rulesData.rate, "h4", preloadInput, "number");
  3773. let dbClick2StopInput=createCheckbox(i18n("dbClick2Stop"), rulesData.dbClick2Stop);
  3774. let manualModeInput=createCheckbox(i18n("manualMode"), rulesData.manualMode);
  3775. let clickModeInput=createCheckbox(i18n("clickMode"), rulesData.clickMode);
  3776. let pageBarMenuInput=createCheckbox(i18n("pageBarMenu"), rulesData.pageBarMenu);
  3777. let arrowToScrollInput=createCheckbox(i18n("arrowToScroll"), rulesData.arrowToScroll);
  3778. let sideControllerInput=createCheckbox(i18n("sideController"), rulesData.sideController);
  3779.  
  3780. let hideBarInput = createCheckbox(i18n("hideBar"), rulesData.hideBar && !rulesData.hideBarButNoStop, "h4", dbClick2StopInput, 'radio');
  3781. hideBarInput.name = 'hideBar';
  3782. let hideBarButNoStopInput = createCheckbox(i18n("hideBarButNoStop"), rulesData.hideBarButNoStop, "h4", dbClick2StopInput, 'radio');
  3783. hideBarButNoStopInput.name = 'hideBar';
  3784. hideBarInput.addEventListener('mouseup', e => {
  3785. if (hideBarInput.checked) {
  3786. setTimeout(() => {hideBarInput.checked = false}, 0);
  3787. }
  3788. });
  3789. hideBarButNoStopInput.addEventListener('mouseup', e => {
  3790. if (hideBarButNoStopInput.checked) {
  3791. setTimeout(() => {hideBarButNoStopInput.checked = false}, 0);
  3792. }
  3793. });
  3794.  
  3795. let dbClick2StopCtrlInput=createCheckbox(i18n("dbClick2StopCtrl"), rulesData.dbClick2StopCtrl, "h4", dbClick2StopInput);
  3796. let dbClick2StopAltInput=createCheckbox(i18n("dbClick2StopAlt"), rulesData.dbClick2StopAlt, "h4", dbClick2StopInput);
  3797. let dbClick2StopShiftInput=createCheckbox(i18n("dbClick2StopShift"), rulesData.dbClick2StopShift, "h4", dbClick2StopInput);
  3798. let dbClick2StopMetaInput=createCheckbox(i18n("dbClick2StopMeta"), rulesData.dbClick2StopMeta, "h4", dbClick2StopInput);
  3799. let dbClick2StopKeyInput=createCheckbox(i18n("dbClick2StopKey"), rulesData.dbClick2StopKey, "h4", dbClick2StopInput, "key");
  3800.  
  3801. let customRulesTitle=document.createElement("h2");
  3802. customRulesTitle.innerHTML=i18n("customRules");
  3803. configCon.insertBefore(customRulesTitle, insertPos);
  3804. let customRulesInput=document.createElement("textarea");
  3805. customRulesInput.spellcheck=false;
  3806. configCon.insertBefore(customRulesInput, insertPos);
  3807. if(rulesData.editTemp){
  3808. if(!ruleParser.customRules){
  3809. ruleParser.customRules=[];
  3810. }
  3811. for(let i in ruleParser.customRules){
  3812. if(ruleParser.customRules[i].url==rulesData.editTemp.url){
  3813. ruleParser.customRules.splice(i, 1);
  3814. break;
  3815. }
  3816. }
  3817. ruleParser.customRules.unshift(rulesData.editTemp);
  3818. rulesData.editTemp=null;
  3819. storage.setItem("rulesData", rulesData);
  3820. customRulesInput.previousElementSibling.scrollIntoView();
  3821. }
  3822. customRulesInput.style.width="100%";
  3823. customRulesInput.style.height="800px";
  3824. 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]`;
  3825. customRulesInput.value=getFormatJSON(ruleParser.customRules);
  3826. let blacklistInput=document.createElement("textarea");
  3827. blacklistInput.style.width="100%";
  3828. blacklistInput.style.height="500px";
  3829. blacklistInput.style.display="none";
  3830. blacklistInput.spellcheck=false;
  3831. blacklistInput.placeholder="http://*.xxx.com/*/y";
  3832. blacklistInput.value=rulesData.blacklist?rulesData.blacklist.join("\n"):"";
  3833. let blacklistBtn=document.createElement("button");
  3834. blacklistBtn.innerText=i18n("editBlacklist");
  3835. blacklistBtn.style.width="100%";
  3836. blacklistBtn.onclick=e=>{
  3837. blacklistInput.style.display=blacklistInput.style.display=="none"?"":"none";
  3838. };
  3839. configCon.insertBefore(blacklistBtn, insertPos);
  3840. configCon.insertBefore(blacklistInput, insertPos);
  3841. let saveBtn=document.createElement("button");
  3842. saveBtn.innerHTML=i18n("save");
  3843. saveBtn.style.width="100%";
  3844. saveBtn.style.position="fixed";
  3845. saveBtn.style.zIndex="999";
  3846. saveBtn.style.bottom=0;
  3847. saveBtn.style.left=0;
  3848. saveBtn.style.fontSize="x-large";
  3849. configCon.insertBefore(saveBtn, insertPos);
  3850. saveBtn.onclick=e=>{
  3851. try{
  3852. storage.setItem("hpRules", []);
  3853. storage.setItem("smartRules", []);
  3854. if(customRulesInput.value==""){
  3855. storage.setItem("customRules", "");
  3856. }else{
  3857. let customRules=JSON.parse(customRulesInput.value);
  3858. if(Array && Array.isArray && !Array.isArray(customRules)){
  3859. showTips("Rules must be a Array!");
  3860. return;
  3861. }
  3862. debug(customRules);
  3863. storage.setItem("customRules", customRules);
  3864. customRulesInput.value=JSON.stringify(customRules, null, 4);
  3865. }
  3866. }catch(e){
  3867. debug(e);
  3868. showTips("JSON error, check again!");
  3869. return;
  3870. }
  3871. rulesData.opacity = opacityInput.value / 100;
  3872. rulesData.blacklist = blacklistInput.value ? blacklistInput.value.split("\n") : "";
  3873. rulesData.hideBar = hideBarInput.checked;
  3874. rulesData.hideBarButNoStop = hideBarButNoStopInput.checked;
  3875. rulesData.dbClick2Stop = dbClick2StopInput.checked;
  3876. rulesData.enableWhiteList = !enableWhiteListInput.checked;
  3877. rulesData.enableDebug = enableDebugInput.checked;
  3878. rulesData.enableHistory = enableHistoryInput.checked;
  3879. rulesData.enableHistoryAfterInsert = enableHistoryAfterInsertInput.checked;
  3880. rulesData.openInNewTab = openInNewTabInput.checked;
  3881. rulesData.hideLoadingIcon = hideLoadingIconInput.checked;
  3882. rulesData.initRun = initRunInput.checked;
  3883. rulesData.autoLoadNum = autoLoadNumInput.value !== "0" ? autoLoadNumInput.value : '';
  3884. rulesData.rate = rateInput.value;
  3885. rulesData.preload = preloadInput.checked;
  3886. rulesData.manualMode = manualModeInput.checked;
  3887. rulesData.clickMode = clickModeInput.checked;
  3888. rulesData.pageBarMenu = pageBarMenuInput.checked;
  3889. rulesData.arrowToScroll = arrowToScrollInput.checked;
  3890. if (rulesData.sideController != sideControllerInput.checked) {
  3891. rulesData.sideControllerPos = false;
  3892. }
  3893. rulesData.sideController = sideControllerInput.checked;
  3894. rulesData.pageElementCss = pageElementCssInput.value;
  3895. rulesData.customCss = customCssInput.value;
  3896. rulesData.upBtnImg = upBtnImgInput.value;
  3897. rulesData.downBtnImg = downBtnImgInput.value;
  3898. rulesData.loadingText = loadingTextInput.value;
  3899. rulesData.dbClick2StopCtrl = dbClick2StopCtrlInput.checked;
  3900. rulesData.dbClick2StopAlt = dbClick2StopAltInput.checked;
  3901. rulesData.dbClick2StopShift = dbClick2StopShiftInput.checked;
  3902. rulesData.dbClick2StopMeta = dbClick2StopMetaInput.checked;
  3903. rulesData.dbClick2StopKey = dbClick2StopKeyInput.value;
  3904. storage.setItem("rulesData", rulesData);
  3905. let customUrls = customUrlsInput.value.trim();
  3906. if (customUrls) {
  3907. customUrls = customUrls.split(/\n/);
  3908. for (let c = 0; c < customUrls.length; c++) {
  3909. let url;
  3910. if(/^0\s*\|/.test(customUrls[c])){
  3911. url=customUrls[c].replace(/^0\s*\|\s*/, "").trim();
  3912. if(!/^http/.test(url)){
  3913. showTips("Wrong url, check again!");
  3914. return;
  3915. }
  3916. }else{
  3917. url=customUrls[c].trim();
  3918. if(!/^http/.test(url)){
  3919. showTips("Wrong url, check again!");
  3920. return;
  3921. }
  3922. }
  3923. let maxId=1,hasUrl=false;
  3924. if(!rulesData.urls){
  3925. rulesData.urls=[];
  3926. }
  3927. ruleUrls.forEach(u=>{
  3928. if(maxId<u.id){
  3929. maxId=u.id;
  3930. }
  3931. if(u.url==url){
  3932. hasUrl=true;
  3933. }
  3934. });
  3935. if(hasUrl)break;
  3936. if(!rulesData.sort)rulesData.sort=[1];
  3937. rulesData.urls.push({id:maxId+1,url:url});
  3938. rulesData.sort.push(maxId+1);
  3939. storage.setItem("rulesData", rulesData);
  3940. }
  3941. }
  3942. showTips("The settings are saved, refresh to view");
  3943. //location.reload();
  3944. };
  3945. return true;
  3946. }
  3947.  
  3948. var inUpdate=false;
  3949. function updateRules(success,fail){
  3950. if(inUpdate)return;
  3951. inUpdate=true;
  3952. let ruleIndex=ruleUrls.length-1;
  3953. storage.setItem("hpRules", []);
  3954. storage.setItem("smartRules", []);
  3955. function addNextRule(){
  3956. if(ruleIndex<0){
  3957. let now=new Date().getTime();
  3958. storage.setItem("ruleLastUpdate", now);
  3959. storage.setItem("rules", ruleParser.rules);
  3960. inUpdate=false;
  3961. success();
  3962. }else{
  3963. let rule=ruleUrls[ruleIndex--];
  3964. ruleParser.addRuleByUrl(rule.url, rule.id, (json,err)=>{
  3965. if(!json){
  3966. fail(rule,err);
  3967. }
  3968. addNextRule();
  3969. })
  3970. }
  3971. }
  3972. addNextRule();
  3973. }
  3974.  
  3975. function objIsArr(obj) {
  3976. return obj &&
  3977. typeof obj === 'object' &&
  3978. typeof obj.length === 'number' &&
  3979. !(obj.propertyIsEnumerable('length'));
  3980. }
  3981.  
  3982. function isVisible(el, win) {
  3983. if(!el || !el.offsetParent)return false;
  3984. var loopable = true,
  3985. visible = el.tagName && win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  3986. while(loopable && visible) {
  3987. el = el.parentNode;
  3988.  
  3989. if(el && el.tagName && el.tagName!="BODY") {
  3990. visible = win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  3991. }else {
  3992. loopable = false;
  3993. }
  3994. }
  3995. return visible;
  3996. }
  3997.  
  3998. function getElementTop(ele) {
  3999. if (!ele) return 0;
  4000. var actualTop = ele.offsetTop;
  4001. var current = ele.offsetParent;
  4002. while (current) {
  4003. actualTop += current.offsetTop;
  4004. current = current.offsetParent;
  4005. }
  4006. return actualTop;
  4007. }
  4008.  
  4009. function getElementBottom(ele) {
  4010. return getElementTop(ele) + ele.offsetHeight;
  4011. }
  4012.  
  4013. function getFormatJSON(obj){
  4014. if(!objIsArr(obj) || obj.length === 0)return "";
  4015. return JSON.stringify(obj, null, 4);
  4016. let ret="[\n";
  4017. let len=obj.length,i=0,isLast;
  4018. obj.forEach(item=>{
  4019. ret+=" {\n";
  4020. let iLen=Object.keys(item).length,j=0;
  4021. for(let key in item){
  4022. isLast=(++j)==iLen;
  4023. let value=item[key];
  4024. if(objIsArr(value)){
  4025. let vstr="[",v=0,vIsLast=false;
  4026. value.forEach(vi=>{
  4027. vIsLast=(++v)==value.length;
  4028. vstr+="\""+vi.replace(/\\/g,"\\\\")+"\""+(vIsLast?"":",");
  4029. });
  4030. vstr+="]";
  4031. ret+=" \""+key+"\":"+vstr+""+(isLast?"":",")+"\n";
  4032. }else{
  4033. if(typeof value=="string"){
  4034. value=value.replace(/\\/g,"\\\\").replace(/"/g,"\\\"");
  4035. value="\""+value+"\"";
  4036. }
  4037. ret+=" \""+key+"\":"+value+""+(isLast?"":",")+"\n";
  4038. }
  4039. }
  4040. isLast=(++i)==len;
  4041. ret+=" }"+(isLast?"":",")+"\n";
  4042. });
  4043. ret+="]";
  4044. return ret;
  4045. }
  4046.  
  4047. function globMatch(first, second) {
  4048. if (first.length == 0 && second.length == 0){
  4049. return true;
  4050. }
  4051.  
  4052. if (first.length > 1 && first[0] == '*' &&
  4053. second.length == 0){
  4054. return false;
  4055. }
  4056.  
  4057. if ((first.length > 1 && first[0] == '?') ||
  4058. (first.length != 0 && second.length != 0 &&
  4059. first[0] == second[0])){
  4060. return globMatch(first.substring(1),
  4061. second.substring(1));
  4062. }
  4063.  
  4064. if (first.length > 0 && first[0] == '*'){
  4065. return globMatch(first.substring(1), second) ||
  4066. globMatch(first, second.substring(1));
  4067. }
  4068.  
  4069. return false;
  4070. }
  4071.  
  4072. function initRules(callback) {
  4073. /*0 wedata格式,1 pagetual格式*/
  4074. ruleUrls=[
  4075. {
  4076. id:1,
  4077. url:'http://wedata.net/databases/AutoPagerize/items_all.json',
  4078. type:0,
  4079. }
  4080. ];var i=0,j=0;
  4081.  
  4082. ruleParser.initSavedRules(()=>{
  4083. storage.getItem("rulesData", data=>{
  4084. if(data){
  4085. rulesData=data;
  4086. if(data.urls)ruleUrls=ruleUrls.concat(data.urls);
  4087. if(data.sort){
  4088. let urls=[];
  4089. data.sort.forEach(id=>{
  4090. for(let s=0;s<ruleUrls.length;s++){
  4091. if(id==ruleUrls[s].id){
  4092. urls.push(ruleUrls[s]);
  4093. break;
  4094. }
  4095. }
  4096. });
  4097. ruleUrls=urls;
  4098. }
  4099. }
  4100. let upBtnImg=rulesData.upBtnImg,downBtnImg=rulesData.downBtnImg;
  4101. if(upBtnImg && downBtnImg){
  4102. downSvgCSS=downSvgCSS.replace("transform: rotate(180deg);","");
  4103. }else if(upBtnImg && !downBtnImg){
  4104. downBtnImg=upBtnImg;
  4105. }else if(downBtnImg && !upBtnImg){
  4106. upBtnImg=downBtnImg;
  4107. }
  4108. if(upBtnImg){
  4109. upSvg=`<img class="pagetual" src="${upBtnImg}"/>`;
  4110. }
  4111. if(downBtnImg){
  4112. downSvg=`<img class="pagetual" src="${downBtnImg}"/>`;
  4113. }
  4114. setLoadingDiv(rulesData.loadingText || i18n("loadingText"));
  4115. if(typeof(rulesData.opacity)=="undefined"){
  4116. rulesData.opacity=0.3;
  4117. }
  4118. if(typeof(rulesData.hideBar)=="undefined"){
  4119. rulesData.hideBar=false;
  4120. }
  4121. if(typeof(rulesData.dbClick2Stop)=="undefined"){
  4122. rulesData.dbClick2Stop=true;
  4123. }
  4124. if(typeof(rulesData.enableWhiteList)=="undefined"){
  4125. rulesData.enableWhiteList=false;
  4126. }
  4127. if(typeof(rulesData.enableHistory)=="undefined"){
  4128. rulesData.enableHistory=false;
  4129. }
  4130. if(typeof(rulesData.openInNewTab)=="undefined"){
  4131. rulesData.openInNewTab=true;
  4132. }
  4133. if(typeof(rulesData.enableDebug)=="undefined"){
  4134. rulesData.enableDebug=true;
  4135. }
  4136. if(typeof(rulesData.initRun)=="undefined"){
  4137. rulesData.initRun=true;
  4138. }
  4139. if(typeof(rulesData.preload)=="undefined"){
  4140. rulesData.preload=true;
  4141. }
  4142. if(typeof(rulesData.manualMode)=="undefined"){
  4143. rulesData.manualMode=false;
  4144. }
  4145. if(typeof(rulesData.clickMode)=="undefined"){
  4146. rulesData.clickMode=false;
  4147. }
  4148. if(typeof(rulesData.pageBarMenu)=="undefined"){
  4149. rulesData.pageBarMenu=false;
  4150. }
  4151. if(typeof(rulesData.arrowToScroll)=="undefined"){
  4152. rulesData.arrowToScroll=false;
  4153. }
  4154. if(typeof(rulesData.hideLoadingIcon)=="undefined"){
  4155. rulesData.hideLoadingIcon=false;
  4156. }
  4157. if(rulesData.blacklist && rulesData.blacklist.length>0){
  4158. for(let b in rulesData.blacklist){
  4159. let curGlob=rulesData.blacklist[b];
  4160. if(globMatch(curGlob, location.href)){
  4161. return;
  4162. }
  4163. }
  4164. }
  4165. if(rulesData.autoLoadNum){
  4166. autoLoadNum=parseInt(rulesData.autoLoadNum);
  4167. }
  4168. enableDebug=rulesData.enableDebug;
  4169. storage.getItem("nextSwitch_"+location.host, i=>{
  4170. storage.getItem("forceState_"+location.host, v=>{
  4171. storage.getItem("ruleLastUpdate", date=>{
  4172. if(typeof(i)!=="undefined"){
  4173. nextIndex=i;
  4174. }
  4175. if(typeof(v)=="undefined"){
  4176. v=(rulesData.enableWhiteList?1:0);
  4177. }
  4178. forceState=v;
  4179. updateDate=date;
  4180. if(initConfig())return;
  4181. if(forceState==1)return;
  4182. let now=new Date().getTime();
  4183. if(!date || now-date>2*24*60*60*1000){
  4184. updateRules(()=>{
  4185. },(rule,err)=>{});
  4186. storage.setItem("ruleLastUpdate", now);
  4187. }
  4188. callback();
  4189. });
  4190. });
  4191. });
  4192. });
  4193. });
  4194. }
  4195.  
  4196. function requestDoc(url, callback){
  4197. let postParams = url.match(/#p{(.*)}$/);
  4198. if (postParams) {
  4199. postParams = postParams[1];
  4200. url = url.replace(/#p{.*/, "");
  4201. }
  4202. _GM_xmlhttpRequest({
  4203. url: url,
  4204. method: postParams ? 'POST' : 'GET',
  4205. data: postParams,
  4206. overrideMimeType: 'text/html;charset=' + (document.characterSet || document.charset || document.inputEncoding),
  4207. headers: {
  4208. 'Referer': location.href,
  4209. 'User-Agent': navigator.userAgent,
  4210. "Content-Type": (postParams ? "application/x-www-form-urlencoded" : "text/html") + ";charset=" + (document.characterSet || document.charset || document.inputEncoding),
  4211. },
  4212. timeout: 20000,
  4213. onload: function(res) {
  4214. var doc=null,response=res.response;
  4215. let preCode=ruleParser.curSiteRule.pageElementPre || ruleParser.curSiteRule.pagePre;
  4216. if(preCode){
  4217. try{
  4218. if (typeof _unsafeWindow.pagetualPagePre!='undefined') {
  4219. response = _unsafeWindow.pagetualPagePre(response);
  4220. } else if (preCode.length == 2) {
  4221. response = response.replace(new RegExp(preCode[0], "gi"), preCode[1]);
  4222. } else {
  4223. response = Function("response",'"use strict";' + preCode)(response);
  4224. }
  4225. }catch(e){
  4226. debug(e);
  4227. }
  4228. }
  4229. try {
  4230. doc=document.implementation.createHTMLDocument('');
  4231. doc.documentElement.innerHTML=response;
  4232. let base=doc.querySelector("base");
  4233. ruleParser.basePath=base?base.href:url;
  4234. }
  4235. catch (e) {
  4236. debug('parse error'+e.toString());
  4237. }
  4238. let pageElement=ruleParser.getPageElement(doc);
  4239. if(inCors && (!pageElement || pageElement.length==0)){
  4240. ruleParser.curSiteRule.pageElement=allOfBody;
  4241. pageElement=ruleParser.getPageElement(doc);
  4242. ruleParser.getInsert(true);
  4243. }
  4244. //只有1的話怕不是圖片哦
  4245. if(pageElement && (pageElement.length>1 || (pageElement.length==1 && pageElement[0].tagName!="IMG") )){
  4246. ruleParser.insertPage(doc, pageElement, url, callback, false);
  4247. if(ruleParser.curSiteRule.action==1){
  4248. requestFromIframe(url, (doc, eles)=>{
  4249. loadPageOver();
  4250. if(eles){
  4251. ruleParser.insertPage(doc, eles, url, callback, true);
  4252. }
  4253. });
  4254. }else ruleParser.curSiteRule.action=0;
  4255. }else if(ruleParser.curSiteRule.singleUrl || curPage==1){
  4256. ruleParser.curSiteRule.action=1;
  4257. requestFromIframe(url, (doc, eles)=>{
  4258. loadPageOver();
  4259. if(eles){
  4260. ruleParser.insertPage(doc, eles, url, callback, true);
  4261. }
  4262. });
  4263. }else{
  4264. debug("Stop as no page element");
  4265. isPause=true;
  4266. callback(false);
  4267. }
  4268. },
  4269. onerror: function(e){
  4270. debug(e, "NetError");
  4271. callback(false);
  4272. },
  4273. ontimeout: function(e){
  4274. debug(e, "NetTimeout");
  4275. callback(false);
  4276. }
  4277. });
  4278. }
  4279.  
  4280. function initPage(){
  4281. ruleParser.initPage(()=>{
  4282. if(ruleParser.curSiteRule.autoLoadNum){
  4283. autoLoadNum=ruleParser.curSiteRule.autoLoadNum;
  4284. }
  4285. if(ruleParser.curSiteRule.nextLink && Array && Array.isArray && Array.isArray(ruleParser.curSiteRule.nextLink)){
  4286. _GM_registerMenuCommand(i18n("nextSwitch"), ()=>{
  4287. NextSwitch.getInstance().start();
  4288. });
  4289. }
  4290. if(ruleParser.nextLinkHref){
  4291. let isJs=/^(javascript|#)/.test(ruleParser.nextLinkHref.replace(location.href,""));
  4292. if(!isJs){
  4293. let inForce=(forceState == 2 || forceState == 3);
  4294. _GM_registerMenuCommand(i18n(inForce?"cancelForceIframe":"forceIframe"), ()=>{
  4295. if(inForce){
  4296. storage.setItem("forceState_"+location.host, "");
  4297. }else{
  4298. let _state=ruleParser.curSiteRule.action>0 || confirm(i18n("forceAllBody"))?2:3;
  4299. storage.setItem("forceState_"+location.host, _state);
  4300. }
  4301. location.reload();
  4302. });
  4303. }
  4304. _GM_registerMenuCommand(i18n("loadNow"), ()=>{
  4305. let loadNum=window.prompt(i18n("loadConfirm"), "1");
  4306. if(loadNum==="" || loadNum===null)return;
  4307. autoLoadNum=Math.abs(parseInt(loadNum));
  4308. nextPage();
  4309. });
  4310. }
  4311. initListener();
  4312. let initRun = typeof ruleParser.curSiteRule.initRun == 'undefined' ? rulesData.initRun : ruleParser.curSiteRule.initRun;
  4313. if (initRun && initRun != 0 && initRun != '0') nextPage();
  4314. });
  4315. }
  4316.  
  4317. var pageBarStyle;
  4318. function initView(){
  4319. _GM_addStyle(`
  4320. .pagetual_pageBar{
  4321. -moz-transition:opacity 0.3s ease-in-out 0s;
  4322. -webkit-transition:opacity 0.3s ease-in-out 0s;
  4323. transition:opacity 0.3s ease-in-out 0s;
  4324. font-family: Arial,sans-serif !important;
  4325. }
  4326. .pagetual_pageBar.stop {
  4327. -webkit-filter: invert(100%);
  4328. filter: invert(100%);
  4329. opacity: 1!important;
  4330. }
  4331. .pagetual_pageBar.hide {
  4332. display: none!important;
  4333. }
  4334. .pagetual_pageBar:hover {
  4335. opacity: 1!important;
  4336. }
  4337. .pagetual_pageBar span {
  4338. vertical-align: super;
  4339. }
  4340. .pagetual_pageBar a::before,
  4341. .pagetual_pageBar a::after {
  4342. content: none;
  4343. }
  4344. .pagetual_pageBar a>span {
  4345. margin-top: 0!important;
  4346. pointer-events: none;
  4347. padding: unset;
  4348. opacity: 0;
  4349. -moz-transition:all 0.3s ease-in-out 0s;
  4350. -webkit-transition:all 0.3s ease-in-out 0s;
  4351. transition:all 0.3s ease-in-out 0s;
  4352. }
  4353. .pagetual_pageBar a>span:hover {
  4354. color: red;
  4355. }
  4356. .pagetual_pageBar a:hover>span {
  4357. opacity: 1;
  4358. }
  4359. .pagetual_pageBar span.prevScreen,
  4360. .pagetual_pageBar span.nextScreen {
  4361. display: block!important;
  4362. }
  4363. .pagetual_pageBar a:hover>span.prevScreen {
  4364. margin-top: -30px!important;
  4365. pointer-events: all;
  4366. }
  4367. .pagetual_pageBar a:hover>span.nextScreen {
  4368. margin-top: 30px!important;
  4369. pointer-events: all;
  4370. }
  4371. .pagetual_pageBar span>svg {
  4372. -moz-transition:transform 0.5s ease, opacity 0.3s ease;
  4373. -webkit-transition:transform 0.5s ease, opacity 0.3s ease;
  4374. transition:transform 0.5 ease, opacity 0.3s ease;
  4375. opacity: 0;
  4376. }
  4377. .pagetual_pageBar:hover span>svg {
  4378. opacity: 1;
  4379. }
  4380. .pagetual_pageBar span>svg.upSvg:hover {
  4381. transform: rotate(360deg) scale3d(1.2, 1.2, 1.2);
  4382. }
  4383. .pagetual_pageBar span>svg.downSvg:hover {
  4384. transform: rotate(540deg) scale3d(1.2, 1.2, 1.2)!important;
  4385. }
  4386. .pagetual_pageBar .pagetual_pageNum{
  4387. color: #55555f;
  4388. }
  4389. .pagetual_pageBar .pagetual_pageNum:hover{
  4390. color: #ff6464;
  4391. }
  4392. .pagetual_tipsWords{
  4393. font-size: 50px;
  4394. font-weight: bold;
  4395. font-family: "黑体", -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto",
  4396. "Oxygen", "Ubuntu", "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji",
  4397. "Segoe UI Emoji", "Segoe UI Symbol";
  4398. color: #ffffff;
  4399. min-height: 70px;
  4400. max-width: 80%;
  4401. line-height: 70px;
  4402. position: fixed;
  4403. left: 50%;
  4404. top: 10%;
  4405. margin-left: -99999px;
  4406. padding: 0 15px;
  4407. z-index: 999999999;
  4408. background-color: #000;
  4409. border: 1px solid #303030;
  4410. border-radius: 10px;
  4411. opacity: 0;
  4412. filter: alpha(opacity=65);
  4413. box-shadow: 5px 5px 20px 0px #000;
  4414. -moz-transition:opacity 0.3s ease-in-out 0s;
  4415. -webkit-transition:opacity 0.3s ease-in-out 0s;
  4416. transition:opacity 0.3s ease-in-out 0s;
  4417. pointer-events: none;
  4418. }
  4419. .pagetual_loading {
  4420. width: 50px;
  4421. height: 50px;
  4422. margin: 10px auto;
  4423. border-radius: 100%;
  4424. display: flex;
  4425. -webkit-animation: pagetual_loading_scaleout 1.0s infinite ease-in-out;
  4426. animation: pagetual_loading_scaleout 1.0s infinite ease-in-out;
  4427. }
  4428. @-webkit-keyframes pagetual_loading_scaleout {
  4429. 0% { -webkit-transform: scale(0.0) }
  4430. 100% {
  4431. -webkit-transform: scale(1.0);
  4432. opacity: 0;
  4433. }
  4434. }
  4435. @keyframes pagetual_loading_scaleout {
  4436. 0% {
  4437. transform: scale(0.0);
  4438. -webkit-transform: scale(0.0);
  4439. } 100% {
  4440. transform: scale(1.0);
  4441. -webkit-transform: scale(1.0);
  4442. opacity: 0;
  4443. }
  4444. }
  4445. .pagetual_loading_text {
  4446. white-space: nowrap;
  4447. -webkit-animation: pagetual_loading_opacity 2.6s infinite ease-in-out;
  4448. animation: pagetual_loading_opacity 2.6s infinite ease-in-out;
  4449. }
  4450. @-webkit-keyframes pagetual_loading_opacity {
  4451. 0% { opacity: 1 }
  4452. 50% { opacity: 0.2 }
  4453. 100% { opacity: 1 }
  4454. }
  4455. @keyframes pagetual_loading_opacity {
  4456. 0% { opacity: 1 }
  4457. 50% { opacity: 0.2 }
  4458. 100% { opacity: 1 }
  4459. }
  4460. `);
  4461. 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;`;
  4462. }
  4463. var loadingDiv=document.createElement("div");
  4464. 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;";
  4465.  
  4466. 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;`;
  4467. function setLoadingDiv(loadingText){
  4468. 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>`}`;
  4469. }
  4470.  
  4471. 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>`;
  4472. var upSvgCSS=`display:initial;position:relative;cursor: pointer;margin: 0 8px;width: 30px;height: 30px;vertical-align: middle;fill: currentColor;overflow: hidden;`;
  4473. 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>`;
  4474. 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);`;
  4475.  
  4476. 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;`;
  4477. 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;`;
  4478.  
  4479. var tipsWords=document.createElement("div");
  4480. tipsWords.className="pagetual_tipsWords";
  4481.  
  4482. var isPause = false, isHideBar = false, isLoading = false, curPage = 1, forceState = 0, bottomGap = 1000, autoLoadNum = -1, nextIndex = 0, stopScroll = false;
  4483.  
  4484. function changeStop(stop) {
  4485. isPause = stop;
  4486. [].forEach.call(document.querySelectorAll(".pagetual_pageBar"), bar => {
  4487. if (isPause) {
  4488. bar.classList.add("stop");
  4489. } else {
  4490. bar.classList.remove("stop");
  4491. }
  4492. });
  4493. }
  4494.  
  4495. function changeHideBar(hide) {
  4496. isHideBar = hide;
  4497. [].forEach.call(document.querySelectorAll(".pagetual_pageBar"), bar => {
  4498. if (isHideBar) {
  4499. bar.classList.add("hide");
  4500. } else {
  4501. bar.classList.remove("hide");
  4502. }
  4503. });
  4504. }
  4505.  
  4506. function isInViewPort(element) {
  4507. if(!document.body.contains(element))return false;
  4508. if(_unsafeWindow.getComputedStyle(element).display=="none")return false;
  4509. const viewWidth = window.innerWidth || document.documentElement.clientWidth;
  4510. const viewHeight = window.innerHeight || document.documentElement.clientHeight;
  4511. const {
  4512. top,
  4513. right,
  4514. bottom,
  4515. left,
  4516. } = element.getBoundingClientRect();
  4517.  
  4518. return (
  4519. top >= 0 &&
  4520. left >= 0 &&
  4521. right <= viewWidth + 1 &&
  4522. bottom <= viewHeight * 2
  4523. );
  4524. }
  4525.  
  4526. function getPageBar() {
  4527. let preBar = null, nextBar = null;
  4528. let pageBars = [].slice.call(document.querySelectorAll(".pagetual_pageBar"));
  4529. for (let i = 0; i < pageBars.length; i++) {
  4530. let pageBar = pageBars[i];
  4531. if (!pageBar || !document.body.contains(pageBar)) continue;
  4532. let {
  4533. top,
  4534. right,
  4535. bottom,
  4536. left,
  4537. } = pageBar.getBoundingClientRect();
  4538. if (top > 500) {
  4539. nextBar = pageBar;
  4540. preBar = (i - 1 >= 0 ? pageBars[i - 1] : null);
  4541. if (pageBar && document.body.contains(pageBar)) {
  4542. let {
  4543. top,
  4544. right,
  4545. bottom,
  4546. left,
  4547. } = pageBar.getBoundingClientRect();
  4548. if (top < -500) {
  4549. preBar = pageBar;
  4550. } else preBar = (i - 2 >= 0 ? pageBars[i - 2] : null);
  4551. }
  4552. break;
  4553. }
  4554. }
  4555. if (!nextBar) preBar = pageBars[pageBars.length - 2];
  4556. return {preBar: preBar, nextBar: nextBar};
  4557. }
  4558.  
  4559. var urlChanged=false;
  4560. var _wr = function(type) {
  4561. var orig = history[type];
  4562. return function() {
  4563. var rv = orig.apply(this, arguments);
  4564. var e = new Event(type);
  4565. e.arguments = arguments;
  4566. window.dispatchEvent(e);
  4567. return rv;
  4568. };
  4569. };
  4570. var changeHandler = e => {
  4571. urlChanged = true;
  4572. isPause = true;
  4573. setTimeout(() => {
  4574. lastActiveUrl = location.href;
  4575. if (guidePage.test(location.href)) {
  4576. setTimeout(() => {
  4577. if(typeof JSONEditor !== 'undefined'){
  4578. createEdit();
  4579. }else{
  4580. window.onload = e => {
  4581. createEdit();
  4582. }
  4583. }
  4584. }, 500);
  4585. } else if (location.href == configPage[0]) {
  4586. location.reload();
  4587. } else if (!ruleParser.ruleMatch(ruleParser.curSiteRule)) {
  4588. initPage();
  4589. }
  4590. if (!ruleParser.nextLinkHref) isLoading = false;
  4591. },1);
  4592. };
  4593. history.pushState = _wr('pushState');
  4594. window.addEventListener('pushState', changeHandler);
  4595.  
  4596. function initListener(){
  4597. let loadmoreBtn,loading=true,lastScroll=0,checkLoadMoreTimes=0;
  4598. if (ruleParser.curSiteRule.loadMore) {
  4599. loading=false;
  4600. } else {
  4601. let checkLoadMore=setInterval(()=>{
  4602. loadmoreBtn=getLoadMore(document);
  4603. if(loadmoreBtn && isVisible(loadmoreBtn, _unsafeWindow)){
  4604. loading=false;
  4605. clearInterval(checkLoadMore);
  4606. }else if(checkLoadMoreTimes++>30){
  4607. clearInterval(checkLoadMore);
  4608. }
  4609. },300);
  4610. }
  4611. let clickMode = typeof ruleParser.curSiteRule.clickMode == 'undefined' ? rulesData.clickMode : ruleParser.curSiteRule.clickMode;
  4612. let clickNext = async () => {
  4613. let nextLink = ruleParser.nextLinkHref;
  4614. if (!nextLink) return;
  4615. let isJs = /^(javascript|#)/.test(nextLink.replace(location.href, ""));
  4616. if (isJs) {
  4617. let nextBtn = await ruleParser.getNextLink(document);
  4618. if (nextBtn) emuClick(nextBtn);
  4619. } else {
  4620. window.location.href = nextLink;
  4621. }
  4622. };
  4623. let checkScrollReach=()=>{
  4624. let scrolly=window.scrollY;
  4625. let windowHeight=window.innerHeight || document.documentElement.clientHeight;
  4626. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  4627. if(clickMode){
  4628. if(scrollH-scrolly-windowHeight<10){
  4629. clickNext();
  4630. }
  4631. }else if(scrollH-scrolly-windowHeight<bottomGap){
  4632. nextPage();
  4633. }
  4634. };
  4635. let scrollHandler = e=>{
  4636. if(urlChanged && !isLoading){
  4637. ruleParser.initPage(()=>{
  4638. if(ruleParser.nextLinkHref){
  4639. initView();
  4640. }
  4641. isPause=false;
  4642. });
  4643. urlChanged=false;
  4644. }
  4645. if(isPause)return;
  4646. if(!loading){
  4647. if(ruleParser.curSiteRule.loadMore || !loadmoreBtn || !document.body.contains(loadmoreBtn)){
  4648. loadmoreBtn=getLoadMore(document);
  4649. }
  4650. if(loadmoreBtn){
  4651. if(isInViewPort(loadmoreBtn)){
  4652. emuClick(loadmoreBtn);
  4653. loading=true;
  4654. setTimeout(()=>{loading=false},200);
  4655. }
  4656. }else{
  4657. loading=true;
  4658. setTimeout(()=>{loading=false},200);
  4659. }
  4660. }
  4661. if(!isLoading && !stopScroll){
  4662. checkScrollReach();
  4663. }
  4664. if(ruleParser.curSiteRule.lockScroll){
  4665. let curScroll=document.body.scrollTop||document.documentElement.scrollTop;
  4666. if(isLoading && Math.abs(lastScroll-curScroll)>350){
  4667. document.body.scrollTop=lastScroll;
  4668. document.documentElement.scrollTop=lastScroll;
  4669. }else{
  4670. lastScroll=curScroll;
  4671. }
  4672. }
  4673. };
  4674. document.addEventListener('dblclick', e=>{
  4675. if(forceState==1 || e.target.tagName=='INPUT' || e.target.tagName=='TEXTAREA') return;
  4676. if(!rulesData.dbClick2StopKey){
  4677. if((rulesData.dbClick2StopCtrl && !e.ctrlKey) ||
  4678. (rulesData.dbClick2StopAlt && !e.altKey) ||
  4679. (rulesData.dbClick2StopShift && !e.shiftKey) ||
  4680. (rulesData.dbClick2StopMeta && !e.metaKey)){
  4681. return;
  4682. }
  4683. }
  4684. if(e.target.tagName !== "BODY" && e.target.className !== 'pagetual_pageBar'){
  4685. let selStr=document.getSelection().toString();
  4686. if(selStr && selStr.trim()){
  4687. return;
  4688. }
  4689. }
  4690. if(rulesData.dbClick2Stop && (ruleParser.nextLinkHref || loadmoreBtn)){
  4691. setTimeout(()=>{
  4692. if (rulesData.hideBarButNoStop || rulesData.hideBar) {
  4693. changeHideBar(!isHideBar);
  4694. }
  4695. if (!rulesData.hideBarButNoStop) {
  4696. changeStop(!isPause);
  4697. showTips(i18n(isPause?"disable":"enable"));
  4698. }
  4699. if(!isPause){
  4700. checkScrollReach();
  4701. }
  4702. },10);
  4703. }
  4704. });
  4705. if(rulesData.dbClick2StopKey){
  4706. document.addEventListener('keydown', e=>{
  4707. if((rulesData.dbClick2StopCtrl && !e.ctrlKey) ||
  4708. (rulesData.dbClick2StopAlt && !e.altKey) ||
  4709. (rulesData.dbClick2StopShift && !e.shiftKey) ||
  4710. (rulesData.dbClick2StopMeta && !e.metaKey)){
  4711. return;
  4712. }
  4713. if (document.activeElement &&
  4714. (document.activeElement.tagName == 'INPUT' ||
  4715. document.activeElement.tagName == 'TEXTAREA')) {
  4716. return;
  4717. }
  4718. var key = e.key.toLowerCase();
  4719. if(rulesData.dbClick2StopKey.toLowerCase()==key){
  4720. forceState=(forceState==1?0:1);
  4721. showTips(i18n(forceState==1?"disableSiteTips":"enableSiteTips"));
  4722. if(!ruleParser.curSiteRule.url) {
  4723. storage.setItem("forceState_"+location.host, forceState);
  4724. location.reload();
  4725. }
  4726. }
  4727. });
  4728. }
  4729. if (ruleParser.curSiteRule.listenHashChange) {
  4730. window.addEventListener('hashchange', () => {
  4731. urlChanged = true;
  4732. isPause = true;
  4733. if (!ruleParser.nextLinkHref) isLoading = false;
  4734. }, false);
  4735. }
  4736. let manualMode = typeof ruleParser.curSiteRule.manualMode == 'undefined' ? rulesData.manualMode : ruleParser.curSiteRule.manualMode;
  4737. if (manualMode) {
  4738. document.addEventListener('keydown', e => {
  4739. if (document.activeElement &&
  4740. (document.activeElement.tagName == 'INPUT' ||
  4741. document.activeElement.tagName == 'TEXTAREA' ||
  4742. document.activeElement.contentEditable == 'true')) {
  4743. return;
  4744. }
  4745. if(e.keyCode == 39){
  4746. clickNext();
  4747. }
  4748. });
  4749. document.addEventListener('pagetual.next', function() {
  4750. clickNext();
  4751. }, false);
  4752. return;
  4753. }
  4754. if (rulesData.arrowToScroll) {
  4755. document.addEventListener('keyup', e => {
  4756. if (document.activeElement &&
  4757. (document.activeElement.tagName == 'INPUT' ||
  4758. document.activeElement.tagName == 'TEXTAREA' ||
  4759. document.activeElement.contentEditable == 'true')) {
  4760. return;
  4761. }
  4762. if (e.keyCode == 39) {
  4763. let nextPageBar=getPageBar().nextBar;
  4764. if (nextPageBar) {
  4765. scrollToPageBar(nextPageBar);
  4766. } else {
  4767. let scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
  4768. window.scrollTo({ top: scrollTop + (window.innerHeight || document.documentElement.clientHeight), behavior: 'smooth'});
  4769. }
  4770. } else if (e.keyCode == 37) {
  4771. let prePageBar = getPageBar().preBar;
  4772. if (prePageBar) {
  4773. scrollToPageBar(prePageBar);
  4774. } else {
  4775. let scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
  4776. window.scrollTo({ top: scrollTop - (window.innerHeight || document.documentElement.clientHeight), behavior: 'smooth'});
  4777. }
  4778. }
  4779. });
  4780. }
  4781. if (!ruleParser.curSiteRule.wheel) {
  4782. document.addEventListener('scroll', scrollHandler, true);
  4783. }
  4784. document.addEventListener('wheel', scrollHandler, true);
  4785. }
  4786.  
  4787. function showTips(content, wordColor, backColor){
  4788. document.body.appendChild(tipsWords);
  4789. tipsWords.style.opacity=0.8;
  4790. tipsWords.innerText=content;
  4791. tipsWords.style.marginLeft=-tipsWords.offsetWidth/2+"px";
  4792. tipsWords.style.color=wordColor||0xFFFFFF;
  4793. tipsWords.style.backgroundColor=backColor||0x000;
  4794. setTimeout(()=>{tipsWords.style.opacity=0},1000);
  4795. }
  4796.  
  4797. function getLoadMore(doc) {
  4798. if (ruleParser.curSiteRule.loadMore === "") return null;
  4799. let btnSel = ruleParser.curSiteRule.loadMore || ".LoadMore,.load-more,.button-show-more,button[data-testid='more-results-button']", loadmoreBtn;
  4800. if (btnSel) {
  4801. loadmoreBtn = getElement(btnSel, doc);
  4802. }
  4803. if (!loadmoreBtn) {
  4804. let buttons = doc.querySelectorAll("input,button,a,div[onclick]"), loadmoreReg = /^\s*(加载更多|加載更多|load\s*more|もっと読み込む)\s*$/i;
  4805. for (let i = 0; i < buttons.length; i++) {
  4806. let button = buttons[i];
  4807. if (button.innerText.length > 20) continue;
  4808. if (button && loadmoreReg.test(button.innerText)) {
  4809. loadmoreBtn = button;
  4810. break;
  4811. }
  4812. }
  4813. }
  4814. if (loadmoreBtn && !ruleParser.curSiteRule.loadMore && loadmoreBtn.dataset.ajax !== "true") {
  4815. let href = loadmoreBtn.getAttribute("href");
  4816. if (href && href != "/" && !/^(javascript|#)/.test(href.replace(location.href,""))) {
  4817. loadmoreBtn = null;
  4818. }
  4819. }
  4820. return loadmoreBtn;
  4821. }
  4822.  
  4823. function scrollToPageBar(bar){
  4824. let yOffset = -20;
  4825. if (typeof ruleParser.curSiteRule.pageBarTop !== 'undefined') {
  4826. yOffset = -ruleParser.curSiteRule.pageBarTop;
  4827. }
  4828. const y = bar.getBoundingClientRect().top + window.pageYOffset + yOffset;
  4829. window.scrollTo({ top: y, behavior: 'smooth'});
  4830. }
  4831.  
  4832. const pageNumReg=/[&\/\?](p=|page[=\/_-]?)\d+|[_-]\d+\./;
  4833. function createPageBar(url) {
  4834. SideController.setup();
  4835. url = url.replace(/#p{.*/, "");
  4836. if (rulesData.opacity == 0 || ruleParser.curSiteRule.pageBar === 0) return null;
  4837. let insert=ruleParser.getInsert();
  4838. if(!insert || !insert.parentNode)return;
  4839. curPage++;
  4840. let example=ruleParser.curSiteRule.insertPos==2?insert.children[0]:(insert.parentNode.children[parseInt(insert.parentNode.children.length/2)]||insert);
  4841. if (example.className=="pagetual_pageBar") {
  4842. example=example.previousElementSibling;
  4843. }
  4844. if(!example || !example.parentNode)example=insert;
  4845. let exampleStyle = _unsafeWindow.getComputedStyle(example);
  4846. let inTable, inLi;
  4847. if (forceState == 2) {
  4848. inTable = inLi = false;
  4849. } else {
  4850. inTable=example.parentNode.tagName=="TABLE" ||
  4851. example.parentNode.tagName=="TBODY" ||
  4852. example.tagName=="TR" ||
  4853. example.tagName=="TBODY" ||
  4854. exampleStyle.display=="table-row" ||
  4855. (example.previousElementSibling && example.previousElementSibling.tagName=="TR") ||
  4856. (example.previousElementSibling && example.previousElementSibling.tagName=="TBODY");
  4857. inLi=example.tagName=="LI" || (example.previousElementSibling && example.previousElementSibling.tagName=="LI");
  4858. }
  4859. let pageBar=document.createElement(inTable?"tr":(inLi?"li":"div"));
  4860. let upSpan=document.createElement("span");
  4861. let downSpan=document.createElement("span");
  4862. let pageText=document.createElement("a");
  4863. let pageNum;
  4864. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  4865. pageBar.className=isHideBar?"pagetual_pageBar hide":"pagetual_pageBar";
  4866. pageBar.id="pagetual_pageBar"+curPage;
  4867. pageBar.setAttribute("translate", "no");
  4868. if(isPause){
  4869. pageBar.classList.add("stop");
  4870. }
  4871. pageBar.style.cssText=pageBarStyle;
  4872. pageBar.title=i18n(isPause?"enable":"disable");
  4873. upSpan.innerHTML=upSvg;
  4874. upSpan.children[0].style.cssText=upSvgCSS;
  4875. upSpan.title=i18n("toTop");
  4876. downSpan.innerHTML=downSvg;
  4877. downSpan.children[0].style.cssText=downSvgCSS;
  4878. downSpan.title=i18n("toBottom");
  4879. upSpan.style.cssText=initStyle;
  4880. downSpan.style.cssText=initStyle;
  4881. pageText.href=url;
  4882. pageText.style.cssText=pageTextStyle;
  4883. pageText.title=i18n("current");
  4884. if(rulesData.openInNewTab)pageText.target="_blank";
  4885. pageBar.appendChild(upSpan);
  4886. pageBar.appendChild(pageText);
  4887. if(rulesData.pageBarMenu){
  4888. pageText.addEventListener("click", e=>{
  4889. e.stopPropagation();
  4890. if (e.ctrlKey || e.altKey || e.shiftKey || e.metaKey) return;
  4891. e.preventDefault();
  4892. Picker.getInstance().start();
  4893. });
  4894. }
  4895. let touched = false;
  4896. let touchBodyHandler = e => {
  4897. touched = false;
  4898. document.body.removeEventListener('touchstart', touchBodyHandler);
  4899. };
  4900. pageText.addEventListener("touchstart", e => {
  4901. if (touched) return;
  4902. touched = true;
  4903. pageText.style.pointerEvents = 'none';
  4904. setTimeout(() => {
  4905. pageText.style.pointerEvents = 'all';
  4906. }, 250);
  4907. document.body.addEventListener("touchstart", touchBodyHandler);
  4908. });
  4909. if(ruleParser.nextTitle){
  4910. pageText.innerHTML=ruleParser.nextTitle+" ";
  4911. pageText.title=ruleParser.nextTitle;
  4912. }
  4913. if(ruleParser.curSiteRule.pageNum || pageNumReg.test(url)){
  4914. pageText.innerHTML+="Page ";
  4915. pageNum=document.createElement("span");
  4916. pageNum.innerHTML=ruleParser.getPageNumFromUrl(url);
  4917. pageNum.className="pagetual_pageNum";
  4918. pageNum.title=i18n("inputPageNum");
  4919. pageNum.style.cssText=pageTextStyle;
  4920. pageNum.style.cursor="pointer";
  4921. pageNum.style.color="";
  4922. pageNum.style.marginLeft="5px";
  4923. pageNum.addEventListener("click", e=>{
  4924. let pageInput=prompt(i18n("inputPageNum"), "1");
  4925. if(pageInput){
  4926. let pageLink=ruleParser.getLinkByPage(url, pageInput);
  4927. if(pageLink){
  4928. _GM_openInTab(pageLink,{active:true});
  4929. }
  4930. }
  4931. e.preventDefault();
  4932. e.stopPropagation();
  4933. });
  4934. pageBar.appendChild(pageNum);
  4935. }else{
  4936. pageText.innerHTML+="Page "+curPage;
  4937. }
  4938. let preBtn=document.createElement("span");
  4939. preBtn.innerHTML="∧";
  4940. preBtn.title="Prev page";
  4941. preBtn.className="prevScreen";
  4942. 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";
  4943. let nextBtn=document.createElement("span");
  4944. nextBtn.innerHTML="∨";
  4945. nextBtn.title="Next page";
  4946. nextBtn.className="nextScreen";
  4947. 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";
  4948. let localPage=curPage;
  4949. preBtn.addEventListener("click", e=>{
  4950. e.stopPropagation();
  4951. e.preventDefault();
  4952. let prePageBar = document.querySelector("#pagetual_pageBar"+(localPage-1));
  4953. if (prePageBar) {
  4954. scrollToPageBar(prePageBar);
  4955. } else {
  4956. let scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
  4957. window.scrollTo({ top: scrollTop - (window.innerHeight || document.documentElement.clientHeight), behavior: 'smooth'});
  4958. }
  4959. });
  4960. nextBtn.addEventListener("click", e=>{
  4961. e.stopPropagation();
  4962. e.preventDefault();
  4963. let nextPageBar=document.querySelector("#pagetual_pageBar"+(localPage+1));
  4964. if (nextPageBar) {
  4965. scrollToPageBar(nextPageBar);
  4966. } else {
  4967. let nextEle = pageBar.parentNode.children[pageBar.parentNode.children.length - 1];
  4968. if (nextEle) scrollToPageBar(nextEle);
  4969. else {
  4970. scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  4971. window.scrollTo({ top: scrollH || 9999999, behavior: 'smooth'});
  4972. }
  4973. }
  4974. });
  4975. pageText.insertBefore(preBtn, pageText.firstChild);
  4976. pageText.insertBefore(nextBtn, pageText.firstChild);
  4977. pageBar.appendChild(downSpan);
  4978. if (forceState == 2) {
  4979. pageBar.style.width = "99%";
  4980. } else {
  4981. let parentStyle=_unsafeWindow.getComputedStyle(example.parentNode);
  4982. let parentWidth=example.parentNode.offsetWidth||parseInt(parentStyle.width);
  4983. pageBar.style.width=parentWidth-parseInt(parentStyle.paddingLeft)-parseInt(parentStyle.paddingRight)-10+"px";
  4984. pageBar.style.margin='10px 5px';
  4985. if(parentStyle.display=="grid" || parentStyle.display=="inline-grid"){
  4986. pageBar.style.gridColumnStart=1;
  4987. pageBar.style.gridColumnEnd=1+parseInt(example.parentNode.offsetWidth/example.offsetWidth);
  4988. }
  4989. if(inTable){
  4990. example=(example.tagName=="TR" || example.tagName=="TBODY")?example:example.previousElementSibling;
  4991. if(example.tagName=="TBODY")example=example.querySelector("tr");
  4992. let preTr=example;
  4993. while(preTr && preTr.children.length==0)preTr=preTr.previousElementSibling;
  4994. if(preTr)example=preTr;
  4995. let tdNum=0;
  4996. if (exampleStyle.display=="table-row") {
  4997. [].forEach.call(example.children, el=>{
  4998. tdNum+=el.colSpan||1;
  4999. });
  5000. } else {
  5001. [].forEach.call(example.children, el=>{
  5002. if(el.tagName=="TD" || el.tagName=="TH"){
  5003. tdNum+=el.colSpan||1;
  5004. }
  5005. });
  5006. }
  5007. pageBar.style.display="table-row";
  5008. pageBar.style.backgroundColor="unset";
  5009. pageBar.style.lineHeight="20px";
  5010. pageBar.style.boxShadow="";
  5011. pageBar.style.height="35px";
  5012. let td=document.createElement("td");
  5013. td.colSpan=tdNum||1;
  5014. let inTd=document.createElement("div");
  5015. inTd.style.backgroundColor="rgb(240 240 240 / 80%)";
  5016. inTd.style.borderRadius="20px";
  5017. inTd.style.padding="0 0";
  5018. inTd.style.margin="0";
  5019. inTd.style.lineHeight="20px";
  5020. inTd.style.textAlign="center";
  5021. inTd.style.boxShadow="rgb(0 0 0 / 67%) 0px 0px 10px 0px";
  5022. inTd.appendChild(upSpan);
  5023. inTd.appendChild(pageText);
  5024. if(pageNum)inTd.appendChild(pageNum);
  5025. inTd.appendChild(downSpan);
  5026. td.appendChild(inTd);
  5027. pageBar.appendChild(td);
  5028. }else if(inLi){
  5029. example=example.tagName=="LI"?example:example.previousElementSibling;
  5030. pageBar.style.display=getComputedStyle(example).display;
  5031. pageBar.style.backgroundColor="unset";
  5032. pageBar.style.lineHeight="20px";
  5033. pageBar.style.boxShadow="";
  5034. pageBar.style.height="35px";
  5035. let td=document.createElement("td");
  5036. td.colSpan=example.children.length;
  5037. td.style.width='100%';
  5038. let inTd=document.createElement("div");
  5039. inTd.style.backgroundColor="rgb(240 240 240 / 80%)";
  5040. inTd.style.borderRadius="20px";
  5041. inTd.style.margin="0"
  5042. inTd.style.padding="0 0";
  5043. inTd.style.textAlign="center";
  5044. inTd.style.minWidth="150px";
  5045. inTd.appendChild(upSpan);
  5046. inTd.appendChild(pageText);
  5047. inTd.style.width='calc(100% - 20px)';
  5048. inTd.style.boxShadow="rgb(0 0 0 / 67%) 0px 0px 10px 0px";
  5049. if(pageNum)inTd.appendChild(pageNum);
  5050. inTd.appendChild(downSpan);
  5051. if (pageBar.style.display === 'table-row') {
  5052. td.appendChild(inTd);
  5053. pageBar.appendChild(td);
  5054. } else {
  5055. inTd.style.width='100%';
  5056. pageBar.appendChild(inTd);
  5057. }
  5058. }
  5059. }
  5060.  
  5061. upSpan.addEventListener("click", e=>{
  5062. document.body.scrollTop=0;
  5063. document.documentElement.scrollTop=0;
  5064. e.preventDefault();
  5065. e.stopPropagation();
  5066. });
  5067. downSpan.addEventListener("click", e=>{
  5068. changeStop(true);
  5069. pageBar.title = i18n(isPause ? "enable" : "disable");
  5070. scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  5071. document.body.scrollTop = scrollH || 9999999;
  5072. document.documentElement.scrollTop = scrollH || 9999999;
  5073. e.preventDefault();
  5074. e.stopPropagation();
  5075. });
  5076. pageBar.addEventListener("click", e=>{
  5077. changeStop(!isPause);
  5078. pageBar.title=i18n(isPause?"enable":"disable");
  5079. });
  5080. ruleParser.insertElement(pageBar);
  5081. if(ruleParser.curSiteRule.pageBar && ruleParser.curSiteRule.pageBar !== 0){
  5082. try{
  5083. ((typeof _unsafeWindow.pagetualPageBar=='undefined') ? Function("pageBar",'"use strict";' + ruleParser.curSiteRule.pageBar) : _unsafeWindow.pagetualPageBar)(pageBar);
  5084. }catch(e){
  5085. debug(e);
  5086. }
  5087. }
  5088.  
  5089. let posEle=pageBar.nextElementSibling||pageBar;
  5090. while(posEle && !posEle.offsetParent){
  5091. posEle=posEle.previousElementSibling||posEle.parentNode;
  5092. }
  5093. if(posEle){
  5094. let actualTop = getElementTop(posEle);
  5095. bottomGap=scrollH-actualTop+(window.innerHeight||document.documentElement.clientHeight)*(ruleParser.curSiteRule.rate||rulesData.rate||1);
  5096. if(bottomGap<100)bottomGap=100;
  5097. }else{
  5098. bottomGap=1000;
  5099. }
  5100. return pageBar;
  5101. }
  5102.  
  5103. function emuClick(btn){
  5104. let orgHref=btn.getAttribute('href');
  5105. if(orgHref && orgHref != "#"){
  5106. btn.setAttribute('href', orgHref.replace(/#$/,""));
  5107. }
  5108. if(!PointerEvent)return btn.click();
  5109. let eventParam={
  5110. isTrusted: true,
  5111. altKey: false,
  5112. azimuthAngle: 0,
  5113. bubbles: true,
  5114. button: 0,
  5115. buttons: 0,
  5116. clientX: 1,
  5117. clientY: 1,
  5118. cancelBubble: false,
  5119. cancelable: true,
  5120. composed: true,
  5121. ctrlKey: false,
  5122. defaultPrevented: false,
  5123. detail: 1,
  5124. eventPhase: 2,
  5125. fromElement: null,
  5126. height: 1,
  5127. isPrimary: false,
  5128. metaKey: false,
  5129. pointerId: 1,
  5130. pointerType: "mouse",
  5131. pressure: 0,
  5132. relatedTarget: null,
  5133. returnValue: true,
  5134. shiftKey: false,
  5135. toElement: null,
  5136. twist: 0,
  5137. which: 1
  5138. };
  5139. let mouseEvent = new PointerEvent("mousedown",eventParam);
  5140. btn.dispatchEvent(mouseEvent);
  5141. mouseEvent = new PointerEvent("mouseup",eventParam);
  5142. btn.dispatchEvent(mouseEvent);
  5143. let dispatchTouchEvent = (ele, type) => {
  5144. let touchEvent;
  5145. try {
  5146. touchEvent = document.createEvent('TouchEvent')
  5147. touchEvent.initTouchEvent(type, true, true)
  5148. } catch (err) {
  5149. try {
  5150. touchEvent = document.createEvent('UIEvent')
  5151. touchEvent.initUIEvent(type, true, true)
  5152. } catch (err) {
  5153. touchEvent = document.createEvent('Event')
  5154. touchEvent.initEvent(type, true, true)
  5155. }
  5156. }
  5157. touchEvent.targetTouches = [{
  5158. pageX: 1,
  5159. pageY: 1,
  5160. clientX: 1,
  5161. clientY: 1,
  5162. target: btn
  5163. }];
  5164. touchEvent.touches = [{
  5165. pageX: 1,
  5166. pageY: 1,
  5167. clientX: 1,
  5168. clientY: 1,
  5169. target: btn
  5170. }];
  5171. touchEvent.changedTouches = [{
  5172. pageX: 1,
  5173. pageY: 1,
  5174. clientX: 1,
  5175. clientY: 1,
  5176. target: btn
  5177. }];
  5178. ele.dispatchEvent(touchEvent);
  5179. }
  5180. dispatchTouchEvent(btn, "touchstart");
  5181. dispatchTouchEvent(btn, "touchend");
  5182.  
  5183. btn.click();
  5184. if(orgHref && orgHref != "#"){
  5185. setTimeout(()=>btn.setAttribute('href', orgHref),0);
  5186. }
  5187. }
  5188.  
  5189. var failFromIframe=0;
  5190. var inCors=false;
  5191. var checkRemoveIntv;
  5192. function requestFromIframe(url, callback){
  5193. url = url.indexOf('=') == -1 ? url.replace(/#[^#]*/,"") : url;
  5194. let iframe = document.createElement('iframe');
  5195. iframe.name = 'pagetual-iframe';
  5196. iframe.width = '100%';
  5197. iframe.height = '1000';
  5198. iframe.frameBorder = '0';
  5199. if(ruleParser.curSiteRule.sandbox!=false){
  5200. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  5201. }
  5202. 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;';
  5203. let waitTime=100,checkEval;
  5204. if(ruleParser.curSiteRule.waitElement){
  5205. checkEval = doc => {
  5206. return ruleParser.waitElement(doc);
  5207. };
  5208. }else if(ruleParser.curSiteRule.wait){
  5209. if(isNaN(ruleParser.curSiteRule.wait)){
  5210. try{
  5211. checkEval=(typeof _unsafeWindow.pagetualWait=='undefined') ? Function("doc",'"use strict";' + ruleParser.curSiteRule.wait) : _unsafeWindow.pagetualWait;
  5212. }catch(e){
  5213. debug(e);
  5214. }
  5215. }else{
  5216. waitTime=ruleParser.curSiteRule.wait;
  5217. }
  5218. }
  5219. if (checkRemoveIntv) clearInterval(checkRemoveIntv);
  5220. checkRemoveIntv = setInterval(() => {
  5221. if (!iframe || !document.body.contains(iframe)) {
  5222. clearInterval(checkRemoveIntv);
  5223. loadPageOver();
  5224. }
  5225. }, 500);
  5226. let loadedHandler = e => {
  5227. if(e.data != 'pagetual-iframe:DOMLoaded' && e.type != 'load')return;
  5228. clearInterval(checkRemoveIntv);
  5229. window.removeEventListener('message', loadedHandler, false);
  5230. iframe.removeEventListener('load', loadedHandler, false);
  5231. let tryTimes=0;
  5232. function checkIframe(){
  5233. if (urlChanged || isPause) {
  5234. return callback(false, false);
  5235. }
  5236. try{
  5237. let doc=iframe.contentDocument || iframe.contentWindow.document;
  5238. let base=doc.querySelector("base");
  5239. ruleParser.basePath=base?base.href:url;
  5240. let eles=ruleParser.getPageElement(doc, iframe.contentWindow);
  5241. if(checkEval && !checkEval(doc)){
  5242. setTimeout(()=>{
  5243. checkIframe();
  5244. },waitTime);
  5245. return;
  5246. }else if(eles && eles.length>0){
  5247. callback(doc, eles);
  5248. }else if(tryTimes++ < 100){
  5249. setTimeout(()=>{
  5250. checkIframe();
  5251. },waitTime);
  5252. return;
  5253. }else{
  5254. if(failFromIframe++ > 2){
  5255. failFromIframe=0;
  5256. debug("Stop as failFromIframe");
  5257. isPause=true;
  5258. callback(false, false);
  5259. }else{
  5260. callback(false, false);
  5261. }
  5262. }
  5263. }catch(e){
  5264. debug("Stop as cors");
  5265. inCors=true;
  5266. if (forceState === 3) {
  5267. isPause=true;
  5268. }
  5269. if(!ruleParser.curSiteRule.pageElement){
  5270. ruleParser.curSiteRule.pageElement=allOfBody;
  5271. ruleParser.getInsert(true);
  5272. }
  5273. ruleParser.curSiteRule.action=0;
  5274. ruleParser.nextLinkHref=url;
  5275. callback(false, false);
  5276. nextPage();
  5277. }
  5278. document.body.removeChild(iframe);
  5279. }
  5280. setTimeout(()=>{
  5281. checkIframe();
  5282. },waitTime);
  5283. };
  5284. window.addEventListener('message', loadedHandler, false);
  5285. iframe.addEventListener('load', loadedHandler, false);
  5286. iframe.src=url;
  5287. document.body.appendChild(iframe);
  5288. }
  5289.  
  5290. var emuIframe,lastActiveUrl;
  5291. function emuPage(callback){
  5292. let orgPage=null,orgContent=null,preContent=null,iframeDoc,times=0,loadmoreBtn,pageEle,nextLink,loadmoreEnd=false,waitTimes=10,changed=false;
  5293. function returnFalse(log){
  5294. debug(log);
  5295. isPause=true;
  5296. callback(false, false);
  5297. if(emuIframe && emuIframe.parentNode){
  5298. emuIframe.parentNode.removeChild(emuIframe);
  5299. emuIframe=null;
  5300. }
  5301. }
  5302. async function checkPage(){
  5303. if(isPause)return loadPageOver();
  5304. try{
  5305. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  5306. }catch(e){
  5307. returnFalse("Stop as cors");
  5308. return;
  5309. }
  5310.  
  5311. let waitTime=200,checkEval;
  5312. if(ruleParser.curSiteRule.waitElement){
  5313. checkEval = doc => {
  5314. return ruleParser.waitElement(doc);
  5315. };
  5316. }else if(ruleParser.curSiteRule.wait){
  5317. if(isNaN(ruleParser.curSiteRule.wait)){
  5318. try{
  5319. checkEval=(typeof _unsafeWindow.pagetualWait=='undefined') ? Function("doc", '"use strict";' + ruleParser.curSiteRule.wait) : _unsafeWindow.pagetualWait;
  5320. }catch(e){
  5321. debug(e);
  5322. }
  5323. }else{
  5324. waitTime=ruleParser.curSiteRule.wait;
  5325. }
  5326. }
  5327.  
  5328. if(!orgPage){
  5329. if(!loadmoreEnd){
  5330. loadmoreBtn=getLoadMore(iframeDoc);
  5331. if(loadmoreBtn && isVisible(loadmoreBtn, iframeDoc.defaultView)){
  5332. emuClick(loadmoreBtn);
  5333. let intv=setInterval(()=>{
  5334. loadmoreBtn=getLoadMore(iframeDoc);
  5335. if(!loadmoreBtn || !document.body.contains(loadmoreBtn) || !isVisible(loadmoreBtn, iframeDoc.defaultView)){
  5336. clearInterval(intv);
  5337. loadmoreEnd=true;
  5338. setTimeout(()=>{
  5339. checkPage();
  5340. },500);
  5341. }else if(isInViewPort(loadmoreBtn)){
  5342. emuClick(loadmoreBtn);
  5343. }
  5344. },200);
  5345. return;
  5346. }else{
  5347. loadmoreEnd=true;
  5348. }
  5349. }
  5350. if(checkEval && !checkEval(iframeDoc)){
  5351. waitTimes=10;
  5352. setTimeout(()=>{
  5353. checkPage();
  5354. },waitTime);
  5355. return;
  5356. }else {
  5357. nextLink = await ruleParser.getNextLink(iframeDoc);
  5358. pageEle = ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true);
  5359. if (!pageEle || pageEle.length==0 || !nextLink) {
  5360. if (waitTimes-- > 0) {
  5361. setTimeout(() => {
  5362. checkPage();
  5363. }, waitTime);
  5364. return;
  5365. }
  5366. }
  5367. }
  5368. orgPage=pageEle;
  5369. if(!orgPage || orgPage.length==0){
  5370. returnFalse("Stop as no page when emu");
  5371. return;
  5372. }
  5373. if(orgPage[0].tagName=="UL")orgPage=orgPage[0].children;
  5374. if(nextLink){
  5375. orgPage=orgPage[parseInt(orgPage.length/2)];
  5376. if(orgPage.tagName=="IMG"){
  5377. if (!ruleParser.curSiteRule.lazyImgSrc) ruleParser.curSiteRule.lazyImgSrc = "0";
  5378. if (orgPage.src) {
  5379. orgContent = orgPage.src;
  5380. } else {
  5381. setTimeout(()=>{
  5382. checkPage();
  5383. },500);
  5384. return;
  5385. }
  5386. }else{
  5387. orgContent=orgPage.innerHTML;
  5388. }
  5389. preContent=orgContent;
  5390. if(!isVisible(nextLink, iframeDoc.defaultView)){
  5391. returnFalse("Stop as next hide when emu");
  5392. }else{
  5393. emuClick(nextLink);
  5394. setTimeout(()=>{
  5395. checkPage();
  5396. },500);
  5397. }
  5398. }else{
  5399. returnFalse("Stop as no next when emu");
  5400. }
  5401. return;
  5402. }
  5403. nextLink = nextLink || await ruleParser.getNextLink(iframeDoc);
  5404. if(!nextLink){
  5405. if(waitTimes-->0){
  5406. setTimeout(()=>{
  5407. checkPage();
  5408. },waitTime);
  5409. return;
  5410. }
  5411. }
  5412. if(times++ > 200){
  5413. returnFalse("Stop as timeout when emu");
  5414. return;
  5415. }
  5416. let eles=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true),checkItem;
  5417. if(eles && eles.length>0){
  5418. checkItem=eles;
  5419. if(eles[0].tagName=="UL")checkItem=eles[0].children;
  5420. checkItem=checkItem[parseInt(checkItem.length/2)];
  5421. }
  5422. if(!checkItem || (checkEval && !checkEval(iframeDoc))){
  5423. setTimeout(()=>{
  5424. checkPage();
  5425. },waitTime);
  5426. }else{
  5427. let checkInner;
  5428. if (checkItem.tagName == "IMG") {
  5429. if (checkItem.src) {
  5430. checkInner = checkItem.src;
  5431. } else {
  5432. setTimeout(() => {
  5433. checkPage();
  5434. }, waitTime);
  5435. return;
  5436. }
  5437. }else{
  5438. checkInner=checkItem.innerHTML;
  5439. }
  5440. if(orgPage!=checkItem || checkInner!=preContent){
  5441. changed=true;
  5442. orgPage=checkItem;
  5443. preContent=checkInner;
  5444. setTimeout(()=>{
  5445. checkPage();
  5446. },waitTime);
  5447. }else if(changed){
  5448. times = 0;
  5449. if (orgContent == preContent) {
  5450. returnFalse("Stop as same content");
  5451. } else {
  5452. callback(iframeDoc, eles);
  5453. }
  5454. }else{
  5455. if (times % 5 === 1) {
  5456. emuClick(nextLink);
  5457. }
  5458. setTimeout(()=>{
  5459. checkPage();
  5460. },waitTime);
  5461. }
  5462. }
  5463. }
  5464. if(!emuIframe){
  5465. let loaded=false;
  5466. emuIframe = document.createElement('iframe');
  5467. emuIframe.name = 'pagetual-iframe';
  5468. if(ruleParser.curSiteRule.sandbox!=false){
  5469. emuIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  5470. }
  5471. emuIframe.width = '100%';
  5472. emuIframe.height = '100';
  5473. emuIframe.frameBorder = '0';
  5474. 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;';
  5475. emuIframe.addEventListener("load", e => {
  5476. setTimeout(() => {
  5477. try {
  5478. iframeDoc = emuIframe.contentDocument || emuIframe.contentWindow.document;
  5479. } catch(e) {
  5480. returnFalse("Stop as cors");
  5481. return;
  5482. }
  5483. let code = ruleParser.curSiteRule.init;
  5484. if (code) {
  5485. try {
  5486. Function('doc','win','iframe','"use strict";' + code)(iframeDoc, iframeDoc.defaultView, emuIframe);
  5487. } catch(e) {
  5488. debug(e);
  5489. }
  5490. }
  5491. if (loaded) return;
  5492. loaded = true;
  5493. checkPage();
  5494. },500);
  5495. });
  5496. if (!lastActiveUrl) lastActiveUrl=location.href;
  5497. emuIframe.src = lastActiveUrl;
  5498. document.body.appendChild(emuIframe);
  5499. }else{
  5500. if (emuIframe.src != lastActiveUrl) emuIframe.src = lastActiveUrl;
  5501. checkPage();
  5502. }
  5503. }
  5504.  
  5505. var scrollToResizeInited = false;
  5506. var resizePool = [];
  5507. var scrollingToResize = false;
  5508.  
  5509. function scrollToResize(e) {
  5510. if (scrollingToResize) return;
  5511. else {
  5512. scrollingToResize = true;
  5513. let fitWidth = ruleParser.curSiteRule.fitWidth !== false;
  5514. let resizeHandler = () => {
  5515. resizePool.forEach(resizeArr => {
  5516. let iframe = resizeArr[1]();
  5517. let frameDoc = resizeArr[2]();
  5518. if(ruleParser.curSiteRule.singleUrl || forceState === 2){
  5519. iframe.style.height = (frameDoc.body.scrollHeight || frameDoc.body.offsetHeight) + "px";
  5520. iframe.style.minHeight = iframe.style.height;
  5521. iframe.style.width = "100%";
  5522. frameDoc.documentElement.scrollTop = 0;
  5523. frameDoc.documentElement.scrollLeft = 0;
  5524. }else{
  5525. let pageEle = resizeArr[0]();
  5526. if(pageEle){
  5527. let targetElement = pageEle[0];
  5528. if (!targetElement) return;
  5529. if(pageEle.length > 1){
  5530. targetElement = targetElement.parentNode;
  5531. }
  5532. let scrollHeight = targetElement.scrollHeight || targetElement.offsetHeight;
  5533. if(parseInt(iframe.style.height)==scrollHeight) return;
  5534. iframe.style.height=(scrollHeight+1)+"px";
  5535. let scrollTop = 0, scrollLeft = 0;
  5536. frameDoc.body.scrollTop = 0;
  5537. frameDoc.body.scrollLeft = 0;
  5538. while(targetElement && targetElement.offsetParent){
  5539. targetElement.offsetParent.scrollTop = targetElement.offsetTop;
  5540. if(targetElement.offsetParent.scrollTop == 0){
  5541. scrollTop += targetElement.offsetTop;
  5542. }
  5543. if(fitWidth){
  5544. targetElement.offsetParent.scrollLeft = targetElement.offsetLeft;
  5545. if(targetElement.offsetParent.scrollLeft == 0){
  5546. scrollLeft += targetElement.offsetLeft;
  5547. }
  5548. }
  5549. targetElement = targetElement.offsetParent;
  5550. }
  5551. frameDoc.documentElement.scrollTop = scrollTop;
  5552. frameDoc.documentElement.scrollLeft = scrollLeft;
  5553. if (frameDoc.documentElement.scrollTop == 0 && frameDoc.documentElement.scrollLeft == 0) {
  5554. frameDoc.body.scrollTop += scrollTop;
  5555. frameDoc.body.scrollLeft += scrollLeft;
  5556. }
  5557. if(!fitWidth && iframe.style.marginLeft == '0px'){
  5558. iframe.style.width = "100vw";
  5559. iframe.style.marginLeft = -iframe.getBoundingClientRect().left + "px";
  5560. }
  5561. }
  5562. }
  5563. });
  5564. };
  5565. setTimeout(() => {
  5566. scrollingToResize = false;
  5567. resizeHandler();
  5568. }, 200);
  5569. resizeHandler();
  5570. }
  5571. }
  5572.  
  5573. function forceIframe(url, callback){
  5574. url = url.indexOf('=') == -1 ? url.replace(/#[^#]*/,"") : url;
  5575. let curIframe = document.createElement('iframe'),iframeDoc,isloaded=false,inAction=true;
  5576. let loadedHandler = ()=>{
  5577. inAction=false;
  5578. if(isloaded)return;
  5579. isloaded=true;
  5580. ruleParser.insertPage(iframeDoc, [], url, null, true);
  5581. callback(curIframe, true);
  5582. let getIframe = () => {
  5583. return curIframe;
  5584. };
  5585. let getFrameDoc = () => {
  5586. return iframeDoc;
  5587. };
  5588. if(ruleParser.curSiteRule.singleUrl){
  5589. resizePool.push([() => {}, getIframe, getFrameDoc]);
  5590. }else{
  5591. let pageElement = ruleParser.getPageElement(iframeDoc,iframeDoc.defaultView);
  5592. let getPageEle = () => {
  5593. if (!pageElement || pageElement.length===0) {
  5594. pageElement = ruleParser.getPageElement(iframeDoc,iframeDoc.defaultView);
  5595. }
  5596. return pageElement;
  5597. };
  5598. resizePool.push([getPageEle, getIframe, getFrameDoc]);
  5599. }
  5600. scrollToResize();
  5601. };
  5602. curIframe.name = 'pagetual-iframe';
  5603. curIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  5604. curIframe.frameBorder = '0';
  5605. curIframe.scrolling="no";
  5606. 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;';
  5607. curIframe.addEventListener("load", e=>{
  5608. try{
  5609. iframeDoc=curIframe.contentDocument || curIframe.contentWindow.document;
  5610. }catch(e){
  5611. debug("Stop as cors");
  5612. isPause=true;
  5613. callback(false, false);
  5614. return;
  5615. }
  5616. let css=ruleParser.curSiteRule.css || rulesData.customCss;
  5617. if(css){
  5618. css = css.replace(/^inIframe:/, "");
  5619. let styleEle=iframeDoc.createElement("style");
  5620. styleEle.innerHTML=css;
  5621. iframeDoc.head.appendChild(styleEle);
  5622. }
  5623. loadedHandler();
  5624. let code=ruleParser.curSiteRule.init;
  5625. if(code){
  5626. try{
  5627. Function('doc','win','iframe','"use strict";' + code)(iframeDoc,iframeDoc.defaultView,curIframe);
  5628. }catch(e){
  5629. debug(e);
  5630. }
  5631. }
  5632. });
  5633. let checkTimes=0,findPageEle=false;
  5634. let forceRefresh=e=>{
  5635. if(inAction || !iframeDoc)return;
  5636. inAction=true;
  5637. let foundNext=()=>{
  5638. document.removeEventListener("scroll", forceRefresh);
  5639. }
  5640. setTimeout(async () => {
  5641. inAction=false;
  5642. if(!ruleParser.nextLinkHref){
  5643. checkTimes++;
  5644. await ruleParser.getNextLink(iframeDoc);
  5645. if(ruleParser.nextLinkHref){
  5646. foundNext();
  5647. }else if(checkTimes>=10){
  5648. foundNext();
  5649. }else if(checkTimes>=3 && !findPageEle){
  5650. let pageElement = ruleParser.getPageElement(iframeDoc,iframeDoc.defaultView);
  5651. if(!pageElement){
  5652. inAction=true;
  5653. curIframe.contentWindow.location.reload();
  5654. }else{
  5655. findPageEle=true;
  5656. }
  5657. }
  5658. }else{
  5659. foundNext();
  5660. }
  5661. },50);
  5662. };
  5663. document.addEventListener("scroll", forceRefresh);
  5664. curIframe.src=url;
  5665. let insert=ruleParser.getInsert();
  5666. if(ruleParser.curSiteRule.singleUrl || forceState==2){
  5667. document.body.appendChild(loadingDiv);
  5668. document.body.appendChild(curIframe);
  5669. }else{
  5670. ruleParser.insertElement(curIframe);
  5671. }
  5672.  
  5673. if (!scrollToResizeInited) {
  5674. scrollToResizeInited = true;
  5675. document.addEventListener("scroll", scrollToResize);
  5676. }
  5677. return curIframe;
  5678. }
  5679.  
  5680. function loadPageOver(){
  5681. isLoading = false;
  5682. stopScroll = true;
  5683. setTimeout(() => {stopScroll = false}, 500);
  5684. if(loadingDiv.parentNode){
  5685. loadingDiv.parentNode.removeChild(loadingDiv);
  5686. }
  5687. }
  5688.  
  5689. var tryTimes = 0;
  5690.  
  5691. async function nextPage(){
  5692. if(typeof ruleParser.curSiteRule.manualMode=='undefined' ? rulesData.manualMode : ruleParser.curSiteRule.manualMode)return;
  5693. if(typeof ruleParser.curSiteRule.clickMode=='undefined' ? rulesData.clickMode : ruleParser.curSiteRule.clickMode)return;
  5694. if(isPause || isLoading || forceState==1)return;
  5695. if(ruleParser.curSiteRule.delay){
  5696. try{
  5697. let checkDelay=((typeof _unsafeWindow.pagetualDelay=='undefined') ? Function('"use strict";' + ruleParser.curSiteRule.delay) : _unsafeWindow.pagetualDelay)();
  5698. if(!checkDelay)return;
  5699. }catch(e){
  5700. debug(e);
  5701. }
  5702. }
  5703. if(ruleParser.curSiteRule.pageElementCss || ruleParser.curSiteRule.pageElementStyle || rulesData.pageElementCss){
  5704. ruleParser.getPageElement(document, _unsafeWindow);
  5705. }
  5706. let nextLink = ruleParser.nextLinkHref;
  5707. if (!nextLink) {
  5708. if (curPage == 1) {
  5709. await ruleParser.getNextLink(document);
  5710. nextLink = ruleParser.nextLinkHref;
  5711. }
  5712. if (!nextLink) {
  5713. isLoading = true;
  5714. if (curPage == 1 && (ruleParser.curSiteRule.pinUrl || tryTimes++ <= 10)) {
  5715. setTimeout(() => {isLoading = false}, 500);
  5716. }
  5717. return;
  5718. }
  5719. }
  5720. let pvGallery=document.querySelector("span.pv-gallery-container");
  5721. if(pvGallery && pvGallery.style.display!="none")return;
  5722. let insert=ruleParser.getInsert();
  5723. if (insert) {
  5724. if (curPage == 1) {
  5725. /*window.postMessage({
  5726. insert: geneSelector(ruleParser.curSiteRule.insertPos == 2 ? insert : insert.parentNode, true),
  5727. command: 'pagetual.insert'
  5728. }, '*');*/
  5729. }
  5730. let isJs = ruleParser.curSiteRule.action == 3 || /^(javascript|#)/.test(nextLink.replace(location.href,""));
  5731. if(!isJs){
  5732. emuIframe=null;
  5733. lastActiveUrl=nextLink;
  5734. if(location.protocol=="https:" && /^http:/.test(nextLink)){
  5735. nextLink=nextLink.replace(/^http/,"https");
  5736. }
  5737. }
  5738. isLoading=true;
  5739. ruleParser.insertElement(loadingDiv);
  5740. let parent=loadingDiv.parentNode;
  5741. if(parent.tagName=="TBODY"){
  5742. parent=parent.parentNode;
  5743. }
  5744. if(parent.tagName=="TABLE"){
  5745. parent.parentNode.appendChild(loadingDiv);
  5746. }
  5747. loadingDiv.style.cssText=loadingCSS;
  5748. if (curPage == 1 && isJs && ruleParser.curSiteRule.singleUrl) {
  5749. loadingDiv.style.display = "none";
  5750. }
  5751. let sleep=ruleParser.curSiteRule.sleep||0;
  5752. setTimeout(()=>{
  5753. if(ruleParser.curSiteRule.pageElementByJs){
  5754. var over=ele=>{
  5755. loadPageOver();
  5756. if (urlChanged || isPause) return;
  5757. if (ele) {
  5758. createPageBar(nextLink);
  5759. ruleParser.insertPage(null, ele, nextLink, null, true);
  5760. if(autoLoadNum>=0){
  5761. if(autoLoadNum!=0 && --autoLoadNum==0){
  5762. autoLoadNum=-1;
  5763. }else{
  5764. setTimeout(() => nextPage(), 1);
  5765. }
  5766. }
  5767. }else{
  5768. debug("Stop as no page when get by js");
  5769. isPause=true;
  5770. }
  5771. };
  5772. try{
  5773. ((typeof _unsafeWindow.pagetualPageElementByJs=='undefined') ? Function("over",'"use strict";' + ruleParser.curSiteRule.pageElementByJs) : _unsafeWindow.pagetualPageElementByJs)(over);
  5774. }catch(e){
  5775. debug(e);
  5776. }
  5777. }else if((forceState==2||ruleParser.curSiteRule.action==2) && !isJs){
  5778. forceIframe(nextLink, (iframe, eles)=>{
  5779. loadPageOver();
  5780. if (urlChanged || isPause) return;
  5781. let pageBar = createPageBar(nextLink);
  5782. if (pageBar) iframe.parentNode.insertBefore(pageBar, iframe);
  5783. if (autoLoadNum >= 0) {
  5784. if (autoLoadNum != 0 && --autoLoadNum == 0) {
  5785. autoLoadNum=-1;
  5786. } else {
  5787. setTimeout(() => nextPage(), 1);
  5788. }
  5789. }
  5790. });
  5791. }else if((forceState==3||ruleParser.curSiteRule.action==1) && !isJs){
  5792. requestFromIframe(nextLink, (doc, eles)=>{
  5793. loadPageOver();
  5794. if (urlChanged || isPause) return;
  5795. if (eles) {
  5796. ruleParser.insertPage(doc, eles, nextLink, ()=>{
  5797. createPageBar(nextLink);
  5798. }, true);
  5799. if(autoLoadNum>=0){
  5800. if(autoLoadNum!=0 && --autoLoadNum==0){
  5801. autoLoadNum=-1;
  5802. }else{
  5803. setTimeout(() => nextPage(), 1);
  5804. }
  5805. }
  5806. }
  5807. });
  5808. }else{
  5809. if(!isJs){
  5810. requestDoc(nextLink, (eles)=>{
  5811. loadPageOver();
  5812. if (urlChanged || isPause) return;
  5813. if (eles) {
  5814. createPageBar(nextLink);
  5815. if(autoLoadNum>=0){
  5816. if(autoLoadNum!=0 && --autoLoadNum==0){
  5817. autoLoadNum=-1;
  5818. }else{
  5819. setTimeout(() => nextPage(), 1);
  5820. }
  5821. }
  5822. }
  5823. });
  5824. }else{
  5825. emuPage((doc, eles)=>{
  5826. loadPageOver();
  5827. if (urlChanged || isPause) return;
  5828. if (eles) {
  5829. ruleParser.insertPage(doc, eles, "", ()=>{
  5830. createPageBar(nextLink);
  5831. }, true);
  5832. if(autoLoadNum>=0){
  5833. if(autoLoadNum!=0 && --autoLoadNum==0){
  5834. autoLoadNum=-1;
  5835. }else{
  5836. setTimeout(() => nextPage(), 1);
  5837. }
  5838. }
  5839. }
  5840. });
  5841. }
  5842. }
  5843. },sleep);
  5844. }
  5845. }
  5846.  
  5847. function init(){
  5848. initRules(()=>{
  5849. initPage();
  5850. });
  5851. }
  5852.  
  5853. function visibilitychangeHandler(){
  5854. document.removeEventListener('visibilitychange', visibilitychangeHandler);
  5855. init();
  5856. }
  5857.  
  5858. setTimeout(()=>{
  5859. if (document.hidden) {
  5860. document.addEventListener('visibilitychange', visibilitychangeHandler);
  5861. } else {
  5862. init();
  5863. }
  5864. },100);
  5865. })();