东方永页机

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

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

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