东方永页机

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

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

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

QingJ © 2025

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