东方永页机

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

当前为 2023-03-05 提交的版本,查看 最新版本

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