东方永页机

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

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

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

QingJ © 2025

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