东方永页机

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

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