东方永页机

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

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

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

QingJ © 2025

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