东方永页机

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

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

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

QingJ © 2025

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