东方永页机

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

当前为 2023-02-26 提交的版本,查看 最新版本

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址