东方永页机

自动翻页脚本 - 自动加载并拼接下一分页内容,支持任意网页

当前为 2022-08-26 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Pagetual
  3. // @name:zh-CN 东方永页机
  4. // @name:zh-TW 東方永頁機
  5. // @name:ja 東方永頁機
  6. // @name:ru Пейджетуал
  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.30.7
  14. // @description Perpetual pages - most powerful auto-pager script, auto loading next paginated web pages and inserting into current page.
  15. // @description:zh-CN 自动翻页脚本 - 自动加载并拼接下一分页内容,支持任意网页
  16. // @description:zh-TW 自動翻頁脚本 - 自動加載並拼接下一分頁內容,支持任意網頁
  17. // @description:ja Webページを自動で読み込み継ぎ足し表示を行うブラウザ拡張です
  18. // @description:ru Просто автоматически загрузите следующую страницу
  19. // @description:de Laden Sie einfach automatisch die nächste Seite
  20. // @description:es Carga automática de páginas web paginadas
  21. // @description:fr Chargement automatique des pages Web paginées
  22. // @description:it Caricamento automatico di pagine Web impaginate
  23. // @description:ko 다음 페이지를 자동으로 로드하세요
  24. // @author hoothin
  25. // @match *://*/*
  26. // @license MIT
  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. // @run-at document-idle
  52. // @exclude http://www.toodledo.com/tasks/*
  53. // @exclude http*://maps.google.com*/*
  54. // @exclude *://www.google.*/_/chrome/newtab*
  55. // @exclude *://mega.*/*
  56. // @exclude *://*.mega.*/*
  57. // @exclude *://*.youku.com/v_*
  58. // @exclude *://*pan.baidu.com
  59. // @exclude *://*.iqiyi.com/v_*
  60. // @exclude *://*.iqiyi.com/w_*
  61. // @exclude *://*.iqiyi.com/a_*
  62. // @exclude *://*.le.com/ptv/vplay/*
  63. // @exclude *://v.qq.com/x/cover/*
  64. // @exclude *://v.qq.com/x/page/*
  65. // @exclude *://v.qq.com/tv/*
  66. // @exclude *://*.tudou.com/listplay/*
  67. // @exclude *://*.tudou.com/albumplay/*
  68. // @exclude *://*.tudou.com/programs/view/*
  69. // @exclude *://*.mgtv.com/b/*
  70. // @exclude *://film.sohu.com/album/*
  71. // @exclude *://tv.sohu.com/v/*
  72. // @exclude *://*.bilibili.com/video/*
  73. // @exclude *://*.bilibili.com/bangumi/play/*
  74. // @exclude *://*.baofeng.com/play/*
  75. // @exclude *://vip.pptv.com/show/*
  76. // @exclude *://v.pptv.com/show/*
  77. // @exclude *://www.le.com/ptv/vplay/*
  78. // @exclude *://www.wasu.cn/Play/show/*
  79. // @exclude *://m.v.qq.com/*
  80. // @exclude *://m.iqiyi.com/*
  81. // @exclude *://m.youku.com/alipay_video/*
  82. // @exclude *://m.mgtv.com/b/*
  83. // @exclude *://m.tv.sohu.com/v/*
  84. // @exclude *://m.film.sohu.com/album/*
  85. // @exclude *://m.le.com/ptv/vplay/*
  86. // @exclude *://m.pptv.com/show/*
  87. // @exclude *://m.acfun.cn/v/*
  88. // @exclude *://m.bilibili.com/video/*
  89. // @exclude *://m.bilibili.com/anime/*
  90. // @exclude *://m.bilibili.com/bangumi/play/*
  91. // @exclude *://m.wasu.cn/Play/show/*
  92. // @exclude *://www.youtube.com
  93. // @exclude *://www.youtube.com/
  94. // @exclude *://www.youtube.com/watch*
  95. // @exclude *://baike.baidu.com/*
  96. // @exclude *://*.instagram.com/*
  97. // @exclude *://order.jd.com/*
  98. // @exclude *://pagetual.hoothin.com/*
  99. // @exclude *://wenku.baidu.com/view/*
  100. // @connect *
  101. // ==/UserScript==
  102.  
  103. (function() {
  104. 'use strict';
  105.  
  106. if (window.name === 'pagetual-iframe' || (window.frameElement && window.frameElement.name === 'pagetual-iframe')) {
  107. var domloaded = function (){
  108. window.scroll(window.scrollX, 999999);
  109. window.parent.postMessage('pagetual-iframe:DOMLoaded', '*');
  110. };
  111. if(window.opera){
  112. document.addEventListener('DOMContentLoaded', domloaded, false);
  113. } else {
  114. domloaded();
  115. }
  116. return;
  117. }
  118.  
  119. if(window.top != window.self){
  120. try{
  121. if (top.location.hostname != window.location.hostname || window.top != window.parent) {
  122. return;
  123. }
  124. }catch(e){
  125. return;
  126. }
  127. }
  128.  
  129. const lang = navigator.appName=="Netscape"?navigator.language:navigator.userLanguage;
  130. let config={};
  131. switch (lang){
  132. case "zh-CN":
  133. case "zh-SG":
  134. config = {
  135. enableDebug:"调试模式,输出信息至控制台",
  136. disable:"暂时禁用",
  137. disableSite:"切换禁用状态",
  138. disableSiteTips:"已在此站禁用",
  139. enableSiteTips:"已在此站启用",
  140. enable:"启用翻页",
  141. toTop:"回到顶部",
  142. toBottom:"前往页尾",
  143. current:"当前页",
  144. forceIframe:"强制拼接",
  145. cancelForceIframe:"取消强制拼接",
  146. configure:"打开配置页面",
  147. firstUpdate:"点击此处初始化规则",
  148. update:"更新规则",
  149. click2update:"点击立即更新规则",
  150. loadNow:"立即翻页",
  151. loadConfirm:"要翻几页?(0为不间断)",
  152. noNext:"没有找到下一页,请新建规则",
  153. passSec:"更新于 #t# 秒前",
  154. passMin:"更新于 #t# 分钟前",
  155. passHour:"更新于 #t# 小时前",
  156. passDay:"更新于 #t# 天前",
  157. cantDel:"无法删除内置规则",
  158. confirmDel:"是否确认要删除此规则?",
  159. updateSucc:"更新成功",
  160. beginUpdate:"正在更新,请耐心等待,不要关闭页面",
  161. customUrls:"导入 Pagetual 或 AutoPagerize 规则 url,一行一条",
  162. customRules:"输入【东方永页机】格式的自定义规则",
  163. save:"保存设置",
  164. loadingText:"少女祈祷中...",
  165. opacity:"不透明值",
  166. opacityPlaceholder:"0:隐藏",
  167. hideBar:"隐藏分页隔条",
  168. dbClick2Stop:"空白处双击暂停翻页",
  169. sortTitle:"排序在下次更新规则后生效",
  170. autoRun:"自动启用,否则为白名单模式",
  171. autoLoadNum:"自动加载指定页数",
  172. inputPageNum:"输入页码跳转",
  173. enableHistory:"翻页后写入历史记录",
  174. initRun:"打开页面后立即尝试翻页,否则滚动至页尾再翻页",
  175. preload:"翻页前预读下一页,加速浏览",
  176. click2ImportRule:"点击下方添加特殊规则库,并静待更新成功:",
  177. forceAllBody:"是否拼接整个页面?",
  178. openInNewTab:"使拼接页面的内容在新页面打开",
  179. importSucc:"导入成功",
  180. import:"导入",
  181. editCurrent:"编辑此站规则",
  182. editBlacklist:"编辑黑名单网址,一行一条,支持? *通配符",
  183. upBtnImg:"回到页首图标",
  184. downBtnImg:"前往页尾图标",
  185. loadingTextTitle:"加载中文字",
  186. dbClick2StopCtrl:"Ctrl 键",
  187. dbClick2StopAlt:"Alt 键",
  188. dbClick2StopShift:"Shift 键",
  189. dbClick2StopMeta:"Meta 键",
  190. dbClick2StopKey:"快捷键",
  191. pageElementCss:"页面主体框架的样式",
  192. customCss:"自定义 CSS",
  193. firstAlert:"你还未导入规则库,请选择合适的规则库导入哦",
  194. picker:"东方永页机主体元素抓取器",
  195. closePicker:"关闭东方永页机抓取器",
  196. pickerPlaceholder:"没想法建议留空",
  197. pickerCheck:"检查你编辑的选择器并复制",
  198. switchSelector:"点击切换元素",
  199. gotoEdit:"使用当前的选择器前往编辑规则",
  200. manualMode:"禁用拼接,手动用右方向键翻页(或发送事件'pagetual.next')",
  201. nextSwitch:"切换其他页码",
  202. arrowToScroll:"左方向键滚动至上一页,右方向键滚动至下一页"
  203. };
  204. break;
  205. case "zh-TW":
  206. case "zh-HK":
  207. config = {
  208. enableDebug:"調試模式,輸出信息至控制台",
  209. disable:"暫時禁用",
  210. disableSite:"切換禁用狀態",
  211. disableSiteTips:"已在此站禁用",
  212. enableSiteTips:"已在此站啟用",
  213. enable:"啟用翻頁",
  214. toTop:"回到頂部",
  215. toBottom:"前往頁尾",
  216. current:"當前頁",
  217. forceIframe:"強制拼接",
  218. cancelForceIframe:"取消强制拼接",
  219. configure:"打開配置頁面",
  220. firstUpdate:"點擊此處初始化規則",
  221. update:"更新規則",
  222. click2update:"點擊立即更新規則",
  223. loadNow:"立即翻頁",
  224. loadConfirm:"要翻几頁?(0為不間斷)",
  225. noNext:"沒有找到下一頁,請新建規則",
  226. passSec:"更新于 #t# 秒前",
  227. passMin:"更新于 #t# 分鐘前",
  228. passHour:"更新于 #t# 小時前",
  229. passDay:"更新于 #t# 天前",
  230. cantDel:"無法刪除内置規則",
  231. confirmDel:"是否確認要刪除此規則?",
  232. updateSucc:"更新成功",
  233. beginUpdate:"正在更新,請稍候",
  234. customUrls:"導入 Pagetual 或 AutoPagerize 規則 url,一行一條",
  235. customRules:"輸入【東方永頁機】格式的自定義規則",
  236. save:"存儲設置",
  237. loadingText:"少女祈禱中...",
  238. opacity:"不透明值",
  239. opacityPlaceholder:"0:隱藏",
  240. hideBar:"隱藏分頁隔條",
  241. dbClick2Stop:"空白處雙擊暫停翻頁",
  242. sortTitle:"排序在下次更新規則後生效",
  243. autoRun:"自動啓用,否則為白名單模式",
  244. autoLoadNum:"自動加載指定頁數",
  245. inputPageNum:"輸入頁碼跳轉",
  246. enableHistory:"翻頁后寫入歷史記錄",
  247. initRun:"打開頁面后立即嘗試翻頁,否則滾動至頁尾再翻頁",
  248. preload:"翻頁前預讀下一頁,加速瀏覽",
  249. click2ImportRule:"點擊下方添加特殊規則庫,并靜待更新成功:",
  250. forceAllBody:"是否拼接整個頁面?",
  251. openInNewTab:"使拼接頁面的内容在新頁面打開",
  252. importSucc:"導入成功",
  253. import:"導入",
  254. editCurrent:"編輯此站規則",
  255. editBlacklist:"編輯黑名單網址,一行一條,支持? *通配符",
  256. upBtnImg:"回到頁首圖標",
  257. downBtnImg:"前往頁尾圖標",
  258. loadingTextTitle:"加載中文字",
  259. dbClick2StopCtrl:"Ctrl 鍵",
  260. dbClick2StopAlt:"Alt 鍵",
  261. dbClick2StopShift:"Shift 鍵",
  262. dbClick2StopMeta:"Meta 鍵",
  263. dbClick2StopKey:"快捷鍵",
  264. pageElementCss:"頁面主體框架的樣式",
  265. customCss:"自定義 CSS",
  266. firstAlert:"你還未導入規則庫,請選擇合適的規則庫導入哦",
  267. picker:"東方永頁機主體元素抓取器",
  268. closePicker:"關閉東方永頁機抓取器",
  269. pickerPlaceholder:"沒想法建議留空",
  270. pickerCheck:"檢查你編輯的選擇器並複製",
  271. switchSelector:"點擊切換元素",
  272. gotoEdit:"使用當前的選擇器前往編輯規則",
  273. manualMode:"禁用拼接,手動用右方向鍵翻頁(或發送事件'pagetual.next')",
  274. nextSwitch:"切換其他頁碼",
  275. arrowToScroll:"左方向鍵滾動至上一頁,右方向鍵滾動至下一頁"
  276. };
  277. break;
  278. case "ja":
  279. config = {
  280. enableDebug:"デバッグモード",
  281. disable: "一時的に無効にする",
  282. disableSite:"無効状態の切り替え",
  283. disableSiteTips:"このサイトで既に無効になっています",
  284. enableSiteTips:"このサイトで既に有効になっています",
  285. enable: "ページめくりを有効にする",
  286. toTop: "トップに戻る",
  287. toBottom: "ページの下部に移動",
  288. current: "現在のページ",
  289. forceIframe: "強制ステッチ",
  290. cancelForceIframe: "強制ステッチをキャンセル",
  291. configure: "設定ページを開く",
  292. firstUpdate:"ここをクリックしてルールを初期化します",
  293. update: "更新ルール",
  294. click2update:"今すぐルールを更新してください",
  295. loadNow:"今すぐページをめくる",
  296. loadConfirm:"数ページめくりたいですか?(0は途切れない)",
  297. noNext:"次のページが見つかりません、新しいルールを作成してください",
  298. passSec: "#t#秒前に更新",
  299. passMin: "#t#分前に更新",
  300. passHour: "#t#時間前に更新",
  301. passDay: "#t#日前に更新",
  302. cantDel: "組み込みルールを削除できません",
  303. confirmDel: "このルールを削除してもよろしいですか?",
  304. updateSucc: "更新に成功しました",
  305. beginUpdate: "更新中、お待ちください",
  306. customUrls: "インポートルールのURL、1行に1つ",
  307. customRules: "【東方永頁機】の形式でカスタムルールを入力してください",
  308. save: "設定を保存",
  309. loadingText: "少女祈祷中...",
  310. opacity:"不透明値",
  311. opacityPlaceholder:"0:隠す",
  312. hideBar:"ページ区切り文字を非表示にします",
  313. dbClick2Stop:"空白部分をダブルクリックしてページめくりを一時停止します",
  314. sortTitle:"並べ替えは、次のルールの更新後に有効になります",
  315. autoRun:"自動的に有効",
  316. autoLoadNum:"指定したページ数を自動的に読み込みます",
  317. inputPageNum:"ジャンプするページ番号を入力",
  318. enableHistory:"ページめくり後の履歴を書く",
  319. initRun:"Webページを開いた直後にページをめくる",
  320. preload:"事前に次のページを読む",
  321. click2ImportRule:"以下をクリックして、ルールベースを追加します:",
  322. forceAllBody:"フルページ埋め込み?",
  323. openInNewTab:"スプライスされたページのコンテンツを新しいページで開きます",
  324. importSucc:"インポート完了",
  325. import:"インポート",
  326. editCurrent:"現在のルールの編集",
  327. editBlacklist:"ブラックリストのURLを編集し、1行ずつ、サポート? *ワイルドカード",
  328. upBtnImg:"トップアイコンに戻る",
  329. downBtnImg:"フッターアイコンに移動",
  330. loadingTextTitle:"テキストをロード",
  331. dbClick2StopCtrl:"Ctrlキー",
  332. dbClick2StopAlt:"Altキー",
  333. dbClick2StopShift:"Shiftキー",
  334. dbClick2StopMeta:"Metaキー",
  335. dbClick2StopKey:"Shortcutキー",
  336. pageElementCss:"ページ本文フレームの STYLE",
  337. customCss:"カスタム CSS",
  338. firstAlert:"ルールベースをインポートしていないため、インポートする適切なルールベースを選択してください",
  339. picker:"Pagetualページ要素ピッカー",
  340. closePicker:"Pagetualピッカーを閉じる",
  341. pickerPlaceholder:"わからない場合は空のままにしてください",
  342. pickerCheck:"セレクターをチェックしてコピー",
  343. switchSelector:"クリックして要素を切り替えます",
  344. gotoEdit:"現在のセレクターでルールを編集する",
  345. manualMode:"スプライシングを無効にします。手動で右の矢印キーを使用してページをめくります",
  346. nextSwitch:"次のページに切り替え",
  347. arrowToScroll:"左矢印キーで前へ、右矢印キーで次へ"
  348. };
  349. break;
  350. case "ru":
  351. case "ru-RU":
  352. config = {
  353. enableDebug:"Включить отладку",
  354. disable:"Отключить",
  355. disableSite:"Переключить состояние отключения",
  356. disableSiteTips:"Отключено на этом сайте",
  357. enableSiteTips:"Включено на этом сайте",
  358. enable:"Включить",
  359. toTop:"В начало",
  360. toBottom:"В конец",
  361. current:"Текущая страница",
  362. forceIframe:"Принудительно присоединить следующую страницу",
  363. cancelForceIframe:"Отменить принудительное присоединение",
  364. configure:"Настроить",
  365. firstUpdate:"Нажмите здесь, чтобы инициализировать правила",
  366. update:"Обновить правила онлайн",
  367. click2update:"Нажмите, чтобы обновить правила по URL сейчас",
  368. loadNow:"Загрузить следующую страницу сейчас",
  369. loadConfirm:"Сколько страниц вы хотите загрузить? (0 означает бесконечность)",
  370. noNext:"Ссылка на следующую страницу не найдена, пожалуйста, создайте новое правило",
  371. passSec:"Обновлено #t# секунд назад",
  372. passMin:"Обновлено #t# минут назад",
  373. passHour:"Обновлено #t# часов назад",
  374. passDay:"Обновлено #t# дней назад",
  375. cantDel:"Невозможно удалить встроенные правила",
  376. confirmDel:"Вы уверены, что хотите удалить это правило?",
  377. updateSucc:"Обновление прошло успешно",
  378. beginUpdate:"Обновление начато, подождите минуту, пожалуйста",
  379. customUrls:"Импортировать URL-адрес правила Пэйджтуал или AutoPagerize по одному URL на строку",
  380. customRules:"Введите пользовательские правила с форматом [Pagetual]",
  381. save:"Сохранить",
  382. loadingText:"Shojo загружается...",
  383. opacity:"Непрозрачность",
  384. opacityPlaceholder:"0:скрыть",
  385. hideBar:"скрыть промежуток переключения страниц",
  386. dbClick2Stop:"Двойной щелчок по пустому пространству для паузы",
  387. sortTitle:"Сортировка вступает в силу после следующего обновления правила",
  388. autoRun:"Автозапуск (режим черного списка)",
  389. autoLoadNum:"Количество для предварительной загрузки страниц",
  390. inputPageNum:"Введите номер страницы для перехода",
  391. enableHistory:"Записать историю после переключения страниц",
  392. initRun:"Переключать страницы сразу после открытия",
  393. preload:"Предварительная загрузка следующей страницы для ускорения",
  394. click2ImportRule:"Нажмите, чтобы импортировать ссылку базовых правил, затем дождитесь завершения обновления:",
  395. forceAllBody:"Присоединить полное тело страницы?",
  396. openInNewTab:"Открыть дополнительные URL-адреса в новой вкладке",
  397. importSucc:"Импорт завершен",
  398. import:"Импорт",
  399. editCurrent:"Редактировать правило для текущего",
  400. editBlacklist:"Редактировать URL-адреса черного списка, по одной строке, поддержка ? * для подстановочного знака",
  401. upBtnImg:"Иконка возврата к началу",
  402. downBtnImg:"Иконка перехода в нижний колонтитул",
  403. loadingTextTitle:"Текст загрузки",
  404. dbClick2StopCtrl:"Клавиша Ctrl",
  405. dbClick2StopAlt:"Клавиша Alt",
  406. dbClick2StopShift:"Клавиша Shift",
  407. dbClick2StopMeta:"Клавиша Meta",
  408. dbClick2StopKey:"Клавиша быстрого доступа",
  409. pageElementCss:"Пользовательский стиль для основных элементов страницы",
  410. customCss:"Полный пользовательский CSS",
  411. firstAlert:"Вы не импортировали базовое правило, пожалуйста, выберите соответствующее правило для импорта",
  412. picker:"Выбор элемента страницы Пэйджтуал",
  413. closePicker:"Закрыть выбор Пэйджтуал",
  414. pickerPlaceholder:"Оставьте пустым, если вы не знаете",
  415. pickerCheck:"Проверить селектор и скопируй",
  416. switchSelector:"нажмите для переключения элемента",
  417. gotoEdit:"Перейти к редактированию правила с текущим селектором",
  418. manualMode:"Отключить автоматическую перелистывание страниц, перелистывать страницы вручную с помощью стрелок справа (или вызвать событие 'pagetual.next')",
  419. nextSwitch:"Переключить ссылку на следующую страницу",
  420. arrowToScroll:"Нажмите клавишу со стрелкой влево для предыдущего и клавишу со стрелкой вправо для следующего"
  421. };
  422. break;
  423. default:
  424. config = {
  425. enableDebug:"Enable debug output",
  426. disable:"Disable",
  427. disableSite:"Toggle disabled state",
  428. disableSiteTips:"Disabled on this site",
  429. enableSiteTips:"Enabled on this site",
  430. enable:"Enable",
  431. toTop:"To Top",
  432. toBottom:"To Bottom",
  433. current:"Current Page",
  434. forceIframe:"Force to join next page",
  435. cancelForceIframe:"Cancel Force join",
  436. configure:"Configure",
  437. firstUpdate:"Click here to initialize the rules",
  438. update:"Update online rules",
  439. click2update:"Click to update rules from url now",
  440. loadNow:"Load next page now",
  441. loadConfirm:"How much pages do you want to load? (0 means infinite)",
  442. noNext:"No next link found, please create a new rule",
  443. passSec:"Updated #t# seconds ago",
  444. passMin:"Updated #t# minutes ago",
  445. passHour:"Updated #t# hours ago",
  446. passDay:"Updated #t# days ago",
  447. cantDel:"Can't delete buildin rules",
  448. confirmDel:"Are you sure you want to delete this rule?",
  449. updateSucc:"Update succeeded",
  450. beginUpdate:"Begin update, wait a minute please",
  451. customUrls:"Import Pagetual or AutoPagerize rule url, One url per line",
  452. customRules:"Input custom rules with [Pagetual] format",
  453. save:"Save",
  454. loadingText:"Shojo Now Loading...",
  455. opacity:"Opacity",
  456. opacityPlaceholder:"0:hide",
  457. hideBar:"hide the paging spacer",
  458. dbClick2Stop:"Double-click on the blank space to pause",
  459. sortTitle:"Sorting takes effect after the next rule update",
  460. autoRun:"Auto run (black list mode)",
  461. autoLoadNum:"Amount for preload pages",
  462. inputPageNum:"Enter page number to jump",
  463. enableHistory:"Write history after page turning",
  464. initRun:"Turn pages immediately after opening",
  465. preload:"Preload next page for speeding up",
  466. click2ImportRule:"Click to import base rules link, then wait until the update is complete:",
  467. forceAllBody:"Join full body of page?",
  468. openInNewTab:"Open urls of additions in new tab",
  469. importSucc:"Import completed",
  470. import:"Import",
  471. editCurrent:"Edit rule for current",
  472. editBlacklist:"Edit the blacklist urls, line by line, Support ? * for wildcard",
  473. upBtnImg:"Icon of back to top",
  474. downBtnImg:"Icon of go to footer",
  475. loadingTextTitle:"Loading text",
  476. dbClick2StopCtrl:"Ctrl key",
  477. dbClick2StopAlt:"Alt key",
  478. dbClick2StopShift:"Shift key",
  479. dbClick2StopMeta:"Meta key",
  480. dbClick2StopKey:"Shortcut key",
  481. pageElementCss:"Custom style for main page elements",
  482. customCss:"Custom complete css",
  483. firstAlert:"You have not imported the base rule, please select the appropriate rule to import",
  484. picker:"Pagetual page element picker",
  485. closePicker:"Close Pagetual picker",
  486. pickerPlaceholder:"Leave empty if you have no idea",
  487. pickerCheck:"Check selector and copy",
  488. switchSelector:"Click to switch element",
  489. gotoEdit:"Go to edit rule with current selector",
  490. manualMode:"Disable splicing, manually turn pages with the right arrow keys (or dispatch event 'pagetual.next')",
  491. nextSwitch:"Switch next link",
  492. arrowToScroll:"Press left arrow key to scroll prev and right arrow key to scroll next"
  493. };
  494. break;
  495. }
  496. const noRuleTest=false;
  497. var enableDebug=true;
  498. function i18n(name, param) {
  499. return config[name]?config[name].replace("#t#",param):name;
  500. };
  501.  
  502. function debug(str) {
  503. if(enableDebug){
  504. console.log(
  505. `%cPagetual v.${_GM_info.script.version}】 debug`,
  506. 'color: yellow;font-size: x-large;font-weight: bold;'
  507. );
  508. console.debug(str);
  509. }
  510. };
  511.  
  512. var _GM_xmlhttpRequest,_GM_registerMenuCommand,_GM_notification,_GM_addStyle,_GM_openInTab,_GM_info,_GM_setClipboard;
  513. if(typeof GM_xmlhttpRequest!='undefined'){
  514. _GM_xmlhttpRequest=GM_xmlhttpRequest;
  515. }else if(typeof GM!='undefined' && typeof GM.xmlHttpRequest!='undefined'){
  516. _GM_xmlhttpRequest=GM.xmlHttpRequest;
  517. }else{
  518. _GM_xmlhttpRequest=(f)=>{fetch(f.url).then(response=>response.text()).then(data=>{let res={response:data};f.onload(res)}).catch(f.onerror())};
  519. }
  520. if(typeof GM_registerMenuCommand!='undefined'){
  521. _GM_registerMenuCommand=GM_registerMenuCommand;
  522. }else if(typeof GM!='undefined' && typeof GM.registerMenuCommand!='undefined'){
  523. _GM_registerMenuCommand=GM.registerMenuCommand;
  524. }else{
  525. _GM_registerMenuCommand=(s,f)=>{};
  526. }
  527. if(typeof GM_info!='undefined'){
  528. _GM_info=GM_info;
  529. }else if(typeof GM!='undefined' && typeof GM.info!='undefined'){
  530. _GM_info=GM.info;
  531. }else{
  532. _GM_info={script:1};
  533. }
  534. if(typeof GM_notification!='undefined'){
  535. _GM_notification=GM_notification;
  536. }else if(typeof GM!='undefined' && typeof GM.notification!='undefined'){
  537. _GM_notification=GM.notification;
  538. }else{
  539. _GM_notification=(s)=>{showTips(s)};
  540. }
  541. if(typeof GM_openInTab!='undefined'){
  542. _GM_openInTab=GM_openInTab;
  543. }else if(typeof GM!='undefined' && typeof GM.openInTab!='undefined'){
  544. _GM_openInTab=GM.openInTab;
  545. }else{
  546. _GM_openInTab=(s,t)=>{window.open(s)};
  547. }
  548. if(typeof GM_addStyle!='undefined'){
  549. _GM_addStyle=GM_addStyle;
  550. }else if(typeof GM!='undefined' && typeof GM.addStyle!='undefined'){
  551. _GM_addStyle=GM.addStyle;
  552. }else{
  553. _GM_addStyle=cssStr=>{
  554. let styleEle=document.createElement("style");
  555. styleEle.innerHTML=cssStr;
  556. document.head.appendChild(styleEle);
  557. };
  558. }
  559. if (typeof GM_setClipboard != 'undefined') {
  560. _GM_setClipboard = GM_setClipboard;
  561. } else if (typeof GM != 'undefined' && typeof GM.setClipboard != 'undefined') {
  562. _GM_setClipboard = GM.setClipboard;
  563. } else {
  564. _GM_setClipboard = (s, i) => {};
  565. }
  566. var _unsafeWindow=(typeof unsafeWindow=='undefined')?window:unsafeWindow;//兼容 ios userscripts 的寫法
  567. var storage={
  568. supportGM: typeof GM_getValue=='function' && typeof GM_getValue('a','b')!='undefined',
  569. supportGMPromise: typeof GM!='undefined' && typeof GM.getValue=='function' && typeof GM.getValue('a','b')!='undefined',
  570. mxAppStorage:(function(){
  571. try{
  572. return window.external.mxGetRuntime().storage;
  573. }catch(e){
  574. }
  575. })(),
  576. operaUJSStorage:(function(){
  577. try{
  578. return window.opera.scriptStorage;
  579. }catch(e){
  580. }
  581. })(),
  582. setItem:function(key,value){
  583. if(this.operaUJSStorage){
  584. this.operaUJSStorage.setItem(key,value);
  585. }else if(this.mxAppStorage){
  586. this.mxAppStorage.setConfig(key,value);
  587. }else if(this.supportGM){
  588. GM_setValue(key,value);
  589. if(value==="" && typeof GM_deleteValue!='undefined'){
  590. GM_deleteValue(key);
  591. }
  592. }else if(this.supportGMPromise){
  593. GM.setValue(key,value);
  594. if(value==="" && typeof GM!='undefined' && typeof GM.deleteValue!='undefined'){
  595. GM.deleteValue(key);
  596. }
  597. }else if(window.localStorage){
  598. window.localStorage.setItem(key,value);
  599. }
  600. },
  601. getItem:function(key,cb){
  602. var value;
  603. if(this.operaUJSStorage){
  604. value=this.operaUJSStorage.getItem(key);
  605. }else if(this.mxAppStorage){
  606. value=this.mxAppStorage.getConfig(key);
  607. }else if(this.supportGM){
  608. value=GM_getValue(key);
  609. }else if(this.supportGMPromise){
  610. value=GM.getValue(key).then(v=>{cb(v)});
  611. return;
  612. }else if(window.localStorage){
  613. value=window.localStorage.getItem(key);
  614. };
  615. cb(value);
  616. }
  617. };
  618. var rulesData={},ruleUrls,updateDate;
  619. const configPage="https://github.com/hoothin/UserScripts/tree/master/Pagetual";
  620. const guidePage=/^https?:\/\/.*\/PagetualGuide\/.*rule\.html/;
  621. const ruleImportUrlReg=/greasyfork\.org\/.*scripts\/438684[^\/]*(\/discussions|\/?$)|github\.com\/hoothin\/UserScripts\/(tree\/master\/Pagetual|issues)/i;
  622. const allOfBody="body>*";
  623. _GM_registerMenuCommand(i18n("configure"), ()=>{
  624. _GM_openInTab(configPage,{active:true});
  625. });
  626. _GM_registerMenuCommand(i18n("editCurrent"), ()=>{
  627. Picker.getInstance().start();
  628. });
  629.  
  630. function getElementByXpath(xpath, contextNode, doc){
  631. doc = doc || document;
  632. contextNode = contextNode || doc;
  633. try {
  634. var result = doc.evaluate(xpath, contextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
  635. return result.singleNodeValue && result.singleNodeValue.nodeType === 1 && result.singleNodeValue;
  636. } catch (err) {
  637. throw new Error(`Invalid xpath: ${xpath}`);
  638. }
  639. }
  640.  
  641. function getAllElementsByXpath(xpath, contextNode, doc){
  642. doc = doc || document;
  643. contextNode = contextNode || doc;
  644. var result = [];
  645. try {
  646. var query = doc.evaluate(xpath, contextNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  647. for (var i = 0; i < query.snapshotLength; i++) {
  648. var node = query.snapshotItem(i);
  649. if (node.nodeType === 1) result.push(node);
  650. }
  651. } catch (err) {
  652. throw new Error(`Invalid xpath: ${xpath}`);
  653. }
  654. return result;
  655. }
  656.  
  657. function isXPath(xpath) {
  658. if (!xpath) return false;
  659. return /^\(*(descendant::|\.\/|\/\/|id\()/.test(xpath);
  660. }
  661.  
  662. function getAllElements(sel, doc) {
  663. try {
  664. if (!isXPath(sel)) {
  665. return doc.querySelectorAll(sel);
  666. }
  667. } catch(e) {
  668. debug(e);
  669. }
  670. return getAllElementsByXpath(sel, doc, doc);
  671. }
  672.  
  673. function getElement(sel, doc) {
  674. try {
  675. if (!isXPath(sel)) {
  676. return doc.querySelector(sel);
  677. }
  678. } catch(e) {
  679. debug(e);
  680. }
  681. return getElementByXpath(sel, doc, doc);
  682. }
  683.  
  684. function geneSelector(ele, addID){
  685. let selector=ele.tagName.toLowerCase();
  686. //Google id class都是隨機。百度更過分,style script順序都是隨機的
  687. if(ele.tagName!="HTML" && ele.tagName!="BODY"){
  688. if(addID && ele.id) selector += '#' + ele.id;
  689. if(ele.className) selector += [].map.call(ele.classList,d=>/^[\w-_]+$/.test(d)?('.'+d):"").join('');
  690. let parent = ele.parentElement;
  691. if(parent){
  692. selector = geneSelector(parent, addID) + ' > ' + selector;
  693. if(!ele.className && (!ele.id || !addID) && parent.children.length>1){
  694. let i,j=0;
  695. for(i=0;i<parent.children.length;i++){
  696. if(parent.children[i].tagName==ele.tagName){
  697. j++;
  698. if(parent.children[i]==ele){
  699. break;
  700. }
  701. }
  702. }
  703. selector += (parent.tagName=="HTML"?"":`:nth-of-type(${j})`);
  704. }
  705. }
  706. }
  707. return selector;
  708. }
  709.  
  710. function createXPathFromElement(elm) {
  711. let allNodes = document.getElementsByTagName('*'), segs;
  712. for (segs = []; elm && elm.nodeType == 1; elm = elm.parentNode) {
  713. if (elm.hasAttribute('id')) {
  714. var uniqueIdCount = 0;
  715. for (var n=0;n < allNodes.length;n++) {
  716. if (allNodes[n].hasAttribute('id') && allNodes[n].id == elm.id) uniqueIdCount++;
  717. if (uniqueIdCount > 1) break;
  718. }
  719. if ( uniqueIdCount == 1) {
  720. segs.unshift('id("' + elm.getAttribute('id') + '")');
  721. return segs.join('/');
  722. } else {
  723. segs.unshift(elm.localName.toLowerCase() + '[@id="' + elm.getAttribute('id') + '"]');
  724. }
  725. } else if (elm.hasAttribute('class')) {
  726. segs.unshift(elm.localName.toLowerCase() + '[@class="' + elm.getAttribute('class') + '"]');
  727. } else {
  728. let i, sib;
  729. for (i = 1, sib = elm.previousSibling; sib; sib = sib.previousSibling) {
  730. if (sib.localName == elm.localName) i++;
  731. }
  732. segs.unshift(elm.localName.toLowerCase() + '[' + i + ']');
  733. }
  734. }
  735. return segs.length ? '/' + segs.join('/') : null;
  736. }
  737.  
  738. var escapeHTMLPolicy;
  739. if (_unsafeWindow.trustedTypes && _unsafeWindow.trustedTypes.createPolicy) {
  740. escapeHTMLPolicy = _unsafeWindow.trustedTypes.createPolicy('default', {
  741. createHTML: (string, sink) => string
  742. });
  743. }
  744.  
  745. function createHTML(html){
  746. return escapeHTMLPolicy?escapeHTMLPolicy.createHTML(html):html;
  747. }
  748.  
  749. class RuleParser {
  750. constructor() {
  751. this.hpRules=[];
  752. this.customRules=[];
  753. this.rules=[];
  754. this.pageDoc=document;
  755. this.nextLinkHref=null;
  756. this.nextTitle="";
  757. this.oldUrl="";
  758. this.curUrl=location.href;
  759. this.curSiteRule={};
  760. }
  761.  
  762. initSavedRules(callback){
  763. var self=this;
  764. storage.getItem("hpRules", hpRules=>{
  765. if(hpRules)self.hpRules=hpRules;
  766. storage.getItem("customRules", customRules=>{
  767. if(customRules)self.customRules=customRules;
  768. storage.getItem("rules", rules=>{
  769. if(rules)self.rules=rules;
  770. callback();
  771. });
  772. });
  773. });
  774. }
  775.  
  776. saveCurSiteRule(){
  777. if(!this.curSiteRule || !this.curSiteRule.url || this.curSiteRule.singleUrl || this.curSiteRule.url.length<13)return;
  778. this.hpRules=this.hpRules.filter(item=>{return item&&item.url!=this.curSiteRule.url});
  779. this.hpRules.unshift(this.curSiteRule);
  780. if(this.hpRules.length>30){
  781. this.hpRules.pop();
  782. }
  783. storage.setItem("hpRules", this.hpRules);
  784. }
  785.  
  786. requestJSON(url, callback){
  787. _GM_xmlhttpRequest({
  788. url: url,
  789. method: 'GET',
  790. timeout: 20000,
  791. onload: function(res) {
  792. let json=null;
  793. try{
  794. json=JSON.parse(res.response||res.responseText);
  795. }catch(e){
  796. debug(e);
  797. }
  798. callback(json);
  799. },
  800. onerror: function(e) {
  801. callback(null, e);
  802. },
  803. ontimeout: function(e) {
  804. callback(null, e);
  805. }
  806. });
  807. }
  808.  
  809. formatRule(item, from){
  810. if(item.data && item.data.url){
  811. return {
  812. name:item.name,
  813. from:from,
  814. type:0,
  815. action:item.data.forceIframe=="true"?1:0,
  816. url:item.data.url,
  817. pageElement:item.data.pageElement,
  818. nextLink:item.data.nextLink,
  819. insert:item.data.insertBefore||undefined,
  820. updatedAt:item.updated_at,
  821. css:(item.data.Stylus && item.data.CSS) ? (item.data.Stylus + item.data.CSS) : (item.data.Stylus || item.data.CSS),
  822. pageAction:item.data.bookmarklet
  823. };
  824. }else{
  825. item.from=from;
  826. return item;
  827. }
  828. return null;
  829. }
  830.  
  831. addRuleByUrl(url, from, callback) {
  832. if(url.indexOf("?")==-1){
  833. url=url+"?"+Date.now();
  834. }else{
  835. url=url+"&"+Date.now();
  836. }
  837. this.requestJSON(url, (json,err)=>{
  838. if(!json){
  839. debug("Update "+url+" rules fail!");
  840. debug(err);
  841. }
  842. this.addRules(json, from);
  843. callback(json, err);
  844. });
  845. }
  846.  
  847. addRules(rules, from) {
  848. if(rules && rules.length>0){
  849. this.rules=this.rules.filter(item=>{return item.from!=from});
  850. rules.forEach(item=>{
  851. let rule=this.formatRule(item, from);
  852. if(rule){
  853. this.rules.unshift(rule);
  854. }
  855. });
  856. }
  857. }
  858.  
  859. ruleMatch(r) {
  860. let findIndex = 0;
  861. if (r.nextLink && r.nextLink != "0" && r.nextLink != 0) {
  862. let nextLinkSel = r.nextLink, nextLink;
  863. if (Array && Array.isArray && Array.isArray(nextLinkSel)) {
  864. nextLink = !nextLinkSel.every((sel, i) => {
  865. let ele = getElement(sel, document);
  866. if (ele) findIndex = i;
  867. return !ele;
  868. });
  869. } else nextLink = getElement(nextLinkSel, document);
  870. if (!nextLink) return false;
  871. }
  872. if (r.pageElement) {
  873. let pageElementSel = r.pageElement, pageElement;
  874. if (Array && Array.isArray && Array.isArray(pageElementSel)) {
  875. pageElementSel = pageElementSel[findIndex];
  876. }
  877. pageElement = getElement(pageElementSel, document);
  878. if (!pageElement) return false;
  879. }
  880. if (r.insert) {
  881. let insertSel = r.insert, insert;
  882. if (Array && Array.isArray && Array.isArray(insertSel)) {
  883. insertSel = insertSel[findIndex];
  884. }
  885. insert = getElement(insertSel, document);
  886. if (!insert) return false;
  887. }
  888. //if (findIndex !== 0) nextIndex = findIndex;
  889. return true;
  890. }
  891.  
  892. waitElement(doc, selArr) {
  893. if (!selArr) selArr = this.curSiteRule.waitElement;
  894. if (selArr[0].trim()) {
  895. let include = getElement(selArr[0], doc);
  896. if (!include) return false;
  897. }
  898. if (doc === document) return true;
  899. if (selArr.length==2 && selArr[1].trim()) {
  900. let exclude = getElement(selArr[1], doc);
  901. if (exclude) {
  902. var actualTop = exclude.offsetTop;
  903. var current = exclude.offsetParent;
  904. while(current !== null){
  905. actualTop += current.offsetTop;
  906. current = current.offsetParent;
  907. }
  908. doc.body.scrollTop = 0;
  909. doc.documentElement.scrollTop = 0;
  910. doc.body.scrollTop = actualTop;
  911. doc.documentElement.scrollTop = actualTop;
  912. doc.body.scrollTop = actualTop + 10;
  913. doc.documentElement.scrollTop = actualTop + 10;
  914. doc.body.scrollTop = actualTop + 50;
  915. doc.documentElement.scrollTop = actualTop + 50;
  916. doc.body.scrollTop = actualTop + 200;
  917. doc.documentElement.scrollTop = actualTop + 200;
  918. return false;
  919. }
  920. }
  921. return true;
  922. }
  923.  
  924. getRule(callback) {
  925. if(noRuleTest){
  926. this.curSiteRule={};
  927. this.curSiteRule.url=location.origin+location.pathname;
  928. this.curSiteRule.singleUrl=true;
  929. callback();
  930. return;
  931. }
  932. if(this.curSiteRule && this.curSiteRule.url){
  933. return this.curSiteRule;
  934. }
  935. var self=this;
  936.  
  937. function setRule(r) {
  938. self.curSiteRule=r;
  939. debug(r);
  940. callback();
  941. }
  942.  
  943. function checkRule(r) {
  944. let urlReg=new RegExp(r.url, "i");
  945. if(urlReg.test(location.href)){
  946. if(r.include){
  947. let include=getElement(r.include, document);
  948. if(!include)return false;
  949. }
  950. if(r.exclude){
  951. let exclude=getElement(r.exclude, document);
  952. if(exclude)return false;
  953. }
  954. if(r.waitElement){
  955. let waitTime=500;
  956. let checkReady=()=>{
  957. setTimeout(()=>{
  958. if(!self.waitElement(document, r.waitElement)){
  959. checkReady();
  960. }else{
  961. setRule(r);
  962. }
  963. },parseInt(waitTime));
  964. };
  965. checkReady();
  966. return true;
  967. }else if(r.wait){
  968. let waitTime=500, checkEval, maxCheckTimes=20;
  969. if(isNaN(r.wait)){
  970. try{
  971. checkEval=(typeof _unsafeWindow.pagetualWait=='undefined') ? Function("doc",'"use strict";' + r.wait) : _unsafeWindow.pagetualWait;
  972. }catch(e){
  973. debug(e);
  974. }
  975. }else{
  976. waitTime=r.wait;
  977. }
  978. let checkReady=()=>{
  979. if(maxCheckTimes--<=0){
  980. debug("Wait for rule ready but failed");
  981. setRule(r);
  982. return;
  983. }
  984. setTimeout(()=>{
  985. if(!self.ruleMatch(r) || (checkEval && !checkEval(document))){
  986. checkReady();
  987. }else{
  988. setRule(r);
  989. }
  990. },parseInt(waitTime));
  991. };
  992. checkReady();
  993. return true;
  994. }
  995. if(r.pinUrl){
  996. setRule(r);
  997. return true;
  998. }
  999. if(!self.ruleMatch(r)){
  1000. return false;
  1001. }
  1002. setRule(r);
  1003. return true;
  1004. }
  1005. return false;
  1006. }
  1007.  
  1008. for(let i in this.hpRules){
  1009. let rule=this.hpRules[i];
  1010. if(!rule || !rule.url)continue;
  1011. if(rule.singleUrl){
  1012. if(location.origin+location.pathname==rule.url){
  1013. setRule(rule);
  1014. return;
  1015. }
  1016. continue;
  1017. }
  1018. if(checkRule(rule))return;
  1019. }
  1020. for(let i in this.customRules){
  1021. let rule=this.customRules[i];
  1022. if(!rule || !rule.url)continue;
  1023. if(checkRule(rule))return;
  1024. }
  1025. let r=0;
  1026. function searchByTime(){
  1027. setTimeout(()=>{
  1028. let end=r+10;
  1029. end=end>self.rules.length?self.rules.length:end;
  1030. for(;r<end;r++){
  1031. let rule=self.rules[r];
  1032. if(checkRule(rule))return;
  1033. }
  1034. if(end>=self.rules.length){
  1035. self.curSiteRule={};
  1036. self.curSiteRule.url=location.origin+location.pathname;
  1037. self.curSiteRule.singleUrl=true;
  1038. callback();
  1039. return;
  1040. }else{
  1041. searchByTime();
  1042. }
  1043. },1);
  1044. }
  1045. searchByTime();
  1046. }
  1047.  
  1048. getPageElement(doc, curWin, dontFind) {
  1049. if(doc==document && this.docPageElement){
  1050. let parent=this.docPageElement;
  1051. while(parent && parent.nodeName!="BODY"){
  1052. parent=parent.parentNode;
  1053. }
  1054. if(parent && parent.nodeName=="BODY"){
  1055. return this.docPageElement;
  1056. }
  1057. }
  1058. let pageElement=null;
  1059. let self=this;
  1060. let body=doc.body;
  1061. if(this.curSiteRule.pageElement){
  1062. let pageElementSel=this.curSiteRule.pageElement;
  1063. if(Array && Array.isArray && Array.isArray(pageElementSel)){
  1064. pageElementSel=pageElementSel[nextIndex<pageElementSel.length?nextIndex:0];
  1065. }
  1066. pageElement=getAllElements(pageElementSel, doc);
  1067. }
  1068. if(pageElement && pageElement.length===1 && pageElement[0].style.display==='none'){
  1069. pageElement=[body];
  1070. }
  1071. if(this.curSiteRule.singleUrl && pageElement && pageElement.length>0 && pageElement[0].tagName=="TR"){
  1072. let mainTr=this.insert.parentNode.querySelector('tr'),mainTdNum=0,newTdNum=0;
  1073. [].forEach.call(mainTr.children, el=>{
  1074. if(el.tagName=="TD" || el.tagName=="TH"){
  1075. mainTdNum+=el.colSpan||1;
  1076. }
  1077. });
  1078. [].forEach.call(pageElement[0].children, el=>{
  1079. if(el.tagName=="TD" || el.tagName=="TH"){
  1080. newTdNum+=el.colSpan||1;
  1081. }
  1082. });
  1083. if(mainTdNum!=newTdNum){
  1084. this.curSiteRule.pageElement=allOfBody;
  1085. pageElement=[body];
  1086. this.getInsert(true);
  1087. }
  1088. }
  1089. if((this.curSiteRule.singleUrl || !this.curSiteRule.pageElement) && (!pageElement || pageElement.length==0) && curWin && !dontFind){
  1090. if(!body)return null;
  1091. let bodyHeight=parseInt(body.offsetHeight || body.scrollHeight);
  1092. let curHeight=bodyHeight;
  1093. let windowHeight=window.innerHeight || document.documentElement.clientHeight;
  1094. let needCheckNext=(doc==document && this.initNext);
  1095. function checkElement(ele){
  1096. if(ele.childNodes && ele.childNodes.length==1)ele=ele.childNodes[0];
  1097. if(ele.tagName=="PICTURE"){
  1098. self.curSiteRule.pageElement=geneSelector(ele.parentNode)+">"+ele.tagName.toLowerCase();
  1099. debug(self.curSiteRule.pageElement);
  1100. return [ele];
  1101. }
  1102. if(curHeight/bodyHeight<=0.25){
  1103. self.curSiteRule.pageElement=allOfBody;
  1104. debug(self.curSiteRule.pageElement);
  1105. return [body];
  1106. }
  1107. if(ele.tagName=="FORM"){
  1108. self.curSiteRule.pageElement=geneSelector(ele)+">*";
  1109. debug(self.curSiteRule.pageElement);
  1110. return ele.children;
  1111. }
  1112. if(ele.children.length==0 && !self.curSiteRule.pageElement){
  1113. if(ele.parentNode.tagName=="P")ele=ele.parentNode;
  1114. self.curSiteRule.pageElement=geneSelector(ele.parentNode)+">"+ele.tagName.toLowerCase();
  1115. debug(self.curSiteRule.pageElement);
  1116. return [ele];
  1117. }
  1118. let i,maxHeight=curHeight*0.55,curMaxEle=null,curMaxArea=0,maxWidth=0;
  1119. let isHori=true;
  1120. let offsetTop=ele.children[0].offsetTop;
  1121. for(i=1;i<ele.children.length;i++){
  1122. if(ele.children[i].offsetTop!=offsetTop){
  1123. isHori=false;
  1124. break;
  1125. }
  1126. }
  1127. let sameClassName = null, hasSameClass = false;
  1128. for(i=0;i<ele.children.length;i++){
  1129. let curNode=ele.children[i];
  1130. if(curNode.tagName=="CANVAS")continue;
  1131. if(curNode.tagName!="IMG" && /^\s*$/.test(curNode.innerText))continue;
  1132. if(curNode.className && sameClassName !== ''){
  1133. if (sameClassName === null) sameClassName = curNode.className;
  1134. else {
  1135. if (sameClassName != curNode.className) {
  1136. sameClassName = '';
  1137. hasSameClass = false;
  1138. } else hasSameClass = true;
  1139. }
  1140. }
  1141. if(needCheckNext && !curNode.contains(self.initNext) && getElementTop(curNode)>windowHeight){
  1142. continue;
  1143. }
  1144. let comStyle=curWin.getComputedStyle(curNode);
  1145. let h=parseInt(curNode.offsetHeight || curNode.scrollHeight);
  1146. let w=parseInt(curNode.scrollWidth);
  1147. if(isNaN(h) || isNaN(w))continue;
  1148. if(isHori && h<=50)continue;
  1149. let a=h*w+h,moreChild=curNode.children[0];
  1150. while(moreChild){
  1151. comStyle=curWin.getComputedStyle(moreChild);
  1152. let ch=parseInt(moreChild.offsetHeight || moreChild.scrollHeight);
  1153. let cw=parseInt(moreChild.scrollWidth);
  1154. if(h<ch)h=ch;
  1155. if(moreChild.innerText!="" && !isNaN(ch) && !isNaN(cw)){
  1156. a+=ch*cw;
  1157. }
  1158. moreChild=moreChild.nextElementSibling;
  1159. }
  1160. let isMax=false;
  1161. if(isHori){
  1162. if(maxWidth<w){
  1163. isMax=true;
  1164. }else if(maxWidth<w+300 && curMaxArea<a){
  1165. isMax=true;
  1166. }
  1167. }else{
  1168. isMax=curMaxArea<a;
  1169. }
  1170. if(curMaxEle==null || isMax){
  1171. if(h>0 || !isHori)curHeight=h;
  1172. curMaxArea=a;
  1173. maxWidth=w;
  1174. curMaxEle=curNode;
  1175. }
  1176. }
  1177. if(curMaxEle && !hasSameClass && (isHori || curHeight>maxHeight || (needCheckNext && curHeight>windowHeight && ele.contains(self.initNext)))){
  1178. return checkElement(curMaxEle);
  1179. }
  1180. if(ele.tagName=="P" || ele.tagName=="BR")ele=ele.parentNode;
  1181. if(ele.tagName=="TD")ele=ele.parentNode;
  1182. if(ele.tagName=="TBODY"){
  1183. self.curSiteRule.pageElement=geneSelector(ele)+">*";
  1184. if(ele.children.length>0 && ele.children[0].querySelector("th")){
  1185. self.curSiteRule.pageElement+=":not(:first-child)";
  1186. }
  1187. debug(self.curSiteRule.pageElement);
  1188. return ele.children;
  1189. }
  1190. self.curSiteRule.pageElement=geneSelector(ele);
  1191. if(ele.children.length>1){
  1192. let hasText=false;
  1193. for(let i in ele.childNodes){
  1194. let child=ele.childNodes[i];
  1195. if(child.nodeType==3 && child.nodeValue.trim()!=''){
  1196. hasText=true;
  1197. ele=[ele];
  1198. break;
  1199. }
  1200. }
  1201. if(!hasText){
  1202. let middleChild=ele.children[parseInt(ele.children.length/2)];
  1203. if((middleChild.style && middleChild.style.position=="absolute" && middleChild.style.left && middleChild.style.top) || ele.tagName=="UL" || curHeight==0){
  1204. ele=[ele];
  1205. }else{
  1206. self.curSiteRule.pageElement+=">*";
  1207. ele=ele.children;
  1208. }
  1209. }
  1210. }else{
  1211. ele=[ele];
  1212. }
  1213. debug(self.curSiteRule.pageElement);
  1214. return ele;
  1215. }
  1216. pageElement=checkElement(body);
  1217. //if(pageElement)this.saveCurSiteRule();
  1218. }
  1219. if(doc==document && !this.docPageElement){
  1220. this.docPageElement=pageElement;
  1221. }
  1222. if(pageElement && pageElement.length>0){
  1223. let pageElementCss=self.curSiteRule.pageElementCss || self.curSiteRule.pageElementStyle || rulesData.pageElementCss;
  1224. if(pageElementCss){
  1225. [].forEach.call(pageElement, ele=>{
  1226. if(!ele.dataset.pagetualPageElement){
  1227. ele.style.cssText=(ele.style.cssText||'')+pageElementCss;
  1228. ele.dataset.pagetualPageElement=1;
  1229. }
  1230. });
  1231. }
  1232. }
  1233. return pageElement;
  1234. }
  1235.  
  1236. getPage(doc){
  1237. if(typeof _unsafeWindow.Discourse!='undefined')return {};
  1238. let video=document.querySelector("video,iframe[src*=player]");
  1239. if(video){
  1240. if(video.scrollWidth>500 && video.scrollHeight>500){
  1241. debug("Won't run when video found");
  1242. return {};
  1243. }
  1244. }
  1245. let canSave=false;//發現頁碼選擇器在其他頁對不上,還是別保存了
  1246. let url=this.curUrl.replace("#!","").replace("index.php?","?");
  1247. let _url=url.replace(/\.s?html?$/i,"");
  1248. let pageNum=1,preStr="",afterStr="";
  1249. let pageMatch1=url.match(/(.*[a-z\/\-_](?:p|page)?\/?)(\d+)(\.s?html?$|\/?$)/i);
  1250. let pageMatch2=url.match(/(.*[\?&]p(?:age)?=)(\d+)($|[#&].*)/i);
  1251. if(pageMatch1){
  1252. preStr=pageMatch1[1];
  1253. pageNum=parseInt(pageMatch1[2]);
  1254. afterStr=pageMatch1[3];
  1255. }else if(pageMatch2){
  1256. preStr=pageMatch2[1];
  1257. pageNum=parseInt(pageMatch2[2]);
  1258. afterStr=pageMatch2[3];
  1259. }
  1260. let curPage=doc,i,cur,jsNext;
  1261. let next1,next2,next3,next4,nextJs1,nextJs2,nextJs3;
  1262. let next=curPage.querySelector(".page-next>a")||
  1263. curPage.querySelector("a.next_page")||
  1264. curPage.querySelector("#next_page")||
  1265. curPage.querySelector(".nextPage")||
  1266. curPage.querySelector("a[data-pagination=next]")||
  1267. curPage.querySelector("ul.pagination>li.active+li>a")||
  1268. curPage.querySelector(".pagination a[rel=next]")||
  1269. curPage.querySelector(".pagination-nav__item--next>a")||
  1270. curPage.querySelector("a[title='Next page']")||
  1271. curPage.querySelector("a.pageright")||
  1272. curPage.querySelector(".page-numbers.current+a")||
  1273. curPage.querySelector("a#rightFix")||
  1274. curPage.querySelector("a#next")||
  1275. curPage.querySelector(".next>a")||
  1276. curPage.querySelector(".next>button")||
  1277. curPage.querySelector("a[alt=next]")||
  1278. curPage.querySelector("button.next")||
  1279. curPage.querySelector("[title=next]")||
  1280. curPage.querySelector("[title='Next page']")||
  1281. curPage.querySelector("a#btnPreGn")||
  1282. curPage.querySelector("a.page-next")||
  1283. getElementByXpath("//a[contains(@class, 'page__next')]",curPage,curPage);
  1284. if(!next){
  1285. let nexts=curPage.querySelectorAll("a.next");
  1286. for(i=0;i<nexts.length;i++){
  1287. if(!/^([上前首尾][一1]?[页頁张張]|previous(\s*page)?\s*›?$|前のページ)/i.test(nexts[i].innerText.trim()) &&
  1288. nexts[i].style.display!=="none" &&
  1289. nexts[i].parentNode.style.display!=="none"){
  1290. next=nexts[i];
  1291. break;
  1292. }
  1293. }
  1294. }
  1295. if(next && (!next.href || /^javascript:/.test(next.href) || next.getAttribute("href")=="#")){
  1296. jsNext=next;
  1297. next=null;
  1298. }
  1299. if(!next){
  1300. next=curPage.querySelectorAll("[aria-label='Next page']");
  1301. if(next && next.length==1){
  1302. next=next[0];
  1303. if(!next.href || /^javascript:/.test(next.href) || next.getAttribute("href")=="#"){
  1304. if(!jsNext)jsNext=next;
  1305. next=null;
  1306. }
  1307. }else{
  1308. next=null;
  1309. }
  1310. }
  1311. if(!next){
  1312. next=curPage.querySelectorAll("[aria-label='Next']");
  1313. if(next && next.length==1){
  1314. next=next[0];
  1315. if(!next.href || /^javascript:/.test(next.href) || next.getAttribute("href")=="#"){
  1316. if(!jsNext)jsNext=next;
  1317. next=null;
  1318. }
  1319. }else{
  1320. next=null;
  1321. }
  1322. }
  1323. if(next && /^[下后後][一1]?[章话話篇]/i.test(next.innerText.trim())){
  1324. next2=next;
  1325. next=null;
  1326. }
  1327. if(!next){
  1328. next=curPage.querySelector("a.curr+a");
  1329. }
  1330. if(!next){
  1331. next=curPage.querySelector("div.wp-pagenavi>span.current+a,div.page-nav>span.current+a,div.article-paging>span+a");
  1332. }
  1333. if(!next){
  1334. let pageDiv=curPage.querySelector("div.pages>ul");
  1335. if(pageDiv){
  1336. cur=pageDiv.querySelector("li>b");
  1337. if(cur)next=cur.parentNode.nextElementSibling;
  1338. if(next)next=next.querySelector("a");
  1339. }
  1340. }
  1341. if(!next){
  1342. next=curPage.querySelector(".number>ul>li.active+li>a");
  1343. }
  1344. if(!next){
  1345. let aTags=curPage.querySelectorAll("a,button");
  1346. for(i=aTags.length-1;i>=0;i--){
  1347. if(next1 && next2 && next3 && next4)break;
  1348. let aTag=aTags[i];
  1349. if(aTag.innerText=="§")continue;
  1350. if(aTag.innerText.length>50)continue;
  1351. if(aTag.style.display=="none")continue;
  1352. if(aTag.href && /next$/i.test(aTag.href))continue;
  1353. if(aTag.className && /slick|slide/i.test(aTag.className))continue;
  1354. if(aTag.classList && aTag.classList.contains('disabled'))continue;
  1355. if(aTag.parentNode && aTag.parentNode.classList && aTag.parentNode.classList.contains('disabled'))continue;
  1356. if(aTag.innerText.length<=18){
  1357. if(!next1){
  1358. if(/^[下后後][一1]?[页頁张張]|^next([ _-]?page)\s*[›>→»]?$|次のページ|^次へ?$/i.test(aTag.innerText.trim())){
  1359. if(!aTag.href || /^javascript:/.test(aTag.href) || aTag.getAttribute("href")=="#"){
  1360. if(!nextJs1)nextJs1=aTag;
  1361. }else{
  1362. next1=aTag;
  1363. }
  1364. }
  1365. }
  1366. if(!next2){
  1367. if(/^[下后後][一1]?[章话話篇]/i.test(aTag.innerText.trim()) || /nextpage/i.test(aTag.className) || aTag.innerText=="»"){
  1368. if(!aTag.href || /^javascript:/.test(aTag.href) || aTag.getAttribute("href")=="#"){
  1369. if(!nextJs2)nextJs2=aTag;
  1370. }else{
  1371. next2=aTag;
  1372. }
  1373. }
  1374. }
  1375. if(!next3){
  1376. if(aTag.innerText=="Next" || aTag.innerText=="next" || aTag.innerText=="&gt;" || aTag.innerText=="▶" || aTag.innerText==">" || aTag.innerText=="›" || aTag.innerText=="→"){
  1377. if(!aTag.href || /^javascript:/.test(aTag.href) || aTag.getAttribute("href")=="#"){
  1378. if(!nextJs3)nextJs3=aTag;
  1379. }else{
  1380. next3=aTag;
  1381. }
  1382. }
  1383. }
  1384. }
  1385. if(!aTag.href || /^javascript:/.test(aTag.href) || aTag.getAttribute("href")=="#")continue;
  1386. if(!next4 && aTag.href.length<250){
  1387. let _aHref=aTag.href.replace("?&","?").replace("#!","").replace("index.php?","?");
  1388. let _aHrefTrim=_aHref;
  1389. if(preStr)_aHrefTrim=_aHrefTrim.replace(preStr,"");
  1390. if(afterStr)_aHrefTrim=_aHrefTrim.replace(afterStr,"");
  1391. if(pageNum<999 && _aHrefTrim==pageNum+1){
  1392. next4=aTag;
  1393. }else if(this.curUrl!=aTag.href){
  1394. _aHref=_aHref.replace(/\.s?html?$/i,"");
  1395. if(_aHref.indexOf(_url)!=-1 && /^[\/\?&]?[_-]?(p|page)?=?\/?2(\/|\?|&|$)/i.test(_aHref.replace(_url,""))){
  1396. let curHref=aTag.getAttribute("href");
  1397. let pageOne=curHref.replace(/\/2(\/|\?|&|$)/,"/1$1");
  1398. if(pageOne==curHref)pageOne=null;
  1399. else pageOne=curPage.querySelector(`a[href='${pageOne}']`);
  1400. if(!pageOne || pageOne.className!=curHref.className)next4=aTag;
  1401. }
  1402. }
  1403. }
  1404. }
  1405. if(next3){
  1406. let eles=getAllElements(`//a[text()='${next3.innerText}']`, curPage);
  1407. if(eles.length>2)next3=null;
  1408. }
  1409. if(nextJs3){
  1410. let eles=getAllElements(`//a[text()='${nextJs3.innerText}']`, curPage);
  1411. if(eles.length>2)nextJs3=null;
  1412. }
  1413. }
  1414. if(!next)next=next1||next4||next3||next2||jsNext||nextJs1||nextJs3||nextJs2;
  1415. if(next && next.classList && next.classList.contains("results-more"))next=null;
  1416. return {next:next,canSave:canSave};
  1417. }
  1418.  
  1419. canonicalUri(src) {
  1420. if (!src) {
  1421. return "";
  1422. }
  1423. let origin = location.protocol + '//' + location.host;
  1424. let url = this.basePath || origin;
  1425. if(url.indexOf("http") !== 0) url = origin + url;
  1426. if(src.charAt(0)=="#")return this.curUrl+src;
  1427. if(src.charAt(0)=="?")return this.curUrl.replace(/^([^?#]+).*/, "$1" + src);
  1428. var root_page = /^[^?#]*\//.exec(url)[0],
  1429. root_domain = /^\w+\:\/\/\/?[^\/]+/.exec(root_page)[0],
  1430. absolute_regex = /^\w+\:\/\//;
  1431. this.updateUrl=false;
  1432. while(src.indexOf("../")===0){
  1433. src=src.substr(3);
  1434. root_page=root_page.replace(/\/[^\/]+\/$/, "/");
  1435. this.updateUrl=true;
  1436. }
  1437. src=src.replace(/\.\//,"");
  1438. if (/^\/\/\/?/.test(src)){
  1439. src = location.protocol + src;
  1440. }
  1441. return (absolute_regex.test(src) ? src : ((src.charAt(0) == "/" ? root_domain : root_page) + src));
  1442. }
  1443.  
  1444. getLinkByPage(url, pageNum) {
  1445. if(!url)return;
  1446. if(this.curSiteRule.pageNum){
  1447. let result=this.curSiteRule.pageNum;
  1448. let strMatch=result.match(/\{.*?}/);
  1449. if(!strMatch)return null;
  1450. let urlReg=new RegExp("("+result.replace(strMatch[0], ")\\d+(")+")","i");
  1451. let code=strMatch[0].replace(/^{/,"").replace(/}$/,"").replace(/\$p/g,pageNum);
  1452. if(code==pageNum){
  1453. result=url.replace(urlReg,"$1"+code+"$2");
  1454. }else{
  1455. try{
  1456. code=Function('"use strict";return ' + code)();
  1457. result=url.replace(urlReg,"$1"+code+"$2");
  1458. }catch(e){
  1459. debug(e);
  1460. }
  1461. }
  1462. if(result!=url){
  1463. return result;
  1464. }
  1465. }
  1466. return url.replace(/([&\/\?](p=|page[=\/_-]?))\d+/i, "$1"+pageNum).replace(/([_-])\d+\./i, "$1"+pageNum+".");
  1467. }
  1468.  
  1469. getPageNumFromUrl(url) {
  1470. if(!url)return curPage;
  1471. if(this.curSiteRule.pageNum){
  1472. let result=this.curSiteRule.pageNum;
  1473. let strMatch=result.match(/\{.*?}/);
  1474. if(!strMatch)return null;
  1475. let urlReg=new RegExp(".*"+result.replace(strMatch[0], "(\\d+)")+".*","i");
  1476. let curShowNum=url.replace(urlReg,"$1");
  1477. if (curShowNum!=url){
  1478. let code=strMatch[0].replace(/^{/,"").replace(/}$/,"");
  1479. if(code=="$p"){
  1480. return curShowNum;
  1481. }else{
  1482. try{
  1483. let page1=Function('"use strict";return ' + code.replace("$p", "0"))();
  1484. let page2=Function('"use strict";return ' + code.replace("$p", "1"))();
  1485. let numGap=page2-page1;
  1486. return (curShowNum - page1) / numGap;
  1487. }catch(e){
  1488. debug(e);
  1489. }
  1490. }
  1491. } else {
  1492. return 1;
  1493. }
  1494. }
  1495. let pageNum=url.replace(/.*[&\/\?](p=|page[=\/_-]?)(\d+).*/i, "$2");
  1496. return pageNum==url?curPage:pageNum;
  1497. }
  1498.  
  1499. getNextLink(doc) {
  1500. let nextLink=null,page,href;
  1501. let getNextLinkByForm=(form,n)=>{
  1502. let params=[];
  1503. [].forEach.call(form.querySelectorAll("input"), input=>{
  1504. if(n && /^(p|page)$/i.test(input.name)){
  1505. params.push('p='+n);
  1506. }else{
  1507. params.push(input.name+'='+input.value);
  1508. }
  1509. });
  1510. return form.action+'?'+params.join('&');
  1511. };
  1512. if(this.curSiteRule.pageElementByJs){
  1513. this.nextLinkHref="#";
  1514. return true;
  1515. }else if(this.curSiteRule.nextLinkByJs){
  1516. try{
  1517. let targetUrl=((typeof _unsafeWindow.pagetualNextLinkByJs=='undefined') ? Function("doc",'"use strict";' + this.curSiteRule.nextLinkByJs) : _unsafeWindow.pagetualNextLinkByJs)(doc);
  1518. if(targetUrl)nextLink={href:targetUrl};
  1519. }catch(e){
  1520. debug(e);
  1521. }
  1522. }else if(this.curSiteRule.nextLinkByUrl){
  1523. let targetUrl=this.curUrl.replace(new RegExp(this.curSiteRule.nextLinkByUrl[0],"i"), this.curSiteRule.nextLinkByUrl[1]);
  1524. if(targetUrl != this.curUrl){
  1525. let reps=targetUrl.match(/{.*?}/g);
  1526. if(reps){
  1527. reps.forEach(rep=>{
  1528. let code=rep.replace("{","").replace("}","").replace(/\(\)/g, "0");
  1529. let result=code.match(/^(\d*)\+1$/);
  1530. if(result){
  1531. result=parseInt(result[1]||1)+1;
  1532. }else{
  1533. try{
  1534. result=Function('"use strict";return ' + code)();
  1535. }catch(e){
  1536. debug(e);
  1537. }
  1538. }
  1539. targetUrl=targetUrl.replace(rep, result);
  1540. });
  1541. }
  1542. }
  1543. nextLink={href:targetUrl};
  1544. } else if (this.curSiteRule.nextLink) {
  1545. let nextLinkSel = this.curSiteRule.nextLink;
  1546. if (nextLinkSel != "0" && nextLinkSel != 0) {
  1547. if (Array && Array.isArray && Array.isArray(nextLinkSel)) {
  1548. nextLink = getElement(nextLinkSel[nextIndex], doc);
  1549. } else nextLink = getElement(nextLinkSel, doc);
  1550. }
  1551. }else{
  1552. page=this.getPage(doc);
  1553. nextLink=page.next;
  1554. if(nextLink){
  1555. if(nextLink.tagName=="INPUT" && nextLink.parentNode.tagName=="FORM"){
  1556. let form=nextLink.parentNode;
  1557. nextLink.href=getNextLinkByForm(form);
  1558. }
  1559. if((nextLink.className && /slick|slide/i.test(nextLink.className)) || (nextLink.parentNode && nextLink.parentNode.className && /slick|slide/i.test(nextLink.parentNode.className))){
  1560. this.nextLinkHref=false;
  1561. return null;
  1562. }else if(nextLink.parentNode.style.display=="none" || nextLink.style.display=="none" || nextLink.classList.contains("noClick") || nextLink.hasAttribute("disabled")){
  1563. this.nextLinkHref=false;
  1564. return null;
  1565. }else if(doc==document){
  1566. if((!nextLink.href || /^javascript:|#$/.test(nextLink.href)) && !isVisible(nextLink, _unsafeWindow)){
  1567. this.nextLinkHref=false;
  1568. return null;
  1569. }else{
  1570. let nextLinkCs=_unsafeWindow.getComputedStyle(nextLink);
  1571. if(nextLinkCs.cursor=="not-allowed"){
  1572. this.nextLinkHref=false;
  1573. return null;
  1574. }
  1575. this.initNext=nextLink;
  1576. }
  1577. }
  1578. let form=doc.querySelector('#search-form');
  1579. if(!nextLink.href && nextLink.hasAttribute("onclick") && form){
  1580. if(form && /^\d+$/.test(nextLink.innerText)){
  1581. href=getNextLinkByForm(form, nextLink.innerText);
  1582. }
  1583. }
  1584. }
  1585. }
  1586. if(nextLink){
  1587. let needUrl=(this.curSiteRule.action==0 || this.curSiteRule.action==1);
  1588. if(!href)href=nextLink.href;
  1589. if(href && nextLink.getAttribute){
  1590. let _href=nextLink.getAttribute("href");
  1591. if(!_href || _href.charAt(0)=="#" || _href=="?"){
  1592. href="#";
  1593. }else{
  1594. href=_href;
  1595. }
  1596. }
  1597.  
  1598. if((href===""||href===null) && needUrl){
  1599. this.nextLinkHref=false;
  1600. }else if(/^(javascript:void\(0\)|#)/.test(href) && needUrl){
  1601. this.nextLinkHref=false;
  1602. }else{
  1603. this.nextLinkHref=(href && !/^(javascript:|#)/.test(href))?this.canonicalUri(href):"#";
  1604. if(this.nextLinkHref!="#" && (this.nextLinkHref==this.curUrl || this.nextLinkHref==this.curUrl+"#" || this.nextLinkHref==this.oldUrl || this.nextLinkHref==this.oldUrl+"#")){
  1605. this.nextLinkHref=false;
  1606. }else if(doc==document)debug(nextLink);
  1607. }
  1608. }else{
  1609. this.nextLinkHref=false;
  1610. }
  1611. this.preload();
  1612. return nextLink;
  1613. }
  1614.  
  1615. preload(){
  1616. if(!rulesData.preload)return;
  1617. if(!this.nextLinkHref || this.nextLinkHref=="#")return;
  1618. let self=this;
  1619. if(this.curSiteRule && this.curSiteRule.action==1){
  1620. if(!this.preloadIframe){
  1621. this.preloadIframe = document.createElement('iframe');
  1622. let iframe = this.preloadIframe;
  1623. iframe.name = 'pagetual-iframe';
  1624. iframe.width = '100%';
  1625. iframe.height = '0';
  1626. iframe.frameBorder = '0';
  1627. if(ruleParser.curSiteRule.sandbox!=false){
  1628. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1629. }
  1630. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1631. iframe.addEventListener('load', function (e) {
  1632. try{
  1633. let doc=iframe.contentDocument || iframe.contentWindow.document;
  1634. var body = doc.body;
  1635. if (body && body.firstChild) {
  1636. self.lazyImgAction(body.children);
  1637. }
  1638. }catch(e){
  1639. return;
  1640. }
  1641. }, false);
  1642. document.body.appendChild(iframe);
  1643. }
  1644. this.preloadIframe.src = this.nextLinkHref;
  1645. }else{
  1646. _GM_xmlhttpRequest({
  1647. url: this.nextLinkHref,
  1648. method: 'GET',
  1649. overrideMimeType: 'text/html;charset='+document.charset,
  1650. headers: {
  1651. 'Referer': location.href
  1652. },
  1653. timeout: 5000,
  1654. onload: function(res) {
  1655. var doc=null;
  1656. try {
  1657. doc=document.implementation.createHTMLDocument('');
  1658. doc.documentElement.innerHTML=res.response;
  1659. var body = doc.body;
  1660. if (body && body.firstChild) {
  1661. self.lazyImgAction(body.children);
  1662. }
  1663. if(!self.preloadDiv){
  1664. self.preloadDiv = document.createElement('div');
  1665. self.preloadDiv.id = "pagetual-preload";
  1666. self.preloadDiv.style.cssText = 'display:none!important;';
  1667. document.body.appendChild(self.preloadDiv);
  1668. self.checkedImgs={};
  1669. }
  1670. [].forEach.call(doc.images, i=>{
  1671. let iSrc=i.src;
  1672. if(iSrc && !self.checkedImgs[iSrc]){
  1673. self.checkedImgs[iSrc] = true;
  1674. let img = document.createElement('img');
  1675. img.src = iSrc;
  1676. self.preloadDiv.appendChild(img);
  1677. }
  1678. });
  1679. }
  1680. catch (e) {
  1681. return;
  1682. }
  1683. }
  1684. });
  1685. }
  1686. }
  1687.  
  1688. getInsert(refresh) {
  1689. if(refresh){
  1690. this.insert=null;
  1691. }
  1692. if(this.insert && !refresh){
  1693. let parent=this.insert;
  1694. if (isVisible(parent.parentNode, _unsafeWindow)) {
  1695. while(parent && parent.nodeName!="BODY"){
  1696. parent=parent.parentNode;
  1697. }
  1698. if(parent && parent.nodeName=="BODY"){
  1699. return this.insert;
  1700. }
  1701. }
  1702. }
  1703. if(this.curSiteRule.insert){
  1704. let insertSel=this.curSiteRule.insert;
  1705. if(Array && Array.isArray && Array.isArray(insertSel)){
  1706. insertSel=insertSel[nextIndex<insertSel.length?nextIndex:0];
  1707. }
  1708. this.insert=getElement(insertSel, document);
  1709. }else{
  1710. let pageElement=this.getPageElement(document, _unsafeWindow);
  1711. if(pageElement && pageElement.length>0){
  1712. var pELast = pageElement[pageElement.length - 1];
  1713. this.insert = pELast.nextSibling ? pELast.nextSibling : pELast.parentNode.appendChild(document.createTextNode(' '));
  1714. }
  1715. }
  1716. return this.insert;
  1717. }
  1718.  
  1719. pageInit(doc,eles){
  1720. let code=this.curSiteRule.pageInit;
  1721. if(code){
  1722. let initFunc=((typeof _unsafeWindow.pagetualPageInit=='undefined') ? Function("doc", "eles", '"use strict";' + code) : _unsafeWindow.pagetualPageInit);
  1723. let checkInit=(resolve)=>{
  1724. try{
  1725. if(initFunc(doc, eles)===false){
  1726. setTimeout(()=>{
  1727. checkInit(resolve);
  1728. },100);
  1729. } else {
  1730. resolve(true);
  1731. }
  1732. }catch(e){
  1733. resolve(false);
  1734. debug(e);
  1735. }
  1736. };
  1737. return new Promise((resolve) => {
  1738. checkInit(function(e) {
  1739. resolve(e)
  1740. });
  1741. })
  1742. }
  1743. }
  1744.  
  1745. pageAction(doc,eles){
  1746. let code=this.curSiteRule.pageAction;
  1747. if(code){
  1748. try{
  1749. ((typeof _unsafeWindow.pagetualPageAction=='undefined') ? Function("doc", "eles", '"use strict";' + code) : _unsafeWindow.pagetualPageAction)(doc, eles);
  1750. }catch(e){
  1751. debug(e);
  1752. }
  1753. }
  1754. this.lazyImgAction(eles);
  1755. this.openInNewTab(eles);
  1756. }
  1757.  
  1758. openInNewTab(eles){
  1759. if(rulesData.openInNewTab){
  1760. [].forEach.call(eles, ele=>{
  1761. if(ele.tagName=="A" && ele.href && !/^(mailto:|javascript:|#)/.test(ele.href)){
  1762. ele.setAttribute('target', '_blank');
  1763. }else{
  1764. [].forEach.call(ele.querySelectorAll('a[href]:not([href^="mailto:"]):not([href^="javascript:"]):not([href^="#"])'), a=>{
  1765. a.setAttribute('target', '_blank');
  1766. if (a.getAttribute('onclick') == 'atarget(this)') {
  1767. a.removeAttribute('onclick');
  1768. }
  1769. });
  1770. }
  1771. });
  1772. }
  1773. }
  1774.  
  1775. lazyImgAction(eles){
  1776. let lazyImgSrc=this.curSiteRule.lazyImgSrc;
  1777. let setLazyImg = img => {
  1778. let realSrc;
  1779. if (lazyImgSrc) {
  1780. realSrc = img.getAttribute(lazyImgSrc);
  1781. }
  1782. if (!realSrc) {
  1783. if (img.getAttribute("_src") && !img.src) {
  1784. realSrc = img.getAttribute("_src");
  1785. } else if (img.dataset && img.dataset.original) {
  1786. realSrc = img.dataset.original;
  1787. } else if (img.dataset && img.dataset.lazy) {
  1788. realSrc = img.dataset.lazy;
  1789. } else if (img.dataset && img.dataset.src) {
  1790. realSrc = img.dataset.src;
  1791. } else if (img._lazyrias && img._lazyrias.srcset) {
  1792. realSrc = img._lazyrias.srcset[img._lazyrias.srcset.length - 1];
  1793. } else if (img.dataset && img.dataset.origFile) {
  1794. realSrc = img.dataset.origFile;
  1795. } else if (img.srcset) {
  1796. var srcs = img.srcset.split(/[xw],/), largeSize = 0;
  1797. srcs.forEach(srci => {
  1798. let srcInfo = srci.trim().split(" "), curSize = parseInt(srcInfo[1]);
  1799. if (srcInfo[1] && curSize > largeSize) {
  1800. largeSize = curSize;
  1801. realSrc = srcInfo[0];
  1802. }
  1803. });
  1804. }
  1805. }
  1806. if (realSrc) {
  1807. img.src = realSrc;
  1808. if (img.style.display == "none") {
  1809. img.style.display = "";
  1810. }
  1811. if (img.style.visibility == "hidden") {
  1812. img.style.visibility = "";
  1813. }
  1814. if (img.style.opacity == 0) {
  1815. img.style.opacity = "";
  1816. }
  1817. }
  1818. };
  1819. [].forEach.call(eles, ele=>{
  1820. if(ele.tagName=="IMG"){
  1821. setLazyImg(ele);
  1822. }else{
  1823. [].forEach.call(ele.querySelectorAll("img"), img=>{
  1824. setLazyImg(img);
  1825. });
  1826. [].forEach.call(ele.querySelectorAll("div[data-src][data-thumb]"), div=>{
  1827. div.style.setProperty("background-image", "url("+div.dataset.src+")", "important");
  1828. });
  1829. }
  1830. if(ele.tagName=="A" && ele.classList.contains("lazyload")){
  1831. if(ele.dataset.original){
  1832. ele.style.backgroundImage='url("'+ele.dataset.original+'")';
  1833. }
  1834. }else{
  1835. [].forEach.call(ele.querySelectorAll("a.lazyload"), a=>{
  1836. if(a.dataset.original){
  1837. a.style.backgroundImage='url("'+a.dataset.original+'")';
  1838. }
  1839. });
  1840. }
  1841. });
  1842. }
  1843.  
  1844. initPage(callback){
  1845. let self=this;
  1846. curPage=1;
  1847. //if(this.curSiteRule.url && !this.curSiteRule.singleUrl)return;
  1848. this.curSiteRule={};
  1849. this.pageDoc=document;
  1850. this.nextLinkHref=null;
  1851. this.curUrl=location.href;
  1852. let base=document.querySelector("base");
  1853. this.basePath=base?base.href:location.href;
  1854. this.getRule(()=>{
  1855. if(self.curSiteRule.enable==0){
  1856. debug("Stop as rule disable");
  1857. isPause=true;
  1858. return;
  1859. }
  1860. //若是再亂匹配就不緩存wedata,或者只在找完本地規則之後再考慮wedata的緩存
  1861. if(self.curSiteRule && !self.curSiteRule.singleUrl && self.curSiteRule.url.length>13){
  1862. self.hpRules=self.hpRules.filter(item=>{return item&&item.url!=self.curSiteRule.url});
  1863. self.hpRules.unshift(self.curSiteRule);
  1864. if(self.hpRules.length>30){
  1865. self.hpRules.pop();
  1866. }
  1867. storage.setItem("hpRules", self.hpRules);
  1868. }
  1869. let css=self.curSiteRule.css || rulesData.customCss;
  1870. if(css && !/^inIframe:/.test(css)){
  1871. _GM_addStyle(css);
  1872. }
  1873. let autoClick=self.curSiteRule.autoClick;
  1874. if(autoClick){
  1875. let autoClickBtn;
  1876. autoClickBtn=getElement(autoClick, document);
  1877. if(autoClickBtn){
  1878. emuClick(autoClickBtn);
  1879. }
  1880. }
  1881. let code=self.curSiteRule.init;
  1882. if(code){
  1883. try{
  1884. ((typeof _unsafeWindow.pagetualInit=='undefined') ? Function('doc','win','iframe','"use strict";' + code) : _unsafeWindow.pagetualInit)(null,null,null);
  1885. }catch(e){
  1886. debug(e);
  1887. }
  1888. }
  1889. self.getNextLink(document);
  1890. callback();
  1891. });
  1892. }
  1893.  
  1894. insertElement(ele) {
  1895. if(this.curSiteRule.insertPos==2){
  1896. this.insert.appendChild(ele);
  1897. }else{
  1898. this.insert.parentNode.insertBefore(ele, this.insert);
  1899. }
  1900. }
  1901.  
  1902. async insertPage(doc, eles, url, callback, tried){
  1903. this.oldUrl=this.curUrl;
  1904. let oldTitle=this.pageDoc.title;
  1905. this.pageDoc=doc;
  1906. this.curUrl=url;
  1907. let nextLink=this.getNextLink(doc);
  1908. this.nextTitle="";
  1909. if(this.curSiteRule.pageBarText){
  1910. if(this.curSiteRule.pageBarText==1 || this.curSiteRule.pageBarText==true){
  1911. this.nextTitle=doc.title;
  1912. }else{
  1913. try{
  1914. this.nextTitle=((typeof _unsafeWindow.pagetualPageBarText=='undefined') ? Function("doc",'"use strict";' + this.curSiteRule.pageBarText) : _unsafeWindow.pagetualPageBarText)(doc);
  1915. }catch(e){
  1916. debug(e);
  1917. }
  1918. }
  1919. }
  1920. if(curPage==1 && !tried && !nextLink && this.curSiteRule.singleUrl && this.curSiteRule.pageElement && this.curSiteRule.action!=0){
  1921. this.curSiteRule.action=1;
  1922. this.curUrl=location.href;
  1923. return false;
  1924. }
  1925. if(callback)callback(eles);
  1926. this.getInsert();
  1927. var self=this,newEles=[];
  1928. if(!eles || eles.length==0 || !self.insert || !self.insert.parentNode){
  1929. }else{
  1930. isLoading=true;
  1931. await this.pageInit(doc, eles);
  1932. [].forEach.call(eles, ele=>{
  1933. let newEle=ele.cloneNode(true);
  1934. let oldCanvass=ele.querySelectorAll("canvas");
  1935. let newCanvass=newEle.querySelectorAll("canvas");
  1936. if(self.updateUrl){
  1937. [].forEach.call(newEle.querySelectorAll("img"), img=>{
  1938. if (img.getAttribute("src")) img.src=self.canonicalUri(img.getAttribute("src"));
  1939. });
  1940. [].forEach.call(newEle.querySelectorAll("a"), a=>{
  1941. if (a.getAttribute("href")) a.href = self.canonicalUri(a.getAttribute("href"));
  1942. });
  1943. }
  1944. for(let i=0;i<oldCanvass.length;i++){
  1945. let oldCanvas=oldCanvass[i];
  1946. let newCanvas=newCanvass[i];
  1947. newCanvas.getContext('2d').drawImage(oldCanvas, 0, 0);
  1948. }
  1949. self.insertElement(newEle);
  1950. newEles.push(newEle);
  1951. });
  1952. }
  1953. this.pageAction(doc, newEles);
  1954. if(this.oldUrl!=location.href){
  1955. let isJs=/^(javascript|#)/.test(this.oldUrl.replace(location.href,""));
  1956. let enableHistory = this.curSiteRule.history;
  1957. if (enableHistory == 1) {
  1958. enableHistory = true;
  1959. } else if (enableHistory == 0) {
  1960. enableHistory = false;
  1961. } else {
  1962. enableHistory = rulesData.enableHistory;
  1963. }
  1964. if(enableHistory && !isJs){
  1965. _unsafeWindow.history.replaceState(undefined, oldTitle, this.oldUrl);
  1966. document.title=oldTitle;
  1967. }
  1968. }
  1969. isLoading=false;
  1970. return true;
  1971. }
  1972. }
  1973. var ruleParser = new RuleParser();
  1974.  
  1975. class NextSwitch {
  1976. static nextSwitch;
  1977. constructor() {
  1978. this.init();
  1979. }
  1980.  
  1981. static getInstance() {
  1982. if (!NextSwitch.nextSwitch) {
  1983. NextSwitch.nextSwitch = new NextSwitch();
  1984. }
  1985. return NextSwitch.nextSwitch;
  1986. }
  1987.  
  1988. init() {
  1989. let self = this;
  1990. let cssText = `
  1991. #pagetual-nextSwitch {
  1992. position: fixed;
  1993. top: 10px;
  1994. left: calc(50% - 160px);
  1995. background: aliceblue;
  1996. padding: 10px;
  1997. border-radius: 5px;
  1998. text-align: center;
  1999. opacity: 0.95;
  2000. color: #161616;
  2001. z-index: 2147483647;
  2002. font-size: 16px;
  2003. box-shadow: rgb(0 0 0) 0px 0px 10px;
  2004. }
  2005. #pagetual-nextSwitch>.title {
  2006. margin: -5px 45px 10px 45px;
  2007. font-size: 20px;
  2008. font-weight: bold;
  2009. border-bottom: 1px solid black;
  2010. user-select: none;
  2011. color: orangered;
  2012. }
  2013. #pagetual-nextSwitch>.group {
  2014. display: flex;
  2015. flex-direction: column;
  2016. }
  2017. #pagetual-nextSwitch>.group>span {
  2018. color: #161616;
  2019. cursor: pointer;
  2020. margin: 3px;
  2021. font-size: larger;
  2022. }
  2023. #pagetual-nextSwitch>.group>span:hover {
  2024. color: red;
  2025. }
  2026. #pagetual-nextSwitch>.group>span.current {
  2027. border: 2px dotted red;
  2028. border-radius: 10px;
  2029. }
  2030. #pagetual-nextSwitch>.closeSwitch {
  2031. position: absolute;
  2032. top: 3px;
  2033. right: 10px;
  2034. background: none;
  2035. border: none;
  2036. vertical-align: top;
  2037. transition: transform .15s ease-in-out;
  2038. float: right;
  2039. cursor: pointer;
  2040. }
  2041. #pagetual-nextSwitch svg {
  2042. width: 30px;
  2043. height: 30px;
  2044. vertical-align: middle;
  2045. fill: #161616;
  2046. overflow: hidden;
  2047. }
  2048. #pagetual-nextSwitch button:hover {
  2049. transform: scale(1.2);
  2050. }
  2051. `;
  2052. _GM_addStyle(cssText);
  2053. let frame = document.createElement("div");
  2054. frame.id = "pagetual-nextSwitch";
  2055. frame.innerHTML = createHTML(`
  2056. <div class="title">${i18n("nextSwitch")}</div>
  2057. <button type="button" class="closeSwitch">
  2058. <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2754">
  2059. <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">
  2060. </path>
  2061. </svg>
  2062. </button>
  2063. <div class="group"></div>
  2064. `);
  2065. let group = frame.querySelector(".group");
  2066. let closeBtn = frame.querySelector(".closeSwitch");
  2067. closeBtn.addEventListener("click", e => {
  2068. self.close();
  2069. }, true);
  2070. this.frame = frame;
  2071. let currentSpan;
  2072. ruleParser.curSiteRule.nextLink.forEach((link, i) => {
  2073. let span = document.createElement("span");
  2074. let target = getElement(link, document);
  2075. let index = "<b>" + (i + 1) + "</b>: ";
  2076. if (target) {
  2077. let targetInner = target.innerText.trim();
  2078. span.innerHTML = index + (targetInner || link);
  2079. } else {
  2080. span.innerHTML = index + "Not Found";
  2081. }
  2082. span.title = link;
  2083. span.addEventListener("click", e => {
  2084. if (currentSpan) currentSpan.classList.remove("current");
  2085. span.classList.add("current");
  2086. currentSpan = span;
  2087. nextIndex = i;
  2088. storage.setItem("nextSwitch_" + location.host, nextIndex === 0 ? "" : nextIndex);
  2089. ruleParser.curUrl += "#pagetual";
  2090. ruleParser.oldUrl = ruleParser.curUrl;
  2091. autoLoadNum = -1;
  2092. if (!ruleParser.nextLinkHref) {
  2093. isLoading = false;
  2094. }
  2095. ruleParser.getNextLink(ruleParser.pageDoc || document);
  2096. self.close();
  2097. }, true);
  2098. if (i == nextIndex) {
  2099. span.classList.add("current");
  2100. currentSpan = span;
  2101. }
  2102. group.appendChild(span);
  2103. });
  2104. }
  2105.  
  2106. start() {
  2107. document.documentElement.appendChild(this.frame);
  2108. }
  2109.  
  2110. close() {
  2111. if (this.frame.parentNode) this.frame.parentNode.removeChild(this.frame);
  2112. }
  2113. }
  2114.  
  2115. class Picker {
  2116. static picker;
  2117. constructor() {
  2118. this.init();
  2119. }
  2120.  
  2121. static getInstance() {
  2122. if (!Picker.picker) {
  2123. Picker.picker = new Picker();
  2124. }
  2125. return Picker.picker;
  2126. }
  2127.  
  2128. init() {
  2129. let self = this;
  2130. this.signList = [];
  2131. let cssText = `
  2132. body.pagetual-picker,
  2133. body.pagetual-picker *:hover,
  2134. body.pagetual-picker a:hover {
  2135. cursor: crosshair !important;
  2136. }
  2137. #pagetual-picker {
  2138. position: fixed;
  2139. top: 0;
  2140. left: calc(50% - 160px);
  2141. background: aliceblue;
  2142. padding: 10px;
  2143. border-radius: 5px;
  2144. text-align: center;
  2145. opacity: 0.95;
  2146. color: #161616;
  2147. z-index: 2147483647;
  2148. font-size: 16px;
  2149. box-shadow: rgb(0 0 0) 0px 0px 10px;
  2150. }
  2151. #pagetual-picker>.title {
  2152. margin: -5px 45px 10px 45px;
  2153. font-size: 20px;
  2154. font-weight: bold;
  2155. cursor: move;
  2156. border-bottom: 1px solid black;
  2157. user-select: none;
  2158. color: orangered;
  2159. }
  2160. #pagetual-picker button {
  2161. background: none;
  2162. border: none;
  2163. vertical-align: top;
  2164. transition: transform .15s ease-in-out;
  2165. float: right;
  2166. cursor: pointer;
  2167. }
  2168. #pagetual-picker button:hover {
  2169. transform: scale(1.2);
  2170. }
  2171. #pagetual-picker>.closePicker {
  2172. position: absolute;
  2173. top: 3px;
  2174. right: 10px;
  2175. }
  2176. #pagetual-picker>.selector{
  2177. display: inline-block;
  2178. width: 290px;
  2179. height: 20px;
  2180. max-width: 65vw;
  2181. padding: 6px 12px;
  2182. font-size: 16px;
  2183. font-weight: 400;
  2184. line-height: 1.5;
  2185. color: #495057;
  2186. background-color: #fff;
  2187. background-clip: padding-box;
  2188. border: 1px solid #ced4da;
  2189. border-radius: 4px;
  2190. transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;
  2191. box-sizing: content-box;
  2192. }
  2193. #pagetual-picker>.selector:focus {
  2194. color: #495057;
  2195. background-color: #fff;
  2196. border-color: #80bdff;
  2197. outline: 0;
  2198. box-shadow: 0 0 0 3.2px rgb(0 123 255 / 25%);
  2199. }
  2200. #pagetual-picker .xpath {
  2201. line-height: 20px;
  2202. height: 25px;
  2203. width: 25px;
  2204. margin-left: 5px;
  2205. vertical-align: middle;
  2206. appearance: auto;
  2207. display: inline-block;
  2208. }
  2209. #pagetual-picker label {
  2210. font-size: 18px;
  2211. line-height: 25px;
  2212. vertical-align: middle;
  2213. display: inline-block;
  2214. }
  2215. #pagetual-picker .bottom {
  2216. text-align: left;
  2217. margin-top: 10px;
  2218. }
  2219. #pagetual-picker .bottom>button {
  2220. float: right;
  2221. }
  2222. #pagetual-picker svg {
  2223. width: 30px;
  2224. height: 30px;
  2225. vertical-align: middle;
  2226. fill: #161616;
  2227. overflow: hidden;
  2228. }
  2229. #pagetual-picker .allpath {
  2230. font-size: 18px;
  2231. margin: 10px;
  2232. max-width: 350px;
  2233. word-break: break-all;
  2234. cursor: context-menu;
  2235. overflow: hidden;
  2236. max-height: 42px;
  2237. -moz-transition:max-height 1s ease-in;
  2238. -webkit-transition:max-height 1s ease-in;
  2239. transition:max-height 1s ease-in;
  2240. }
  2241. #pagetual-picker .allpath:hover {
  2242. max-height: calc(100vh - 130px);
  2243. overflow: auto;
  2244. }
  2245. #pagetual-picker .allpath>span.path {
  2246. cursor: pointer;
  2247. }
  2248. #pagetual-picker .allpath>span.path:hover {
  2249. color: orangered;
  2250. }
  2251. `;
  2252. _GM_addStyle(cssText);
  2253. this.mainSignDiv = this.createSignDiv();
  2254. this.allSignDiv = [];
  2255. let frame = document.createElement("div");
  2256. frame.id = "pagetual-picker";
  2257. frame.innerHTML = createHTML(`
  2258. <div class="title">${i18n("picker")}</div>
  2259. <button title="${i18n("closePicker")}" type="button" class="closePicker">
  2260. <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2754">
  2261. <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">
  2262. </path>
  2263. </svg>
  2264. </button>
  2265. <div class="allpath" title="${i18n("switchSelector")}"></div>
  2266. <textarea class="selector" spellcheck="false" name="selector" placeholder="${i18n("pickerPlaceholder")}"></textarea>
  2267. <button id="check" title="${i18n("pickerCheck")}" type="button">
  2268. <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1609">
  2269. <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" p-id="1610">
  2270. </path>
  2271. </svg>
  2272. </button>
  2273. <div class="bottom">
  2274. <input class="xpath" name="xpath" id="checkbox_id" type="checkbox">
  2275. <label for="checkbox_id">XPath</label>
  2276. <button id="edit" title="${i18n("gotoEdit")}" type="button">
  2277. <svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4129" style="color: orangered;fill: orangered;">
  2278. <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" p-id="4130">
  2279. </path>
  2280. </svg>
  2281. </button>
  2282. </div>
  2283. `);
  2284. let closeBtn = frame.querySelector(".closePicker");
  2285. let title = frame.querySelector(".title");
  2286. let allpath = frame.querySelector(".allpath");
  2287. let selectorInput = frame.querySelector(".selector");
  2288. let xpath = frame.querySelector(".xpath");
  2289. let checkBtn = frame.querySelector("#check");
  2290. let editBtn = frame.querySelector("#edit");
  2291. closeBtn.addEventListener("click", e => {
  2292. self.close();
  2293. }, true);
  2294. let moving = false;
  2295. let moveHanlder = e => {
  2296. frame.style.left = e.clientX - 160 + "px";
  2297. frame.style.top = e.clientY - 15 + "px";
  2298. e.stopPropagation();
  2299. e.preventDefault();
  2300. };
  2301. let upHanlder = e => {
  2302. moving = false;
  2303. document.removeEventListener("mousemove", moveHanlder, true);
  2304. title.removeEventListener("mouseup", upHanlder, true);
  2305. e.stopPropagation();
  2306. e.preventDefault();
  2307. };
  2308. title.addEventListener("mousedown", e => {
  2309. moving = true;
  2310. document.addEventListener("mousemove", moveHanlder, true);
  2311. title.addEventListener("mouseup", upHanlder, true);
  2312. });
  2313. frame.addEventListener("mouseenter", e => {
  2314. if (moving) return;
  2315. if (self.mainSignDiv.parentNode) self.mainSignDiv.parentNode.removeChild(self.mainSignDiv);
  2316. self.checkInputSelector();
  2317. });
  2318. frame.addEventListener("mouseleave", e => {
  2319. if (moving) return;
  2320. document.body.appendChild(self.mainSignDiv);
  2321. self.clearSigns();
  2322. });
  2323. checkBtn.addEventListener("click", e => {
  2324. self.checkInputSelector();
  2325. if (this.selectorInput.value) _GM_setClipboard(this.selectorInput.value);
  2326. });
  2327. xpath.addEventListener("click", e => {
  2328. if (!selectorInput.value) {
  2329. self.setSelectorDiv("");
  2330. return;
  2331. }
  2332. let element = getElement(selectorInput.value, document);
  2333. let selector = self.getSelectorFromEle(element);
  2334. self.setSelectorDiv(selector);
  2335. selectorInput.value = selector;
  2336. });
  2337. editBtn.addEventListener("click", e => {
  2338. let editTemp;
  2339. if(ruleParser.curSiteRule.url && !ruleParser.curSiteRule.singleUrl){
  2340. editTemp=ruleParser.curSiteRule;
  2341. }else{
  2342. editTemp={
  2343. name: document.title,
  2344. url: "^"+location.origin.replace(/\./g,"\\.")
  2345. };
  2346. }
  2347. if (selectorInput.value) {
  2348. editTemp.pageElement = selectorInput.value;
  2349. }
  2350. rulesData.editTemp=editTemp;
  2351. storage.setItem("rulesData", rulesData);
  2352. _GM_openInTab(configPage, {active: true});
  2353. });
  2354. this.frame = frame;
  2355. this.xpath = xpath;
  2356. this.allpath = allpath;
  2357. this.selectorInput = selectorInput;
  2358. this.moveHandler = e => {
  2359. if (e.target === document) return;
  2360. self.adjustSignDiv(self.mainSignDiv, self.getTarget(e.target));
  2361. };
  2362. this.clickHandler = e => {
  2363. if (self.inPicker) {
  2364. e.stopPropagation();
  2365. e.preventDefault();
  2366. }
  2367. let target = self.getTarget(e.target);
  2368. let selector = self.getSelectorFromEle(target);
  2369. self.setSelectorDiv(selector);
  2370. selectorInput.value = selector;
  2371. };
  2372. }
  2373.  
  2374. getTarget(ele) {
  2375. while (ele.parentNode && (ele.scrollWidth === 0 || ele.scrollHeight === 0)) {
  2376. ele = ele.parentNode;
  2377. }
  2378. return ele;
  2379. }
  2380.  
  2381. close() {
  2382. this.clearSigns();
  2383. if (this.frame.parentNode) this.frame.parentNode.removeChild(this.frame);
  2384. if (this.mainSignDiv.parentNode) this.mainSignDiv.parentNode.removeChild(this.mainSignDiv);
  2385. document.body.classList.remove("pagetual-picker");
  2386. document.body.removeEventListener("mousemove", this.moveHandler, true);
  2387. document.body.removeEventListener("click", this.clickHandler, true);
  2388. this.inPicker = false;
  2389. }
  2390.  
  2391. setImportant(ele, prop, value) {
  2392. ele.style.setProperty(prop, value, "important");
  2393. }
  2394.  
  2395. createSignDiv() {
  2396. let signDiv = document.createElement("div");
  2397. this.setImportant(signDiv, "position", "absolute");
  2398. this.setImportant(signDiv, "pointer-events", "none");
  2399. this.setImportant(signDiv, "z-index", "2147483647");
  2400. this.setImportant(signDiv, "background", "rgba(120, 170, 210, 0.6)");
  2401. this.setImportant(signDiv, "transition", "all 0.15s ease-out");
  2402. this.setImportant(signDiv, "box-shadow", "rgb(0 0 0) 0px 0px 3px 0px");
  2403. return signDiv;
  2404. }
  2405.  
  2406. adjustSignDiv(div, target) {
  2407. let rect = target.getBoundingClientRect();
  2408. this.setImportant(div, "width", rect.width + "px");
  2409. this.setImportant(div, "height", rect.height + "px");
  2410. this.setImportant(div, "left", rect.left + window.scrollX + "px");
  2411. this.setImportant(div, "top", rect.top + window.scrollY + "px");
  2412. }
  2413.  
  2414. getSelectorFromEle(ele) {
  2415. return this.xpath.checked ? createXPathFromElement(ele) : geneSelector(ele, true);
  2416. }
  2417.  
  2418. setSelectorDiv(selector) {
  2419. let self = this;
  2420. this.allpath.innerHTML = createHTML("");
  2421. if (!selector) return;
  2422. if (this.xpath.checked) {
  2423. let span = document.createElement("span");
  2424. span.innerText = selector;
  2425. span.addEventListener("click", e => {
  2426. self.selectorInput.value = selector;
  2427. self.checkInputSelector();
  2428. }, true);
  2429. this.allpath.appendChild(span);
  2430. } else {
  2431. selector.split(">").forEach((item, index) => self.geneSelectorItem(item, index));
  2432. }
  2433. }
  2434.  
  2435. geneSelectorItem(item, index) {
  2436. let self = this;
  2437. item = item.trim();
  2438. if (!item) return;
  2439. if (index !== 0) {
  2440. let span = document.createElement("span");
  2441. span.innerText = " > ";
  2442. this.allpath.appendChild(span);
  2443. }
  2444. let span = document.createElement("span");
  2445. span.className = "path";
  2446. span.innerText = item;
  2447. span.addEventListener("click", e => {
  2448. let selector = "";
  2449. let target = e.target;
  2450. while (target) {
  2451. selector = target.innerText + selector;
  2452. target = target.previousElementSibling;
  2453. }
  2454. self.selectorInput.value = selector;
  2455. self.checkInputSelector();
  2456. }, true);
  2457. this.allpath.appendChild(span);
  2458. }
  2459.  
  2460. checkInputSelector() {
  2461. let self = this;
  2462. this.clearSigns();
  2463. if (!this.selectorInput.value) return;
  2464. let eles = getAllElements(this.selectorInput.value, document);
  2465. if (eles && eles.length > 0) {
  2466. eles.forEach(ele => {
  2467. let sign = self.createSignDiv();
  2468. document.body.appendChild(sign);
  2469. self.adjustSignDiv(sign, ele);
  2470. self.signList.push(sign);
  2471. });
  2472. }
  2473. }
  2474.  
  2475. clearSigns() {
  2476. this.signList.forEach(sign => {
  2477. if (sign.parentNode) sign.parentNode.removeChild(sign);
  2478. });
  2479. this.signList = [];
  2480. }
  2481.  
  2482. start() {
  2483. if (this.inPicker) return;
  2484. this.inPicker = true;
  2485. document.documentElement.appendChild(this.frame);
  2486. document.body.appendChild(this.mainSignDiv);
  2487. document.body.classList.add("pagetual-picker");
  2488.  
  2489. document.body.addEventListener("mousemove", this.moveHandler, true);
  2490. document.body.addEventListener("click", this.clickHandler, true);
  2491. this.xpath.checked = isXPath(ruleParser.curSiteRule.pageElement);
  2492.  
  2493. let pageElementSel=ruleParser.curSiteRule.pageElement || "";
  2494. if(Array && Array.isArray && Array.isArray(pageElementSel)){
  2495. pageElementSel=pageElementSel[nextIndex<pageElementSel.length?nextIndex:0];
  2496. }
  2497. this.setSelectorDiv(pageElementSel);
  2498. }
  2499. }
  2500.  
  2501. function initConfig(){
  2502. initView();
  2503. _GM_registerMenuCommand(i18n(forceState==1?"enable":"disableSite"), ()=>{
  2504. forceState=(forceState==1?0:1);
  2505. storage.setItem("forceState_"+location.host, forceState);
  2506. showTips(i18n(forceState==1?"disableSiteTips":"enableSiteTips"));
  2507. if(!ruleParser.curSiteRule.url) location.reload();
  2508. });
  2509. _GM_registerMenuCommand(i18n("update"), ()=>{
  2510. updateRules(()=>{
  2511. showTips(i18n("updateSucc"));
  2512. location.reload();
  2513. },(rule,err)=>{
  2514. showTips("Update "+rule.url+" rules fail!");
  2515. });
  2516. showTips(i18n("beginUpdate"));
  2517. });
  2518. if(guidePage.test(location.href)){
  2519. function createEdit(){
  2520. var options = {
  2521. mode: 'code',
  2522. modes: ['code', 'tree'],
  2523. templates: [
  2524. {
  2525. text: 'New site',
  2526. title: 'Insert a new site',
  2527. className: 'jsoneditor-type-object',
  2528. field: 'SiteTemplate',
  2529. value: {
  2530. 'name': 'Site name',
  2531. 'url': 'Site url'
  2532. }
  2533. }
  2534. ],
  2535. schema: {
  2536. "title": "Sites data",
  2537. "description": "Object containing site config",
  2538. "type": "array",
  2539. "items": {
  2540. "type": 'object',
  2541. "properties": {
  2542. "name": {
  2543. "title": "Site Name",
  2544. "description": "The site's name.",
  2545. "examples": [
  2546. "Google"
  2547. ],
  2548. "type": "string"
  2549. },
  2550. "url": {
  2551. "title": "Site Url",
  2552. "description": "The Regexp of site's url.",
  2553. "examples": [
  2554. "^https:\/\/yande\\.re\/"
  2555. ],
  2556. "type": "string"
  2557. }
  2558. },
  2559. "required": ["name", "url"]
  2560. }
  2561. }
  2562. };
  2563. var container = document.getElementById("jsoneditor");
  2564. container.style.height='800px';
  2565. var editor = new JSONEditor(container, options);
  2566. editor.set(ruleParser.customRules);
  2567. document.querySelector("#saveBtn").onclick=e=>{
  2568. try{
  2569. storage.setItem("hpRules", []);
  2570. let customRules=editor.get();
  2571. if(!customRules){
  2572. storage.setItem("customRules", "");
  2573. }else{
  2574. if(Array && Array.isArray && !Array.isArray(customRules)){
  2575. showTips("Rules must be a Array!");
  2576. return;
  2577. }
  2578. debug(customRules);
  2579. storage.setItem("customRules", customRules);
  2580. }
  2581. }catch(e){
  2582. debug(e);
  2583. showTips("JSON error, check again!");
  2584. return;
  2585. }
  2586. showTips("Edit successfully");
  2587. };
  2588. }
  2589. if(JSONEditor){
  2590. createEdit();
  2591. }else{
  2592. window.onload = e => {
  2593. createEdit();
  2594. }
  2595. }
  2596. return true;
  2597. }
  2598. if(location.href.indexOf("PagetualGuide")!=-1) return true;
  2599.  
  2600. var configCon,insertPos;
  2601. var noRules=!rulesData.urls || rulesData.urls.length===0;
  2602. if(ruleImportUrlReg.test(location.href)){
  2603. if(noRules){
  2604. setTimeout(() => {
  2605. showTips(i18n("firstAlert"));
  2606. }, 3000);
  2607. setTimeout(() => {
  2608. showTips(i18n("firstAlert"));
  2609. }, 6000);
  2610. showTips(i18n("firstAlert"));
  2611. }
  2612. let importBtn = document.createElement("button"), targetPre;
  2613. importBtn.innerText = i18n("import");
  2614. importBtn.style.marginTop = "100px";
  2615. importBtn.style.float = "right";
  2616. importBtn.style.position = "static";
  2617. importBtn.style.display = "block";
  2618. importBtn.style.fontSize = "20px";
  2619. importBtn.addEventListener("click", e => {
  2620. if (targetPre) {
  2621. if (importBtn.parentNode) importBtn.parentNode.removeChild(importBtn);
  2622. try {
  2623. let rules=targetPre.innerText.trim();
  2624. let isContent=/['"]name['"]/i.test(rules);
  2625. if(isContent){
  2626. let ruleList=JSON.parse(`[${rules}]`);
  2627. for(let i in ruleList){
  2628. let hasRule = false;
  2629. let r = ruleList[i];
  2630. for(let j in ruleParser.customRules){
  2631. if(ruleParser.customRules[j].name == r.name){
  2632. ruleParser.customRules[j] = r;
  2633. hasRule = true;
  2634. break;
  2635. }
  2636. }
  2637. if(!hasRule)ruleParser.customRules.push(r);
  2638. }
  2639. storage.setItem("customRules", ruleParser.customRules);
  2640. storage.setItem("hpRules", []);
  2641. showTips(i18n("importSucc"));
  2642. }else{
  2643. rules=rules.split("\n");
  2644. let diff=false;
  2645. for(let c=0;c<rules.length;c++){
  2646. let urlArr=rules[c].split("|"),url,type=1;
  2647. if(urlArr.length==1){
  2648. url=urlArr[0].trim();
  2649. if(!/^http/.test(url)){
  2650. showTips("Wrong url, check again!");
  2651. return;
  2652. }
  2653. }else if(urlArr.length==2){
  2654. type=urlArr[0].trim();
  2655. url=urlArr[1].trim();
  2656. if(!/^http/.test(url)){
  2657. showTips("Wrong url, check again!");
  2658. return;
  2659. }
  2660. }else{
  2661. break;
  2662. }
  2663. let maxId=0,hasUrl=false;
  2664. if(!rulesData.urls){
  2665. rulesData.urls=[];
  2666. maxId=1;
  2667. }else{
  2668. rulesData.urls.forEach(u=>{
  2669. if(maxId<u.id){
  2670. maxId=u.id;
  2671. }
  2672. if(u.url==url){
  2673. hasUrl=true;
  2674. }
  2675. });
  2676. if(hasUrl)break;
  2677. }
  2678. diff=true;
  2679. if(!rulesData.sort)rulesData.sort=[1];
  2680. rulesData.urls.push({id:maxId+1,url:url,type:type});
  2681. rulesData.sort.unshift(maxId+1);
  2682. }
  2683. if(!diff)return;
  2684. storage.setItem("rulesData", rulesData);
  2685.  
  2686. if(rulesData.urls)ruleUrls=ruleUrls.concat(rulesData.urls);
  2687. if(rulesData.sort){
  2688. let urls=[];
  2689. rulesData.sort.forEach(id=>{
  2690. for(let s=0;s<ruleUrls.length;s++){
  2691. if(id==ruleUrls[s].id){
  2692. urls.push(ruleUrls[s]);
  2693. break;
  2694. }
  2695. }
  2696. });
  2697. ruleUrls=urls;
  2698. }
  2699. updateRules(()=>{
  2700. showTips(i18n("updateSucc"));
  2701. location.reload();
  2702. },(rule,err)=>{
  2703. showTips("Update "+rule.url+" rules fail!");
  2704. });
  2705. showTips(i18n("beginUpdate"));
  2706. }
  2707. } catch (e) {
  2708. _GM_notification(e.toString());
  2709. }
  2710. }
  2711. });
  2712. document.addEventListener("mouseover", e => {
  2713. if (e.target.tagName === "PRE") {
  2714. let nameAttr=e.target.getAttribute("name");
  2715. if(nameAttr=="pagetual" || nameAttr=="user-content-pagetual"){
  2716. targetPre = e.target;
  2717. let clientHeight = 35 - e.target.clientHeight;
  2718. if (clientHeight > -20) clientHeight = -20;
  2719. importBtn.style.marginTop = `${clientHeight}px`;
  2720. e.target.appendChild(importBtn);
  2721. }
  2722. }
  2723. });
  2724.  
  2725. if(location.href==configPage){
  2726. _GM_addStyle(`
  2727. p>span:nth-child(1),p>span:nth-child(2),p>span:nth-child(3){
  2728. cursor: pointer;
  2729. user-select: none;
  2730. }
  2731. p>span:nth-child(1):hover,p>span:nth-child(2):hover,p>span:nth-child(3):hover{
  2732. color:red;
  2733. }
  2734. .updateDate{
  2735. cursor: pointer;
  2736. user-select: none;
  2737. }
  2738. .updateDate:hover{
  2739. color:red;
  2740. }
  2741. input[type=number]::-webkit-inner-spin-button,
  2742. input[type=number]::-webkit-outer-spin-button {
  2743. -webkit-appearance: none;
  2744. margin: 0;
  2745. }
  2746. input[type=number] {
  2747. -moz-appearance:textfield;
  2748. }
  2749. `);
  2750. document.querySelector("[name='user-content-click2import']").innerText=i18n("click2ImportRule")
  2751. configCon=document.querySelector(".markdown-body");
  2752. insertPos=configCon.querySelector("hr");
  2753.  
  2754. if(!noRules){
  2755. document.querySelector("pre[name='user-content-pagetual']").style.display="none";
  2756. document.querySelector("p[name='user-content-click2import']").style.display="none";
  2757. }
  2758. }else return true;
  2759. }else return false;
  2760. class Rulebar {
  2761. init(ruleUrl){
  2762. this.ruleUrl=ruleUrl;
  2763. this.item=document.createElement("p");
  2764. this.item.dataset.id=this.ruleUrl.id;
  2765. let url=document.createElement("span");
  2766. url.innerHTML=ruleUrl.url;
  2767. let up=document.createElement("span");
  2768. up.innerHTML="↑ ";
  2769. up.title=i18n("sortTitle");
  2770. let down=document.createElement("span");
  2771. down.innerHTML="↓ ";
  2772. down.title=i18n("sortTitle");
  2773. let del=document.createElement("span");
  2774. del.innerHTML="× ";
  2775. up.onclick=e=>{
  2776. this.moveUp();
  2777. };
  2778. down.onclick=e=>{
  2779. this.moveDown();
  2780. };
  2781. del.onclick=e=>{
  2782. this.del();
  2783. };
  2784. this.item.appendChild(up);
  2785. this.item.appendChild(down);
  2786. this.item.appendChild(del);
  2787. this.item.appendChild(url);
  2788. configCon.insertBefore(this.item, insertPos);
  2789. }
  2790. saveSort(){
  2791. let sort=[];
  2792. [].forEach.call(this.item.parentNode.querySelectorAll("p[data-id]"), i=>{
  2793. sort.push(i.dataset.id);
  2794. });
  2795. rulesData.sort=sort;
  2796. storage.setItem("rulesData", rulesData);
  2797. }
  2798. moveUp(){
  2799. let preE=this.item.previousElementSibling;
  2800. if(preE.tagName=="P" && preE.children.length>1){
  2801. this.item.parentNode.insertBefore(this.item,preE);
  2802. this.saveSort();
  2803. }
  2804. }
  2805. moveDown(){
  2806. let nextE=this.item.nextElementSibling;
  2807. if(nextE.tagName=="P" && nextE.children.length>1){
  2808. this.item.parentNode.insertBefore(nextE,this.item);
  2809. this.saveSort();
  2810. }
  2811. }
  2812. del(){
  2813. if(this.ruleUrl.id<2){
  2814. showTips(i18n("cantDel"));
  2815. }else if(window.confirm(i18n("confirmDel"))){
  2816. for(let u=0;u<rulesData.urls.length;u++){
  2817. if(this.ruleUrl.id==rulesData.urls[u].id){
  2818. rulesData.urls.splice(u,1);
  2819. break;
  2820. }
  2821. }
  2822. for(let u=0;u<ruleUrls.length;u++){
  2823. if(this.ruleUrl.id==ruleUrls[u].id){
  2824. ruleUrls.splice(u,1);
  2825. break;
  2826. }
  2827. }
  2828. for(let u=0;u<rulesData.sort.length;u++){
  2829. if(this.ruleUrl.id==rulesData.sort[u]){
  2830. rulesData.sort.splice(u,1);
  2831. break;
  2832. }
  2833. }
  2834. storage.setItem("rulesData", rulesData);
  2835. ruleParser.rules=ruleParser.rules.filter(item=>{return item.from!=this.ruleUrl.id});
  2836. storage.setItem("rules", ruleParser.rules);
  2837. this.item.parentNode.removeChild(this.item);
  2838. //location.reload();
  2839. }
  2840. }
  2841. }
  2842. let updateP=document.createElement("p"),i=0;
  2843. let now=new Date().getTime(),inUpdate=false;
  2844.  
  2845.  
  2846. let pastDate=(new Date(updateDate)).toString(),passStr;
  2847. let passTime=(now-updateDate)/1000;
  2848. if(isNaN(passTime)){
  2849. passStr=i18n("firstUpdate");
  2850. }else if(passTime<60){
  2851. passStr=i18n("passSec", parseInt(passTime))+" 👆 "+i18n("click2update");
  2852. }else if(passTime<60*60){
  2853. passStr=i18n("passMin", parseInt(passTime/60))+" 👆 "+i18n("click2update");
  2854. }else if(passTime<60*60*24){
  2855. passStr=i18n("passHour", parseInt(passTime/3600))+" 👆 "+i18n("click2update");
  2856. }else{
  2857. passStr=i18n("passDay", parseInt(passTime/86400))+" 👆 "+i18n("click2update");
  2858. }
  2859.  
  2860.  
  2861. updateP.className="updateDate";
  2862. updateP.innerHTML=passStr;
  2863. updateP.title=i18n("update")+" - "+pastDate;
  2864. updateP.onclick=e=>{
  2865. updateRules(()=>{
  2866. showTips(i18n("updateSucc"));
  2867. updateP.innerHTML=i18n("passSec", 0);
  2868. updateP.title=i18n("update");
  2869. },(rule,err)=>{
  2870. showTips("Update "+rule.url+" rules fail!");
  2871. });
  2872. showTips(i18n("beginUpdate"));
  2873. };
  2874. configCon.insertBefore(updateP, insertPos);
  2875. if(ruleUrls){
  2876. ruleUrls.forEach(ruleUrl=>{
  2877. var rulebar=new Rulebar();
  2878. rulebar.init(ruleUrl);
  2879. });
  2880. }
  2881. let customUrlsTitle=document.createElement("h2");
  2882. customUrlsTitle.innerHTML=i18n("customUrls");
  2883. configCon.insertBefore(customUrlsTitle, insertPos);
  2884. let customUrlsInput=document.createElement("textarea");
  2885. customUrlsInput.style.width="100%";
  2886. customUrlsInput.placeholder="http://wedata.net/databases/AutoPagerize/items_all.json";
  2887. customUrlsInput.spellcheck=false;
  2888. configCon.insertBefore(customUrlsInput, insertPos);
  2889.  
  2890. let btns=document.createElement("div");
  2891. btns.style.display="flex";
  2892. configCon.insertBefore(btns, insertPos);
  2893. let upBtnImg=document.createElement("div");
  2894. upBtnImg.style.width="50%";
  2895. let upBtnImgTitle=document.createElement("h2");
  2896. upBtnImgTitle.style.whiteSpace="nowrap";
  2897. upBtnImgTitle.style.overflow="auto";
  2898. upBtnImgTitle.innerHTML=i18n("upBtnImg");
  2899. upBtnImg.appendChild(upBtnImgTitle);
  2900. let upBtnImgInput=document.createElement("input");
  2901. upBtnImgInput.style.width="100%";
  2902. upBtnImgInput.placeholder="data:image/png;base64,UpBtn";
  2903. upBtnImgInput.value=rulesData.upBtnImg||'';
  2904. upBtnImgInput.spellcheck=false;
  2905. upBtnImg.appendChild(upBtnImgInput);
  2906. btns.appendChild(upBtnImg);
  2907.  
  2908. let downBtnImg=document.createElement("div");
  2909. downBtnImg.style.width="50%";
  2910. let downBtnImgTitle=document.createElement("h2");
  2911. downBtnImgTitle.style.whiteSpace="nowrap";
  2912. downBtnImgTitle.style.overflow="auto";
  2913. downBtnImgTitle.innerHTML=i18n("downBtnImg");
  2914. downBtnImg.appendChild(downBtnImgTitle);
  2915. let downBtnImgInput=document.createElement("input");
  2916. downBtnImgInput.style.width="100%";
  2917. downBtnImgInput.placeholder="data:image/png;base64,DownBtn";
  2918. downBtnImgInput.value=rulesData.downBtnImg||'';
  2919. downBtnImgInput.spellcheck=false;
  2920. downBtnImg.appendChild(downBtnImgInput);
  2921. btns.appendChild(downBtnImg);
  2922.  
  2923. let otherBtns=document.createElement("div");
  2924. otherBtns.style.display="flex";
  2925. configCon.insertBefore(otherBtns, insertPos);
  2926. let loadingText=document.createElement("div");
  2927. loadingText.style.width="100%";
  2928. let loadingTextTitle=document.createElement("h2");
  2929. loadingTextTitle.style.whiteSpace="nowrap";
  2930. loadingTextTitle.style.overflow="auto";
  2931. loadingTextTitle.innerHTML=i18n("loadingTextTitle");
  2932. loadingText.appendChild(loadingTextTitle);
  2933. let loadingTextInput=document.createElement("input");
  2934. loadingTextInput.value=rulesData.loadingText||'';
  2935. loadingTextInput.placeholder=i18n("loadingText");
  2936. loadingTextInput.style.width="100%";
  2937. loadingTextInput.style.margin="0";
  2938. loadingTextInput.spellcheck=false;
  2939. loadingText.appendChild(loadingTextInput);
  2940. otherBtns.appendChild(loadingText);
  2941.  
  2942. let opacity=document.createElement("div");
  2943. let opacityTitle=document.createElement("h2");
  2944. opacityTitle.style.whiteSpace="nowrap";
  2945. opacityTitle.style.overflow="visible";
  2946. opacityTitle.innerHTML=i18n("opacity");
  2947. opacity.appendChild(opacityTitle);
  2948. let opacityInput=document.createElement("input");
  2949. opacityInput.value=rulesData.opacity*100;
  2950. opacityInput.type="number";
  2951. opacityInput.style.width="95px";
  2952. opacityInput.style.margin="0";
  2953. opacityInput.placeholder=i18n("opacityPlaceholder");
  2954. opacityInput.spellcheck=false;
  2955. opacity.appendChild(opacityInput);
  2956. otherBtns.appendChild(opacity);
  2957.  
  2958. let pageElementCss=document.createElement("div");
  2959. pageElementCss.style.marginBottom="30px";
  2960. let pageElementCssTitle=document.createElement("h2");
  2961. pageElementCssTitle.innerHTML=i18n("pageElementCss");
  2962. pageElementCss.appendChild(pageElementCssTitle);
  2963. let pageElementCssInput=document.createElement("input");
  2964. pageElementCssInput.value=rulesData.pageElementCss||'';
  2965. pageElementCssInput.style.width="100%";
  2966. pageElementCssInput.style.margin="0";
  2967. pageElementCssInput.placeholder="font-size: xx-large;";
  2968. pageElementCssInput.spellcheck=false;
  2969. pageElementCss.appendChild(pageElementCssInput);
  2970. configCon.insertBefore(pageElementCss, insertPos);
  2971.  
  2972. let customCss=document.createElement("div");
  2973. customCss.style.marginBottom="50px";
  2974. let customCssTitle=document.createElement("h2");
  2975. customCssTitle.innerHTML=i18n("customCss");
  2976. customCss.appendChild(customCssTitle);
  2977. let customCssInput=document.createElement("textarea");
  2978. customCssInput.value=rulesData.customCss||'';
  2979. customCssInput.style.width="100%";
  2980. customCssInput.style.margin="0";
  2981. customCssInput.placeholder=".pagetual{\n}";
  2982. customCssInput.spellcheck=false;
  2983. customCss.appendChild(customCssInput);
  2984. configCon.insertBefore(customCss, insertPos);
  2985.  
  2986. let configTable=document.createElement("table");
  2987. configTable.style.width="100%";
  2988. let configTbody=document.createElement("tbody");
  2989. configTbody.style.width="100%";
  2990. configTbody.style.display="inline-table";
  2991. configTable.appendChild(configTbody);
  2992. configCon.insertBefore(configTable, insertPos);
  2993. function createCheckbox(innerText, val, tag, parentCheck, otherType){
  2994. if (typeof val == 'undefined') val = "";
  2995. let title=document.createElement(tag||"h3");
  2996. title.innerHTML=innerText;
  2997. title.style.overflowWrap="normal";
  2998. let input=document.createElement("input");
  2999. input.type=otherType||"checkbox";
  3000. input.style.width="30px";
  3001. input.style.height="20px";
  3002. input.style.float="left";
  3003. input.style.margin="5px";
  3004. input.value=val;
  3005. input.checked=val;
  3006. let td=document.createElement("td");
  3007. td.appendChild(input);
  3008. if(parentCheck){
  3009. title.style.margin="0";
  3010. td.appendChild(title);
  3011. let parent=parentCheck.parentNode.nextElementSibling;
  3012. let tr=parent.querySelector("tr");
  3013. if(!tr){
  3014. tr=document.createElement("tr");
  3015. parent.appendChild(tr);
  3016. }
  3017. tr.appendChild(td);
  3018. if(!parentCheck.checked){
  3019. td.style.display="none";
  3020. }
  3021. parentCheck.addEventListener("click", e=>{
  3022. td.style.display=parentCheck.checked?"":"none";
  3023. });
  3024. }else{
  3025. let tr=document.createElement("tr");
  3026. tr.appendChild(td);
  3027. td=document.createElement("td");
  3028. td.appendChild(title);
  3029. tr.appendChild(td);
  3030. configTable.children[0].appendChild(tr);
  3031. }
  3032. return input;
  3033. }
  3034.  
  3035. let enableWhiteListInput=createCheckbox(i18n("autoRun"), rulesData.enableWhiteList!=true);
  3036. let enableDebugInput=createCheckbox(i18n("enableDebug"), rulesData.enableDebug!=false);
  3037. let enableHistoryInput=createCheckbox(i18n("enableHistory"), rulesData.enableHistory===true);
  3038. let openInNewTabInput=createCheckbox(i18n("openInNewTab"), rulesData.openInNewTab!=false);
  3039. let initRunInput=createCheckbox(i18n("initRun"), rulesData.initRun!=false);
  3040. let autoLoadNumInput=createCheckbox(i18n("autoLoadNum"), rulesData.autoLoadNum, "h4", initRunInput, "number");
  3041. let preloadInput=createCheckbox(i18n("preload"), rulesData.preload!=false);
  3042. let dbClick2StopInput=createCheckbox(i18n("dbClick2Stop"), rulesData.dbClick2Stop);
  3043. let manualModeInput=createCheckbox(i18n("manualMode"), rulesData.manualMode);
  3044. let arrowToScrollInput=createCheckbox(i18n("arrowToScroll"), rulesData.arrowToScroll);
  3045. let hideBarInput=createCheckbox(i18n("hideBar"), rulesData.hideBar, "h4", dbClick2StopInput);
  3046. let dbClick2StopCtrlInput=createCheckbox(i18n("dbClick2StopCtrl"), rulesData.dbClick2StopCtrl, "h4", dbClick2StopInput);
  3047. let dbClick2StopAltInput=createCheckbox(i18n("dbClick2StopAlt"), rulesData.dbClick2StopAlt, "h4", dbClick2StopInput);
  3048. let dbClick2StopShiftInput=createCheckbox(i18n("dbClick2StopShift"), rulesData.dbClick2StopShift, "h4", dbClick2StopInput);
  3049. let dbClick2StopMetaInput=createCheckbox(i18n("dbClick2StopMeta"), rulesData.dbClick2StopMeta, "h4", dbClick2StopInput);
  3050. let dbClick2StopKeyInput=createCheckbox(i18n("dbClick2StopKey"), rulesData.dbClick2StopKey, "h4", dbClick2StopInput, "text");
  3051. dbClick2StopKeyInput.setAttribute("maxlength", "1");
  3052.  
  3053. let customRulesTitle=document.createElement("h2");
  3054. customRulesTitle.innerHTML=i18n("customRules");
  3055. configCon.insertBefore(customRulesTitle, insertPos);
  3056. let customRulesInput=document.createElement("textarea");
  3057. customRulesInput.spellcheck=false;
  3058. configCon.insertBefore(customRulesInput, insertPos);
  3059. if(rulesData.editTemp){
  3060. if(!ruleParser.customRules){
  3061. ruleParser.customRules=[];
  3062. }
  3063. for(let i in ruleParser.customRules){
  3064. if(ruleParser.customRules[i].url==rulesData.editTemp.url){
  3065. ruleParser.customRules.splice(i, 1);
  3066. break;
  3067. }
  3068. }
  3069. ruleParser.customRules.unshift(rulesData.editTemp);
  3070. rulesData.editTemp=null;
  3071. storage.setItem("rulesData", rulesData);
  3072. customRulesInput.previousElementSibling.scrollIntoView();
  3073. }
  3074. customRulesInput.style.width="100%";
  3075. customRulesInput.style.height="800px";
  3076. 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]`;
  3077. customRulesInput.value=getFormatJSON(ruleParser.customRules);
  3078. let blacklistInput=document.createElement("textarea");
  3079. blacklistInput.style.width="100%";
  3080. blacklistInput.style.height="500px";
  3081. blacklistInput.style.display="none";
  3082. blacklistInput.spellcheck=false;
  3083. blacklistInput.placeholder="http://*.xxx.com/*/y";
  3084. blacklistInput.value=rulesData.blacklist?rulesData.blacklist.join("\n"):"";
  3085. let blacklistBtn=document.createElement("button");
  3086. blacklistBtn.innerText=i18n("editBlacklist");
  3087. blacklistBtn.style.width="100%";
  3088. blacklistBtn.onclick=e=>{
  3089. blacklistInput.style.display=blacklistInput.style.display=="none"?"":"none";
  3090. };
  3091. configCon.insertBefore(blacklistBtn, insertPos);
  3092. configCon.insertBefore(blacklistInput, insertPos);
  3093. let saveBtn=document.createElement("button");
  3094. saveBtn.innerHTML=i18n("save");
  3095. saveBtn.style.width="100%";
  3096. saveBtn.style.position="fixed";
  3097. saveBtn.style.zIndex="999";
  3098. saveBtn.style.bottom=0;
  3099. saveBtn.style.left=0;
  3100. saveBtn.style.fontSize="x-large";
  3101. configCon.insertBefore(saveBtn, insertPos);
  3102. saveBtn.onclick=e=>{
  3103. try{
  3104. storage.setItem("hpRules", []);
  3105. if(customRulesInput.value==""){
  3106. storage.setItem("customRules", "");
  3107. }else{
  3108. let customRules=JSON.parse(customRulesInput.value);
  3109. if(Array && Array.isArray && !Array.isArray(customRules)){
  3110. showTips("Rules must be a Array!");
  3111. return;
  3112. }
  3113. debug(customRules);
  3114. storage.setItem("customRules", customRules);
  3115. }
  3116. }catch(e){
  3117. debug(e);
  3118. showTips("JSON error, check again!");
  3119. return;
  3120. }
  3121. rulesData.opacity=opacityInput.value/100;
  3122. rulesData.blacklist=blacklistInput.value?blacklistInput.value.split("\n"):"";
  3123. rulesData.hideBar=hideBarInput.checked;
  3124. rulesData.dbClick2Stop=dbClick2StopInput.checked;
  3125. rulesData.enableWhiteList=!enableWhiteListInput.checked;
  3126. rulesData.enableDebug=enableDebugInput.checked;
  3127. rulesData.enableHistory=enableHistoryInput.checked;
  3128. rulesData.openInNewTab=openInNewTabInput.checked;
  3129. rulesData.initRun=initRunInput.checked;
  3130. rulesData.autoLoadNum=autoLoadNumInput.value||'';
  3131. rulesData.preload=preloadInput.checked;
  3132. rulesData.manualMode=manualModeInput.checked;
  3133. rulesData.arrowToScroll=arrowToScrollInput.checked;
  3134. rulesData.pageElementCss=pageElementCssInput.value;
  3135. rulesData.customCss=customCssInput.value;
  3136. rulesData.upBtnImg=upBtnImgInput.value;
  3137. rulesData.downBtnImg=downBtnImgInput.value;
  3138. rulesData.loadingText=loadingTextInput.value;
  3139. rulesData.dbClick2StopCtrl=dbClick2StopCtrlInput.checked;
  3140. rulesData.dbClick2StopAlt=dbClick2StopAltInput.checked;
  3141. rulesData.dbClick2StopShift=dbClick2StopShiftInput.checked;
  3142. rulesData.dbClick2StopMeta=dbClick2StopMetaInput.checked;
  3143. rulesData.dbClick2StopKey=dbClick2StopKeyInput.value;
  3144. storage.setItem("rulesData", rulesData);
  3145. let customUrls=customUrlsInput.value.trim();
  3146. if(customUrls){
  3147. customUrls=customUrls.split(/\n/);
  3148. for(let c=0;c<customUrls.length;c++){
  3149. let url;
  3150. if(/^0\s*\|/.test(customUrls[c])){
  3151. url=customUrls[c].replace(/^0\s*\|\s*/, "").trim();
  3152. if(!/^http/.test(url)){
  3153. showTips("Wrong url, check again!");
  3154. return;
  3155. }
  3156. }else{
  3157. url=customUrls[c].trim();
  3158. if(!/^http/.test(url)){
  3159. showTips("Wrong url, check again!");
  3160. return;
  3161. }
  3162. }
  3163. let maxId=1,hasUrl=false;
  3164. if(!rulesData.urls){
  3165. rulesData.urls=[];
  3166. }
  3167. ruleUrls.forEach(u=>{
  3168. if(maxId<u.id){
  3169. maxId=u.id;
  3170. }
  3171. if(u.url==url){
  3172. hasUrl=true;
  3173. }
  3174. });
  3175. if(hasUrl)break;
  3176. if(!rulesData.sort)rulesData.sort=[1];
  3177. rulesData.urls.push({id:maxId+1,url:url});
  3178. rulesData.sort.push(maxId+1);
  3179. storage.setItem("rulesData", rulesData);
  3180. }
  3181. }
  3182. showTips("The settings are saved");
  3183. location.reload();
  3184. };
  3185. return true;
  3186. }
  3187.  
  3188. var inUpdate=false;
  3189. function updateRules(success,fail){
  3190. if(inUpdate)return;
  3191. inUpdate=true;
  3192. let ruleIndex=ruleUrls.length-1;
  3193. storage.setItem("hpRules", []);
  3194. function addNextRule(){
  3195. if(ruleIndex<0){
  3196. let now=new Date().getTime();
  3197. storage.setItem("ruleLastUpdate", now);
  3198. storage.setItem("rules", ruleParser.rules);
  3199. inUpdate=false;
  3200. success();
  3201. }else{
  3202. let rule=ruleUrls[ruleIndex--];
  3203. ruleParser.addRuleByUrl(rule.url, rule.id, (json,err)=>{
  3204. if(!json){
  3205. fail(rule,err);
  3206. }
  3207. addNextRule();
  3208. })
  3209. }
  3210. }
  3211. addNextRule();
  3212. }
  3213.  
  3214. function objIsArr(obj) {
  3215. return obj &&
  3216. typeof obj === 'object' &&
  3217. typeof obj.length === 'number' &&
  3218. !(obj.propertyIsEnumerable('length'));
  3219. }
  3220.  
  3221. function isVisible(el, win) {
  3222. if(!el || !el.offsetParent)return false;
  3223. var loopable = true,
  3224. visible = el.tagName && win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  3225. while(loopable && visible) {
  3226. el = el.parentNode;
  3227.  
  3228. if(el && el.tagName && el.tagName!="BODY") {
  3229. visible = win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  3230. }else {
  3231. loopable = false;
  3232. }
  3233. }
  3234. return visible;
  3235. }
  3236.  
  3237. function getElementTop(ele) {
  3238. var actualTop = ele.offsetTop;
  3239. var current = ele.offsetParent;
  3240. while (current) {
  3241. actualTop += current.offsetTop;
  3242. current = current.offsetParent;
  3243. }
  3244. return actualTop;
  3245. }
  3246.  
  3247. function getFormatJSON(obj){
  3248. if(!objIsArr(obj) || obj.length === 0)return "";
  3249. return JSON.stringify(obj, null, 4);
  3250. let ret="[\n";
  3251. let len=obj.length,i=0,isLast;
  3252. obj.forEach(item=>{
  3253. ret+=" {\n";
  3254. let iLen=Object.keys(item).length,j=0;
  3255. for(let key in item){
  3256. isLast=(++j)==iLen;
  3257. let value=item[key];
  3258. if(objIsArr(value)){
  3259. let vstr="[",v=0,vIsLast=false;
  3260. value.forEach(vi=>{
  3261. vIsLast=(++v)==value.length;
  3262. vstr+="\""+vi.replace(/\\/g,"\\\\")+"\""+(vIsLast?"":",");
  3263. });
  3264. vstr+="]";
  3265. ret+=" \""+key+"\":"+vstr+""+(isLast?"":",")+"\n";
  3266. }else{
  3267. if(typeof value=="string"){
  3268. value=value.replace(/\\/g,"\\\\").replace(/"/g,"\\\"");
  3269. value="\""+value+"\"";
  3270. }
  3271. ret+=" \""+key+"\":"+value+""+(isLast?"":",")+"\n";
  3272. }
  3273. }
  3274. isLast=(++i)==len;
  3275. ret+=" }"+(isLast?"":",")+"\n";
  3276. });
  3277. ret+="]";
  3278. return ret;
  3279. }
  3280.  
  3281. function globMatch(first, second) {
  3282. if (first.length == 0 && second.length == 0){
  3283. return true;
  3284. }
  3285.  
  3286. if (first.length > 1 && first[0] == '*' &&
  3287. second.length == 0){
  3288. return false;
  3289. }
  3290.  
  3291. if ((first.length > 1 && first[0] == '?') ||
  3292. (first.length != 0 && second.length != 0 &&
  3293. first[0] == second[0])){
  3294. return globMatch(first.substring(1),
  3295. second.substring(1));
  3296. }
  3297.  
  3298. if (first.length > 0 && first[0] == '*'){
  3299. return globMatch(first.substring(1), second) ||
  3300. globMatch(first, second.substring(1));
  3301. }
  3302.  
  3303. return false;
  3304. }
  3305.  
  3306. function initRules(callback) {
  3307. /*0 wedata格式,1 pagetual格式*/
  3308. ruleUrls=[
  3309. {
  3310. id:1,
  3311. url:'http://wedata.net/databases/AutoPagerize/items_all.json',
  3312. type:0,
  3313. }
  3314. ];var i=0,j=0;
  3315.  
  3316. ruleParser.initSavedRules(()=>{
  3317. storage.getItem("rulesData", data=>{
  3318. if(data){
  3319. rulesData=data;
  3320. if(data.urls)ruleUrls=ruleUrls.concat(data.urls);
  3321. if(data.sort){
  3322. let urls=[];
  3323. data.sort.forEach(id=>{
  3324. for(let s=0;s<ruleUrls.length;s++){
  3325. if(id==ruleUrls[s].id){
  3326. urls.push(ruleUrls[s]);
  3327. break;
  3328. }
  3329. }
  3330. });
  3331. ruleUrls=urls;
  3332. }
  3333. }
  3334. let upBtnImg=rulesData.upBtnImg,downBtnImg=rulesData.downBtnImg;
  3335. if(upBtnImg && downBtnImg){
  3336. downSvgCSS=downSvgCSS.replace("transform: rotate(180deg);","");
  3337. }else if(upBtnImg && !downBtnImg){
  3338. downBtnImg=upBtnImg;
  3339. }else if(downBtnImg && !upBtnImg){
  3340. upBtnImg=downBtnImg;
  3341. }
  3342. if(upBtnImg){
  3343. upSvg=`<img src="${upBtnImg}"/>`;
  3344. }
  3345. if(downBtnImg){
  3346. downSvg=`<img src="${downBtnImg}"/>`;
  3347. }
  3348. setLoadingDiv(rulesData.loadingText || i18n("loadingText"));
  3349. if(typeof(rulesData.opacity)=="undefined"){
  3350. rulesData.opacity=0.3;
  3351. }
  3352. if(typeof(rulesData.hideBar)=="undefined"){
  3353. rulesData.hideBar=false;
  3354. }
  3355. if(typeof(rulesData.dbClick2Stop)=="undefined"){
  3356. rulesData.dbClick2Stop=true;
  3357. }
  3358. if(typeof(rulesData.enableWhiteList)=="undefined"){
  3359. rulesData.enableWhiteList=false;
  3360. }
  3361. if(typeof(rulesData.enableHistory)=="undefined"){
  3362. rulesData.enableHistory=false;
  3363. }
  3364. if(typeof(rulesData.openInNewTab)=="undefined"){
  3365. rulesData.openInNewTab=true;
  3366. }
  3367. if(typeof(rulesData.enableDebug)=="undefined"){
  3368. rulesData.enableDebug=true;
  3369. }
  3370. if(typeof(rulesData.initRun)=="undefined"){
  3371. rulesData.initRun=true;
  3372. }
  3373. if(typeof(rulesData.preload)=="undefined"){
  3374. rulesData.preload=true;
  3375. }
  3376. if(typeof(rulesData.manualMode)=="undefined"){
  3377. rulesData.manualMode=false;
  3378. }
  3379. if(typeof(rulesData.arrowToScroll)=="undefined"){
  3380. rulesData.arrowToScroll=false;
  3381. }
  3382. if(rulesData.blacklist && rulesData.blacklist.length>0){
  3383. for(let b in rulesData.blacklist){
  3384. let curGlob=rulesData.blacklist[b];
  3385. if(globMatch(curGlob, location.href)){
  3386. return;
  3387. }
  3388. }
  3389. }
  3390. if(rulesData.autoLoadNum){
  3391. autoLoadNum=parseInt(rulesData.autoLoadNum);
  3392. }
  3393. enableDebug=rulesData.enableDebug;
  3394. storage.getItem("nextSwitch_"+location.host, i=>{
  3395. storage.getItem("forceState_"+location.host, v=>{
  3396. storage.getItem("ruleLastUpdate", date=>{
  3397. if(typeof(i)!=="undefined"){
  3398. nextIndex=i;
  3399. }
  3400. if(typeof(v)=="undefined"){
  3401. v=(rulesData.enableWhiteList?1:0);
  3402. }
  3403. forceState=v;
  3404. updateDate=date;
  3405. if(initConfig())return;
  3406. if(forceState==1)return;
  3407. let now=new Date().getTime();
  3408. if(!date || now-date>2*24*60*60*1000){
  3409. updateRules(()=>{
  3410. },(rule,err)=>{});
  3411. storage.setItem("ruleLastUpdate", now);
  3412. }
  3413. callback();
  3414. });
  3415. });
  3416. });
  3417. });
  3418. });
  3419. }
  3420.  
  3421. function requestDoc(url, callback){
  3422. _GM_xmlhttpRequest({
  3423. url: url,
  3424. method: 'GET',
  3425. overrideMimeType: 'text/html;charset='+document.charset,
  3426. headers: {
  3427. 'Referer': location.href,
  3428. "Content-Type": "text/html;charset="+document.charset,
  3429. },
  3430. timeout: 5000,
  3431. onload: function(res) {
  3432. var doc=null,response=res.response;
  3433. let preCode=ruleParser.curSiteRule.pageElementPre || ruleParser.curSiteRule.pagePre;
  3434. if(preCode){
  3435. try{
  3436. if (typeof _unsafeWindow.pagetualPagePre!='undefined') {
  3437. response = _unsafeWindow.pagetualPagePre(response);
  3438. } else if (preCode.length == 2) {
  3439. response = response.replace(new RegExp(preCode[0], "gi"), preCode[1]);
  3440. } else {
  3441. response = Function("response",'"use strict";' + preCode)(response);
  3442. }
  3443. }catch(e){
  3444. debug(e);
  3445. }
  3446. }
  3447. try {
  3448. doc=document.implementation.createHTMLDocument('');
  3449. doc.documentElement.innerHTML=response;
  3450. let base=doc.querySelector("base");
  3451. ruleParser.basePath=base?base.href:url;
  3452. }
  3453. catch (e) {
  3454. debug('parse error'+e.toString());
  3455. }
  3456. let pageElement=ruleParser.getPageElement(doc);
  3457. if(inCors && (!pageElement || pageElement.length==0)){
  3458. ruleParser.curSiteRule.pageElement=allOfBody;
  3459. pageElement=ruleParser.getPageElement(doc);
  3460. ruleParser.getInsert(true);
  3461. }
  3462. //只有1的話怕不是圖片哦
  3463. if(pageElement && (pageElement.length>1 || (pageElement.length==1 && pageElement[0].tagName!="IMG") )){
  3464. ruleParser.insertPage(doc, pageElement, url, callback, false);
  3465. if(ruleParser.curSiteRule.action==1){
  3466. requestFromIframe(url, (doc, eles)=>{
  3467. loadPageOver();
  3468. if(eles){
  3469. ruleParser.insertPage(doc, eles, url, callback, true);
  3470. }
  3471. });
  3472. }else ruleParser.curSiteRule.action=0;
  3473. }else if(ruleParser.curSiteRule.singleUrl || curPage==1){
  3474. ruleParser.curSiteRule.action=1;
  3475. requestFromIframe(url, (doc, eles)=>{
  3476. loadPageOver();
  3477. if(eles){
  3478. ruleParser.insertPage(doc, eles, url, callback, true);
  3479. }
  3480. });
  3481. }else{
  3482. isPause=true;
  3483. callback(false);
  3484. }
  3485. },
  3486. onerror: function(e){
  3487. debug(e);
  3488. callback(false);
  3489. },
  3490. ontimeout: function(e){
  3491. debug(e);
  3492. callback(false);
  3493. }
  3494. });
  3495. }
  3496.  
  3497. function initPage(){
  3498. ruleParser.initPage(()=>{
  3499. if(ruleParser.curSiteRule.autoLoadNum){
  3500. autoLoadNum=ruleParser.curSiteRule.autoLoadNum;
  3501. }
  3502. if(ruleParser.curSiteRule.nextLink && Array && Array.isArray && Array.isArray(ruleParser.curSiteRule.nextLink)){
  3503. _GM_registerMenuCommand(i18n("nextSwitch"), ()=>{
  3504. NextSwitch.getInstance().start();
  3505. });
  3506. }
  3507. if(ruleParser.nextLinkHref){
  3508. let isJs=/^(javascript|#)/.test(ruleParser.nextLinkHref.replace(location.href,""));
  3509. if(!isJs){
  3510. let inForce=(forceState == 2 || forceState == 3);
  3511. _GM_registerMenuCommand(i18n(inForce?"cancelForceIframe":"forceIframe"), ()=>{
  3512. if(inForce){
  3513. storage.setItem("forceState_"+location.host, "");
  3514. }else{
  3515. let _state=ruleParser.curSiteRule.action>0 || confirm(i18n("forceAllBody"))?2:3;
  3516. storage.setItem("forceState_"+location.host, _state);
  3517. }
  3518. location.reload();
  3519. });
  3520. }
  3521. _GM_registerMenuCommand(i18n("loadNow"), ()=>{
  3522. let loadNum=window.prompt(i18n("loadConfirm"), "1");
  3523. if(loadNum==="" || loadNum===null)return;
  3524. autoLoadNum=Math.abs(parseInt(loadNum));
  3525. nextPage();
  3526. });
  3527. }
  3528. initListener();
  3529. if(rulesData.initRun && ruleParser.curSiteRule.initRun!=0)nextPage();
  3530. });
  3531. }
  3532.  
  3533. var pageBarStyle;
  3534. function initView(){
  3535. _GM_addStyle(`
  3536. .pagetual_pageBar{
  3537. -moz-transition:opacity 0.3s ease-in-out 0s;
  3538. -webkit-transition:opacity 0.3s ease-in-out 0s;
  3539. transition:opacity 0.3s ease-in-out 0s;
  3540. font-family: Arial,sans-serif !important;
  3541. }
  3542. .pagetual_pageBar.stop {
  3543. -webkit-filter: invert(100%);
  3544. filter: invert(100%);
  3545. opacity: 1!important;
  3546. }
  3547. .pagetual_pageBar.hide {
  3548. display: none!important;
  3549. }
  3550. .pagetual_pageBar:hover {
  3551. opacity: 1!important;
  3552. }
  3553. .pagetual_pageBar span {
  3554. vertical-align: super;
  3555. }
  3556. .pagetual_pageBar a>span {
  3557. margin-top: 0!important;
  3558. opacity: 0;
  3559. -moz-transition:all 0.3s ease-in-out 0s;
  3560. -webkit-transition:all 0.3s ease-in-out 0s;
  3561. transition:all 0.3s ease-in-out 0s;
  3562. }
  3563. .pagetual_pageBar a>span:hover {
  3564. color: red;
  3565. }
  3566. .pagetual_pageBar a:hover>span {
  3567. opacity: 1;
  3568. }
  3569. .pagetual_pageBar a:hover>span.prev {
  3570. margin-top: -30px!important;
  3571. }
  3572. .pagetual_pageBar a:hover>span.next {
  3573. margin-top: 30px!important;
  3574. }
  3575. .pagetual_pageBar span>svg {
  3576. -moz-transition:transform 0.5s ease, opacity 0.3s ease;
  3577. -webkit-transition:transform 0.5s ease, opacity 0.3s ease;
  3578. transition:transform 0.5 ease, opacity 0.3s ease;
  3579. opacity: 0;
  3580. }
  3581. .pagetual_pageBar:hover span>svg {
  3582. opacity: 1;
  3583. }
  3584. .pagetual_pageBar span>svg.upSvg:hover {
  3585. transform: rotate(360deg) scale3d(1.2, 1.2, 1.2);
  3586. }
  3587. .pagetual_pageBar span>svg.downSvg:hover {
  3588. transform: rotate(540deg) scale3d(1.2, 1.2, 1.2)!important;
  3589. }
  3590. .pagetual_pageBar .pagetual_pageNum{
  3591. color: #55555f;
  3592. }
  3593. .pagetual_pageBar .pagetual_pageNum:hover{
  3594. color: #ff6464;
  3595. }
  3596. .pagetual_tipsWords{
  3597. font-size: 50px;
  3598. font-weight: bold;
  3599. font-family: "黑体", -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto",
  3600. "Oxygen", "Ubuntu", "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji",
  3601. "Segoe UI Emoji", "Segoe UI Symbol";
  3602. color: #ffffff;
  3603. min-height: 70px;
  3604. line-height: 70px;
  3605. position: fixed;
  3606. left: 50%;
  3607. top: 10%;
  3608. margin-left: -150px;
  3609. padding: 0 10px;
  3610. z-index: 999999999;
  3611. background-color: #000;
  3612. border: 1px solid black;
  3613. border-radius: 10px;
  3614. opacity: 0;
  3615. filter: alpha(opacity=65);
  3616. box-shadow: 5px 5px 20px 0px #000;
  3617. -moz-transition:opacity 0.3s ease-in-out 0s;
  3618. -webkit-transition:opacity 0.3s ease-in-out 0s;
  3619. transition:opacity 0.3s ease-in-out 0s;
  3620. pointer-events: none;
  3621. }
  3622. .pagetual_loading {
  3623. width: 50px;
  3624. height: 50px;
  3625. margin: 10px auto;
  3626. border-radius: 100%;
  3627. -webkit-animation: pagetual_loading_scaleout 1.0s infinite ease-in-out;
  3628. animation: pagetual_loading_scaleout 1.0s infinite ease-in-out;
  3629. }
  3630. @-webkit-keyframes pagetual_loading_scaleout {
  3631. 0% { -webkit-transform: scale(0.0) }
  3632. 100% {
  3633. -webkit-transform: scale(1.0);
  3634. opacity: 0;
  3635. }
  3636. }
  3637. @keyframes pagetual_loading_scaleout {
  3638. 0% {
  3639. transform: scale(0.0);
  3640. -webkit-transform: scale(0.0);
  3641. } 100% {
  3642. transform: scale(1.0);
  3643. -webkit-transform: scale(1.0);
  3644. opacity: 0;
  3645. }
  3646. }
  3647. .pagetual_loading_text {
  3648. -webkit-animation: pagetual_loading_opacity 2.6s infinite ease-in-out;
  3649. animation: pagetual_loading_opacity 2.6s infinite ease-in-out;
  3650. }
  3651. @-webkit-keyframes pagetual_loading_opacity {
  3652. 0% { opacity: 1 }
  3653. 50% { opacity: 0.2 }
  3654. 100% { opacity: 1 }
  3655. }
  3656. @keyframes pagetual_loading_opacity {
  3657. 0% { opacity: 1 }
  3658. 50% { opacity: 0.2 }
  3659. 100% { opacity: 1 }
  3660. }
  3661. `);
  3662. pageBarStyle=`line-height:1;opacity:${rulesData.opacity};display:${rulesData.opacity==0?"none":"block"};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: initial; width: auto; height: 30px; float: none; clear: both; margin: 5px auto; text-align: center;`;
  3663. }
  3664. var loadingDiv=document.createElement("div");
  3665. loadingDiv.style.cssText="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;";
  3666.  
  3667. 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;`;
  3668. function setLoadingDiv(loadingText){
  3669. loadingDiv.innerHTML=`<p class="pagetual_loading_text" style="${loadingCSS}">${loadingText}</p><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" p-id="6364"><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" p-id="6365"></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" p-id="6366"></path></svg></div>`;
  3670. }
  3671.  
  3672. var upSvg=`<svg width="30" height="30" class="upSvg" style="display:initial;position:absolute;cursor: pointer;margin: 0 -45px;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" p-id="6364"><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" p-id="6365"></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" p-id="6366"></path></svg>`;
  3673. var upSvgCSS=`display:initial;position:absolute;cursor: pointer;margin: 0 -45px;width: 30px;height: 30px;vertical-align: middle;fill: currentColor;overflow: hidden;`;
  3674. var downSvg=`<svg width="30" height="30" class="downSvg" style="display:initial;position:absolute;cursor: pointer;margin: 0 15px;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" p-id="6364"><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" p-id="6365"></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" p-id="6366"></path></svg>`;
  3675. var downSvgCSS=`display:initial;position:absolute;cursor: pointer;margin: 0 15px;width: 30px;height: 30px;vertical-align: middle;fill: currentColor;overflow: hidden;transform: rotate(180deg);`;
  3676.  
  3677. const initStyle=`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 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;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;`;
  3678. const pageTextStyle=`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 auto;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;`;
  3679.  
  3680. var tipsWords=document.createElement("div");
  3681. tipsWords.className="pagetual_tipsWords";
  3682.  
  3683. var isPause=false,isLoading=false,curPage=1,forceState=0,bottomGap=1000,autoLoadNum=-1,nextIndex=0;
  3684.  
  3685. function changeStop(stop, hide){
  3686. isPause=stop;
  3687. [].forEach.call(document.querySelectorAll(".pagetual_pageBar"), bar=>{
  3688. if(isPause){
  3689. bar.classList.add("stop");
  3690. if(hide)bar.classList.add("hide");
  3691. }else{
  3692. bar.classList.remove("stop");
  3693. if(hide)bar.classList.remove("hide");
  3694. }
  3695. });
  3696. }
  3697.  
  3698. function isInViewPort(element) {
  3699. if(!document.body.contains(element))return false;
  3700. if(_unsafeWindow.getComputedStyle(element).display=="none")return false;
  3701. const viewWidth = window.innerWidth || document.documentElement.clientWidth;
  3702. const viewHeight = window.innerHeight || document.documentElement.clientHeight;
  3703. const {
  3704. top,
  3705. right,
  3706. bottom,
  3707. left,
  3708. } = element.getBoundingClientRect();
  3709.  
  3710. return (
  3711. top >= 0 &&
  3712. left >= 0 &&
  3713. right <= viewWidth + 1 &&
  3714. bottom <= viewHeight * 2
  3715. );
  3716. }
  3717.  
  3718. var urlChanged=false;
  3719. var _wr = function(type) {
  3720. var orig = history[type];
  3721. return function() {
  3722. var rv = orig.apply(this, arguments);
  3723. var e = new Event(type);
  3724. e.arguments = arguments;
  3725. window.dispatchEvent(e);
  3726. return rv;
  3727. };
  3728. };
  3729. history.pushState = _wr('pushState');
  3730. window.addEventListener('pushState', function(e) {
  3731. urlChanged=true;
  3732. isPause=true;
  3733. setTimeout(()=>{
  3734. if(location.href==configPage || guidePage.test(location.href)){
  3735. location.reload();
  3736. }else if(!ruleParser.ruleMatch(ruleParser.curSiteRule)){
  3737. initPage();
  3738. }
  3739. },1);
  3740. });
  3741.  
  3742. function initListener(){
  3743. let loadmoreBtn,loading=true,lastScroll=0,checkLoadMoreTimes=0;
  3744. let checkLoadMore=setInterval(()=>{
  3745. loadmoreBtn=getLoadMore(document);
  3746. if(loadmoreBtn && isVisible(loadmoreBtn, _unsafeWindow)){
  3747. loading=false;
  3748. clearInterval(checkLoadMore);
  3749. }else if(checkLoadMoreTimes++>30){
  3750. clearInterval(checkLoadMore);
  3751. }
  3752. },300);
  3753. let checkScrollReach=()=>{
  3754. let scrolly=window.scrollY;
  3755. let windowHeight=window.innerHeight || document.documentElement.clientHeight;
  3756. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  3757. if(scrollH-scrolly-windowHeight<bottomGap){
  3758. nextPage();
  3759. }
  3760. };
  3761. let scrollHandler = e=>{
  3762. if(urlChanged){
  3763. ruleParser.initPage(()=>{
  3764. if(ruleParser.nextLinkHref)initView();
  3765. });
  3766. urlChanged=false;
  3767. isPause=false;
  3768. }
  3769. if(isPause)return;
  3770. if(!loading){
  3771. if(!loadmoreBtn || !document.body.contains(loadmoreBtn)){
  3772. loadmoreBtn=getLoadMore(document);
  3773. }
  3774. if(loadmoreBtn){
  3775. if(isInViewPort(loadmoreBtn)){
  3776. emuClick(loadmoreBtn);
  3777. loading=true;
  3778. setTimeout(()=>{loading=false},200);
  3779. }
  3780. }else{
  3781. loading=true;
  3782. setTimeout(()=>{loading=false},200);
  3783. }
  3784. }
  3785. if(!isLoading){
  3786. checkScrollReach();
  3787. }
  3788. if(ruleParser.curSiteRule.lockScroll){
  3789. let curScroll=document.body.scrollTop||document.documentElement.scrollTop;
  3790. if(isLoading && Math.abs(lastScroll-curScroll)>350){
  3791. document.body.scrollTop=lastScroll;
  3792. document.documentElement.scrollTop=lastScroll;
  3793. }else{
  3794. lastScroll=curScroll;
  3795. }
  3796. }
  3797. };
  3798. document.addEventListener('dblclick', e=>{
  3799. if(forceState==1 || e.target.tagName=='INPUT' || e.target.tagName=='TEXTAREA') return;
  3800. if(!rulesData.dbClick2StopKey){
  3801. if((rulesData.dbClick2StopCtrl && !e.ctrlKey) ||
  3802. (rulesData.dbClick2StopAlt && !e.altKey) ||
  3803. (rulesData.dbClick2StopShift && !e.shiftKey) ||
  3804. (rulesData.dbClick2StopMeta && !e.metaKey)){
  3805. return;
  3806. }
  3807. }
  3808. if(e.target.tagName!="BODY"){
  3809. let selStr=document.getSelection().toString();
  3810. if(selStr && selStr.trim()){
  3811. return;
  3812. }
  3813. }
  3814. if(rulesData.dbClick2Stop && (ruleParser.nextLinkHref || loadmoreBtn)){
  3815. setTimeout(()=>{
  3816. changeStop(!isPause, rulesData.hideBar);
  3817. if(!isPause){
  3818. checkScrollReach();
  3819. }
  3820. showTips(i18n(isPause?"disable":"enable"));
  3821. },10);
  3822. }
  3823. });
  3824. if(rulesData.dbClick2StopKey){
  3825. document.addEventListener('keydown', e=>{
  3826. if((rulesData.dbClick2StopCtrl && !e.ctrlKey) ||
  3827. (rulesData.dbClick2StopAlt && !e.altKey) ||
  3828. (rulesData.dbClick2StopShift && !e.shiftKey) ||
  3829. (rulesData.dbClick2StopMeta && !e.metaKey)){
  3830. return;
  3831. }
  3832. if (document.activeElement &&
  3833. (document.activeElement.tagName == 'INPUT' ||
  3834. document.activeElement.tagName == 'TEXTAREA')) {
  3835. return;
  3836. }
  3837. var key = String.fromCharCode(e.keyCode).toLowerCase();
  3838. if(rulesData.dbClick2StopKey.toLowerCase()==key){
  3839. forceState=(forceState==1?0:1);
  3840. showTips(i18n(forceState==1?"disableSiteTips":"enableSiteTips"));
  3841. if(!ruleParser.curSiteRule.url) {
  3842. storage.setItem("forceState_"+location.host, forceState);
  3843. location.reload();
  3844. }
  3845. }
  3846. });
  3847. }
  3848. let clickNext=() => {
  3849. let nextLink=ruleParser.nextLinkHref;
  3850. if(!nextLink)return;
  3851. let isJs=/^(javascript|#)/.test(nextLink.replace(location.href,""));
  3852. if(isJs){
  3853. let nextBtn=ruleParser.getNextLink(document);
  3854. if(nextBtn)emuClick(nextBtn);
  3855. }else{
  3856. window.location.href = nextLink;
  3857. }
  3858. };
  3859. let manualMode = typeof ruleParser.curSiteRule.manualMode == 'undefined' ? rulesData.manualMode : ruleParser.curSiteRule.manualMode;
  3860. if (manualMode) {
  3861. document.addEventListener('keydown', e => {
  3862. if (document.activeElement &&
  3863. (document.activeElement.tagName == 'INPUT' ||
  3864. document.activeElement.tagName == 'TEXTAREA' ||
  3865. document.activeElement.contentEditable == 'true')) {
  3866. return;
  3867. }
  3868. if(e.keyCode == 39){
  3869. clickNext();
  3870. }
  3871. });
  3872. document.addEventListener('pagetual.next', function() {
  3873. clickNext();
  3874. }, false);
  3875. return;
  3876. }
  3877. if (rulesData.arrowToScroll) {
  3878. let getPageBar = () => {
  3879. let preBar = null, nextBar = null;
  3880. let pageBars = [].slice.call(document.querySelectorAll(".pagetual_pageBar"));
  3881. for (let i = 0; i < pageBars.length; i++) {
  3882. let pageBar = pageBars[i];
  3883. if (!pageBar || !document.body.contains(pageBar)) continue;
  3884. let {
  3885. top,
  3886. right,
  3887. bottom,
  3888. left,
  3889. } = pageBar.getBoundingClientRect();
  3890. if (top > 500) {
  3891. nextBar = pageBar;
  3892. preBar = (i - 1 >= 0 ? pageBars[i - 1] : null);
  3893. if (pageBar && document.body.contains(pageBar)) {
  3894. let {
  3895. top,
  3896. right,
  3897. bottom,
  3898. left,
  3899. } = pageBar.getBoundingClientRect();
  3900. if (top < -500) {
  3901. preBar = pageBar;
  3902. } else preBar = (i - 2 >= 0 ? pageBars[i - 2] : null);
  3903. }
  3904. break;
  3905. }
  3906. }
  3907. if (!nextBar) preBar = pageBars[pageBars.length - 2];
  3908. return {preBar: preBar, nextBar: nextBar};
  3909. };
  3910. document.addEventListener('keyup', e => {
  3911. if (document.activeElement &&
  3912. (document.activeElement.tagName == 'INPUT' ||
  3913. document.activeElement.tagName == 'TEXTAREA' ||
  3914. document.activeElement.contentEditable == 'true')) {
  3915. return;
  3916. }
  3917. if (e.keyCode == 39) {
  3918. let nextPageBar=getPageBar().nextBar;
  3919. if (nextPageBar) {
  3920. scrollToPageBar(nextPageBar);
  3921. } else {
  3922. let scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
  3923. window.scrollTo({ top: scrollTop + (window.innerHeight || document.documentElement.clientHeight), behavior: 'smooth'});
  3924. }
  3925. } else if (e.keyCode == 37) {
  3926. let prePageBar = getPageBar().preBar;
  3927. if (prePageBar) {
  3928. scrollToPageBar(prePageBar);
  3929. } else {
  3930. let scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
  3931. window.scrollTo({ top: scrollTop - (window.innerHeight || document.documentElement.clientHeight), behavior: 'smooth'});
  3932. }
  3933. }
  3934. });
  3935. }
  3936. if (!ruleParser.curSiteRule.wheel) {
  3937. document.addEventListener('scroll', scrollHandler, true);
  3938. }
  3939. document.addEventListener('wheel', scrollHandler, true);
  3940. }
  3941.  
  3942. function showTips(content, wordColor, backColor){
  3943. document.body.appendChild(tipsWords);
  3944. tipsWords.style.opacity=0.8;
  3945. tipsWords.innerText=content;
  3946. tipsWords.style.marginLeft=-tipsWords.offsetWidth/2+"px";
  3947. tipsWords.style.color=wordColor||0xFFFFFF;
  3948. tipsWords.style.backgroundColor=backColor||0x000;
  3949. setTimeout(()=>{tipsWords.style.opacity=0},1000);
  3950. }
  3951.  
  3952. function getLoadMore(doc){
  3953. if(ruleParser.curSiteRule.loadMore==="")return null;
  3954. let btnSel=ruleParser.curSiteRule.loadMore||".LoadMore,.load-more,.button-show-more,button[data-testid='more-results-button']",loadmoreBtn;
  3955. if(btnSel){
  3956. loadmoreBtn=getElement(btnSel, doc);
  3957. }
  3958. if(!loadmoreBtn){
  3959. let buttons=doc.querySelectorAll("input,button,a,div[onclick]"),loadmoreReg=/^\s*(加载更多|加載更多|load\s*more|もっと読み込む)\s*$/i;
  3960. for(let i=0;i<buttons.length;i++){
  3961. let button=buttons[i];
  3962. if(button.innerText.length > 20)continue;
  3963. if(button && loadmoreReg.test(button.innerText)){
  3964. loadmoreBtn=button;
  3965. break;
  3966. }
  3967. }
  3968. }
  3969. if (loadmoreBtn && !ruleParser.curSiteRule.loadMore && loadmoreBtn.dataset.ajax !== "true") {
  3970. let href = loadmoreBtn.getAttribute("href");
  3971. if (href && href != "/" && !/^(javascript|#)/.test(href.replace(location.href,""))) {
  3972. loadmoreBtn = null;
  3973. }
  3974. }
  3975. return loadmoreBtn;
  3976. }
  3977.  
  3978. function scrollToPageBar(bar){
  3979. let yOffset = -20;
  3980. if (typeof ruleParser.curSiteRule.pageBarTop !== 'undefined') {
  3981. yOffset = -ruleParser.curSiteRule.pageBarTop;
  3982. }
  3983. const y = bar.getBoundingClientRect().top + window.pageYOffset + yOffset;
  3984. window.scrollTo({ top: y, behavior: 'smooth'});
  3985. }
  3986.  
  3987. const pageNumReg=/[&\/\?](p=|page[=\/_-]?)\d+|[_-]\d+\./;
  3988. function createPageBar(url){
  3989. let insert=ruleParser.getInsert();
  3990. if(!insert || !insert.parentNode)return;
  3991. curPage++;
  3992. let example=ruleParser.curSiteRule.insertPos==2?insert.children[0]:(insert.parentNode.children[parseInt(insert.parentNode.children.length/2)]||insert);
  3993. if (example.className=="pagetual_pageBar") {
  3994. example=example.previousElementSibling;
  3995. }
  3996. if(!example || !example.parentNode)example=insert;
  3997. let exampleStyle = _unsafeWindow.getComputedStyle(example);
  3998. let inTable=example.parentNode.tagName=="TABLE" ||
  3999. example.tagName=="TR" ||
  4000. example.tagName=="TBODY" ||
  4001. exampleStyle.display=="table-row" ||
  4002. (example.previousElementSibling && example.previousElementSibling.tagName=="TR") ||
  4003. (example.previousElementSibling && example.previousElementSibling.tagName=="TBODY");
  4004. let inLi=example.tagName=="LI" || (example.previousElementSibling && example.previousElementSibling.tagName=="LI");
  4005. if(forceState==2){
  4006. inTable=inLi=false;
  4007. }
  4008. let pageBar=document.createElement(inTable?"tr":(inLi?"li":"div"));
  4009. let upSpan=document.createElement("span");
  4010. let downSpan=document.createElement("span");
  4011. let pageText=document.createElement("a");
  4012. let pageNum;
  4013. pageBar.className="pagetual_pageBar";
  4014. pageBar.id="pagetual_pageBar"+curPage;
  4015. pageBar.setAttribute("translate", "no");
  4016. if(isPause){
  4017. pageBar.classList.add("stop");
  4018. }
  4019. pageBar.style.cssText=pageBarStyle;
  4020. pageBar.title=i18n(isPause?"enable":"disable");
  4021. upSpan.innerHTML=upSvg;
  4022. upSpan.children[0].style.cssText=upSvgCSS;
  4023. upSpan.title=i18n("toTop");
  4024. downSpan.innerHTML=downSvg;
  4025. downSpan.children[0].style.cssText=downSvgCSS;
  4026. downSpan.title=i18n("toBottom");
  4027. upSpan.style.cssText=initStyle;
  4028. downSpan.style.cssText=initStyle;
  4029. pageText.href=url;
  4030. pageText.style.cssText=pageTextStyle;
  4031. pageText.title=i18n("current");
  4032. pageBar.appendChild(upSpan);
  4033. pageBar.appendChild(pageText);
  4034. if(ruleParser.nextTitle){
  4035. pageText.innerHTML=ruleParser.nextTitle+" ";
  4036. pageText.title=ruleParser.nextTitle;
  4037. }
  4038. if(ruleParser.curSiteRule.pageNum || pageNumReg.test(url)){
  4039. pageText.innerHTML+="Page ";
  4040. pageNum=document.createElement("span");
  4041. pageNum.innerHTML=ruleParser.getPageNumFromUrl(url);
  4042. pageNum.className="pagetual_pageNum";
  4043. pageNum.title=i18n("inputPageNum");
  4044. pageNum.style.cssText=pageTextStyle;
  4045. pageNum.style.cursor="pointer";
  4046. pageNum.style.color="";
  4047. pageNum.style.marginLeft="5px";
  4048. pageNum.addEventListener("click", e=>{
  4049. let pageInput=prompt(i18n("inputPageNum"), "1");
  4050. if(pageInput){
  4051. let pageLink=ruleParser.getLinkByPage(url, pageInput);
  4052. if(pageLink){
  4053. _GM_openInTab(pageLink,{active:true});
  4054. }
  4055. }
  4056. e.preventDefault();
  4057. e.stopPropagation();
  4058. });
  4059. pageBar.appendChild(pageNum);
  4060. }else{
  4061. pageText.innerHTML+="Page "+curPage;
  4062. }
  4063. let preBtn=document.createElement("span");
  4064. preBtn.innerHTML="∧";
  4065. preBtn.title="Prev page";
  4066. preBtn.className="prev";
  4067. preBtn.style.cssText="text-align: center;right: unset; float: left; margin-top: -30px; width: 40px; background: rgba(240, 240, 240, 0.8); position: absolute; border-radius: 20px 20px 0 0; box-shadow: rgb(0 0 0 / 50%) 0px -5px 5px;z-index:9999999";
  4068. let nextBtn=document.createElement("span");
  4069. nextBtn.innerHTML="∨";
  4070. nextBtn.title="Next page";
  4071. nextBtn.className="next";
  4072. nextBtn.style.cssText="text-align: center;right: unset; float: left; margin-top: 30px; width: 40px; background: rgba(240, 240, 240, 0.8); position: absolute; border-radius: 0 0 20px 20px; box-shadow: rgb(0 0 0 / 50%) 0px 5px 5px;z-index:9999999";
  4073. let localPage=curPage;
  4074. preBtn.addEventListener("click", e=>{
  4075. e.stopPropagation();
  4076. e.preventDefault();
  4077. let prePageBar = document.querySelector("#pagetual_pageBar"+(localPage-1));
  4078. if (prePageBar) {
  4079. scrollToPageBar(prePageBar);
  4080. } else {
  4081. let scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
  4082. window.scrollTo({ top: scrollTop - (window.innerHeight || document.documentElement.clientHeight), behavior: 'smooth'});
  4083. }
  4084. });
  4085. nextBtn.addEventListener("click", e=>{
  4086. e.stopPropagation();
  4087. e.preventDefault();
  4088. let nextPageBar=document.querySelector("#pagetual_pageBar"+(localPage+1));
  4089. if (nextPageBar) {
  4090. scrollToPageBar(nextPageBar);
  4091. } else {
  4092. let scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
  4093. window.scrollTo({ top: scrollTop + (window.innerHeight || document.documentElement.clientHeight), behavior: 'smooth'});
  4094. }
  4095. });
  4096. pageText.insertBefore(preBtn, pageText.firstChild);
  4097. pageText.insertBefore(nextBtn, pageText.firstChild);
  4098. pageBar.appendChild(downSpan);
  4099. let parentStyle=_unsafeWindow.getComputedStyle(example.parentNode);
  4100. let parentWidth=example.parentNode.offsetWidth||parseInt(parentStyle.width);
  4101. pageBar.style.width=parentWidth-parseInt(parentStyle.paddingLeft)-parseInt(parentStyle.paddingRight)-10+"px";
  4102. if(parentStyle.display=="grid" || parentStyle.display=="inline-grid"){
  4103. pageBar.style.gridColumnStart=1;
  4104. pageBar.style.gridColumnEnd=1+parseInt(example.parentNode.offsetWidth/example.offsetWidth);
  4105. }
  4106. if(inTable){
  4107. example=(example.tagName=="TR" || example.tagName=="TBODY")?example:example.previousElementSibling;
  4108. if(example.tagName=="TBODY")example=example.querySelector("tr");
  4109. let preTr=example;
  4110. while(preTr && preTr.children.length==0)preTr=preTr.previousElementSibling;
  4111. if(preTr)example=preTr;
  4112. let tdNum=0;
  4113. if (exampleStyle.display=="table-row") {
  4114. [].forEach.call(example.children, el=>{
  4115. tdNum+=el.colSpan||1;
  4116. });
  4117. } else {
  4118. [].forEach.call(example.children, el=>{
  4119. if(el.tagName=="TD" || el.tagName=="TH"){
  4120. tdNum+=el.colSpan||1;
  4121. }
  4122. });
  4123. }
  4124. pageBar.style.display="table-row";
  4125. pageBar.style.backgroundColor="unset";
  4126. pageBar.style.lineHeight="20px";
  4127. pageBar.style.boxShadow="";
  4128. let td=document.createElement("td");
  4129. td.colSpan=tdNum||1;
  4130. let inTd=document.createElement("div");
  4131. inTd.style.backgroundColor="rgb(240 240 240 / 80%)";
  4132. inTd.style.borderRadius="20px";
  4133. inTd.style.padding="0 0";
  4134. inTd.style.margin="10px";
  4135. inTd.style.lineHeight="20px";
  4136. inTd.style.textAlign="center";
  4137. inTd.style.boxShadow="rgb(0 0 0 / 67%) 0px 0px 10px 0px";
  4138. inTd.appendChild(upSpan);
  4139. inTd.appendChild(pageText);
  4140. if(pageNum)inTd.appendChild(pageNum);
  4141. inTd.appendChild(downSpan);
  4142. td.appendChild(inTd);
  4143. pageBar.appendChild(td);
  4144. }else if(inLi){
  4145. example=example.tagName=="LI"?example:example.previousElementSibling;
  4146. pageBar.style.display="table-row";
  4147. pageBar.style.backgroundColor="unset";
  4148. pageBar.style.lineHeight="20px";
  4149. pageBar.style.boxShadow="";
  4150. let td=document.createElement("td");
  4151. td.colSpan=example.children.length;
  4152. let inTd=document.createElement("div");
  4153. inTd.style.backgroundColor="rgb(240 240 240 / 80%)";
  4154. inTd.style.borderRadius="20px";
  4155. inTd.style.margin="10px"
  4156. inTd.style.padding="0 0";
  4157. inTd.style.textAlign="center";
  4158. inTd.style.minWidth="150px";
  4159. inTd.appendChild(upSpan);
  4160. inTd.appendChild(pageText);
  4161. inTd.style.width=parseInt(pageBar.style.width)-20+"px";
  4162. inTd.style.boxShadow="rgb(0 0 0 / 67%) 0px 0px 10px 0px";
  4163. if(pageNum)inTd.appendChild(pageNum);
  4164. inTd.appendChild(downSpan);
  4165. td.appendChild(inTd);
  4166. pageBar.appendChild(td);
  4167. }
  4168.  
  4169. upSpan.addEventListener("click", e=>{
  4170. document.body.scrollTop=0;
  4171. document.documentElement.scrollTop=0;
  4172. e.preventDefault();
  4173. e.stopPropagation();
  4174. });
  4175. downSpan.addEventListener("click", e=>{
  4176. changeStop(true);
  4177. pageBar.title=i18n(isPause?"enable":"disable");
  4178. document.body.scrollTop=9999999;
  4179. document.documentElement.scrollTop=9999999;
  4180. e.preventDefault();
  4181. e.stopPropagation();
  4182. });
  4183. pageBar.addEventListener("click", e=>{
  4184. changeStop(!isPause);
  4185. pageBar.title=i18n(isPause?"enable":"disable");
  4186. });
  4187. pageText.addEventListener("click", e=>{
  4188. e.stopPropagation();
  4189. if (e.ctrlKey || e.altKey || e.shiftKey || e.metaKey) return;
  4190. if (e.which == 1) {
  4191. e.preventDefault();
  4192. scrollToPageBar(pageBar);
  4193. }
  4194. });
  4195. ruleParser.insertElement(pageBar);
  4196. if(ruleParser.curSiteRule.pageBar && ruleParser.curSiteRule.pageBar !== 0){
  4197. try{
  4198. ((typeof _unsafeWindow.pagetualPageBar=='undefined') ? Function("pageBar",'"use strict";' + ruleParser.curSiteRule.pageBar) : _unsafeWindow.pagetualPageBar)(pageBar);
  4199. }catch(e){
  4200. debug(e);
  4201. }
  4202. }
  4203.  
  4204. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  4205. let posEle=pageBar.nextElementSibling||pageBar;
  4206. while(posEle && !posEle.offsetParent){
  4207. posEle=posEle.previousElementSibling||posEle.parentNode;
  4208. }
  4209. if(posEle){
  4210. let actualTop = getElementTop(posEle);
  4211. bottomGap=scrollH-actualTop+(window.innerHeight||document.documentElement.clientHeight)*(ruleParser.curSiteRule.rate||1);
  4212. if(bottomGap<100)bottomGap=100;
  4213. }else{
  4214. bottomGap=1000;
  4215. }
  4216. if(rulesData.opacity==0 || ruleParser.curSiteRule.pageBar === 0)pageBar.style.display="none";
  4217. return pageBar;
  4218. }
  4219.  
  4220. function emuClick(btn){
  4221. let orgHref=btn.getAttribute('href');
  4222. if(orgHref){
  4223. btn.setAttribute('href', orgHref.replace(/#$/,""));
  4224. }
  4225. if(!PointerEvent)return btn.click();
  4226. let eventParam={
  4227. isTrusted: true,
  4228. altKey: false,
  4229. azimuthAngle: 0,
  4230. bubbles: true,
  4231. button: 0,
  4232. buttons: 0,
  4233. clientX: 1,
  4234. clientY: 1,
  4235. cancelBubble: false,
  4236. cancelable: true,
  4237. composed: true,
  4238. ctrlKey: false,
  4239. defaultPrevented: false,
  4240. detail: 1,
  4241. eventPhase: 2,
  4242. fromElement: null,
  4243. height: 1,
  4244. isPrimary: false,
  4245. metaKey: false,
  4246. pointerId: 1,
  4247. pointerType: "mouse",
  4248. pressure: 0,
  4249. relatedTarget: null,
  4250. returnValue: true,
  4251. shiftKey: false,
  4252. toElement: null,
  4253. twist: 0,
  4254. which: 1
  4255. };
  4256. var mouseEvent = new PointerEvent("mousedown",eventParam);
  4257. btn.dispatchEvent(mouseEvent);
  4258. mouseEvent = new PointerEvent("mouseup",eventParam);
  4259. btn.dispatchEvent(mouseEvent);
  4260. btn.click();
  4261. if(orgHref){
  4262. setTimeout(()=>btn.setAttribute('href', orgHref),0);
  4263. }
  4264. }
  4265.  
  4266. var failFromIframe=0;
  4267. var inCors=false;
  4268. function requestFromIframe(url, callback){
  4269. url=url.replace(/#[^#]*/,"");
  4270. let orgPage,curPage;
  4271. let iframe = document.createElement('iframe');
  4272. iframe.name = 'pagetual-iframe';
  4273. iframe.width = '100%';
  4274. iframe.height = '0';
  4275. iframe.frameBorder = '0';
  4276. if(ruleParser.curSiteRule.sandbox!=false){
  4277. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  4278. }
  4279. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  4280. let waitTime=100,checkEval;
  4281. if(ruleParser.curSiteRule.waitElement){
  4282. checkEval = doc => {
  4283. return ruleParser.waitElement(doc);
  4284. };
  4285. }else if(ruleParser.curSiteRule.wait){
  4286. if(isNaN(ruleParser.curSiteRule.wait)){
  4287. try{
  4288. checkEval=(typeof _unsafeWindow.pagetualWait=='undefined') ? Function("doc",'"use strict";' + ruleParser.curSiteRule.wait) : _unsafeWindow.pagetualWait;
  4289. }catch(e){
  4290. debug(e);
  4291. }
  4292. }else{
  4293. waitTime=ruleParser.curSiteRule.wait;
  4294. }
  4295. }
  4296. let loadedHandler=e=>{
  4297. if(e.data != 'pagetual-iframe:DOMLoaded' && e.type != 'load')return;
  4298. window.removeEventListener('message', loadedHandler, false);
  4299. iframe.removeEventListener('load', loadedHandler, false);
  4300. let tryTimes=0;
  4301. function checkIframe(){
  4302. try{
  4303. let doc=iframe.contentDocument || iframe.contentWindow.document;
  4304. let base=doc.querySelector("base");
  4305. ruleParser.basePath=base?base.href:url;
  4306. let eles=ruleParser.getPageElement(doc, iframe.contentWindow);
  4307. if(checkEval && !checkEval(doc)){
  4308. setTimeout(()=>{
  4309. checkIframe();
  4310. },waitTime);
  4311. return;
  4312. }else if(eles && eles.length>0){
  4313. callback(doc, eles);
  4314. }else if(tryTimes++ < 100){
  4315. setTimeout(()=>{
  4316. checkIframe();
  4317. },waitTime);
  4318. return;
  4319. }else{
  4320. if(failFromIframe++ > 2){
  4321. failFromIframe=0;
  4322. debug("Stop as failFromIframe");
  4323. isPause=true;
  4324. callback(false, false);
  4325. }else{
  4326. callback(false, false);
  4327. }
  4328. }
  4329. }catch(e){
  4330. debug("Stop as cors");
  4331. inCors=true;
  4332. if (forceState === 3) {
  4333. isPause=true;
  4334. }
  4335. if(!ruleParser.curSiteRule.pageElement){
  4336. ruleParser.curSiteRule.pageElement=allOfBody;
  4337. ruleParser.getInsert(true);
  4338. }
  4339. ruleParser.curSiteRule.action=0;
  4340. ruleParser.nextLinkHref=url;
  4341. callback(false, false);
  4342. nextPage();
  4343. }
  4344. document.body.removeChild(iframe);
  4345. }
  4346. setTimeout(()=>{
  4347. checkIframe();
  4348. },waitTime);
  4349. };
  4350. window.addEventListener('message', loadedHandler, false);
  4351. iframe.addEventListener('load', loadedHandler, false);
  4352. iframe.src=url;
  4353. document.body.appendChild(iframe);
  4354. }
  4355.  
  4356. var emuIframe,lastActiveUrl;
  4357. function emuPage(callback){
  4358. let orgPage=null,orgContent=null,preContent=null,curPage,iframeDoc,times=0,loadmoreBtn,loadmoreEnd=false,waitTimes=10,changed=false;
  4359. function returnFalse(log){
  4360. debug(log);
  4361. isPause=true;
  4362. callback(false, false);
  4363. if(emuIframe && emuIframe.parentNode){
  4364. emuIframe.parentNode.removeChild(emuIframe);
  4365. emuIframe=null;
  4366. }
  4367. }
  4368. function checkPage(){
  4369. if(isPause)return;
  4370. try{
  4371. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  4372. }catch(e){
  4373. returnFalse("Stop as cors");
  4374. return;
  4375. }
  4376.  
  4377. let waitTime=200,checkEval;
  4378. if(ruleParser.curSiteRule.waitElement){
  4379. checkEval = doc => {
  4380. return ruleParser.waitElement(doc);
  4381. };
  4382. }else if(ruleParser.curSiteRule.wait){
  4383. if(isNaN(ruleParser.curSiteRule.wait)){
  4384. try{
  4385. checkEval=(typeof _unsafeWindow.pagetualWait=='undefined') ? Function("doc",'"use strict";' + ruleParser.curSiteRule.wait) : _unsafeWindow.pagetualWait;
  4386. }catch(e){
  4387. debug(e);
  4388. }
  4389. }else{
  4390. waitTime=ruleParser.curSiteRule.wait;
  4391. }
  4392. }
  4393.  
  4394. let pageEle, nextLink;
  4395. if(!orgPage){
  4396. if(!loadmoreEnd){
  4397. loadmoreBtn=getLoadMore(iframeDoc);
  4398. if(loadmoreBtn && isVisible(loadmoreBtn, iframeDoc.defaultView)){
  4399. emuClick(loadmoreBtn);
  4400. let intv=setInterval(()=>{
  4401. loadmoreBtn=getLoadMore(iframeDoc);
  4402. if(!loadmoreBtn || !document.body.contains(loadmoreBtn) || !isVisible(loadmoreBtn, iframeDoc.defaultView)){
  4403. clearInterval(intv);
  4404. loadmoreEnd=true;
  4405. setTimeout(()=>{
  4406. checkPage();
  4407. },500);
  4408. }else if(isInViewPort(loadmoreBtn)){
  4409. emuClick(loadmoreBtn);
  4410. }
  4411. },200);
  4412. return;
  4413. }else{
  4414. loadmoreEnd=true;
  4415. }
  4416. }
  4417. if(checkEval && !checkEval(iframeDoc)){
  4418. setTimeout(()=>{
  4419. checkPage();
  4420. },waitTime);
  4421. return;
  4422. }else {
  4423. nextLink=ruleParser.getNextLink(iframeDoc);
  4424. pageEle=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true);
  4425. if(!pageEle || pageEle.length==0 || !nextLink){
  4426. if(waitTimes-->0){
  4427. setTimeout(()=>{
  4428. checkPage();
  4429. },waitTime);
  4430. return;
  4431. }
  4432. }
  4433. }
  4434. orgPage=pageEle;
  4435. if(!orgPage || orgPage.length==0){
  4436. returnFalse("Stop as no page when emu");
  4437. return;
  4438. }
  4439. if(orgPage[0].tagName=="UL")orgPage=orgPage[0].children;
  4440. if(nextLink){
  4441. orgPage=orgPage[parseInt(orgPage.length/2)];
  4442. if(orgPage.tagName=="IMG" && orgPage.src){
  4443. orgContent=orgPage.src;
  4444. }else{
  4445. orgContent=orgPage.innerHTML;
  4446. }
  4447. preContent=orgContent;
  4448. if(!isVisible(nextLink, iframeDoc.defaultView)){
  4449. returnFalse("Stop as next hide when emu");
  4450. }else{
  4451. emuClick(nextLink);
  4452. setTimeout(()=>{
  4453. checkPage();
  4454. },500);
  4455. }
  4456. }else{
  4457. returnFalse("Stop as no next when emu");
  4458. }
  4459. return;
  4460. }
  4461. nextLink = nextLink || ruleParser.getNextLink(iframeDoc);
  4462. if(!nextLink){
  4463. if(waitTimes-->0){
  4464. setTimeout(()=>{
  4465. checkPage();
  4466. },waitTime);
  4467. return;
  4468. }
  4469. }
  4470. if(times++ > 100){
  4471. returnFalse("Stop as timeout when emu");
  4472. return;
  4473. }
  4474. let eles=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true),checkItem;
  4475. if(eles && eles.length>0){
  4476. checkItem=eles;
  4477. if(eles[0].tagName=="UL")checkItem=eles[0].children;
  4478. checkItem=checkItem[parseInt(checkItem.length/2)];
  4479. }
  4480. if(!checkItem || (checkEval && !checkEval(iframeDoc))){
  4481. setTimeout(()=>{
  4482. checkPage();
  4483. },waitTime);
  4484. }else{
  4485. let checkInner;
  4486. if(checkItem.tagName=="IMG" && checkItem.src){
  4487. checkInner=checkItem.src;
  4488. }else{
  4489. checkInner=checkItem.innerHTML;
  4490. }
  4491. if(orgPage!=checkItem || checkInner!=preContent){
  4492. changed=true;
  4493. orgPage=checkItem;
  4494. preContent=checkInner;
  4495. setTimeout(()=>{
  4496. checkPage();
  4497. },waitTime);
  4498. }else if(changed){
  4499. if (orgContent == preContent) {
  4500. returnFalse("Stop as same content");
  4501. } else {
  4502. callback(iframeDoc, eles);
  4503. }
  4504. }else{
  4505. setTimeout(()=>{
  4506. checkPage();
  4507. },waitTime);
  4508. }
  4509. }
  4510. }
  4511. if(!emuIframe){
  4512. let loaded=false;
  4513. emuIframe = document.createElement('iframe');
  4514. emuIframe.name = 'pagetual-iframe';
  4515. if(ruleParser.curSiteRule.sandbox!=false){
  4516. emuIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  4517. }
  4518. emuIframe.width = '100%';
  4519. emuIframe.height = '0';
  4520. emuIframe.frameBorder = '0';
  4521. emuIframe.style.cssText = 'position:fixed;left:0;top:50%;margin:0!important;padding:0!important;visibility:hidden!important;';
  4522. emuIframe.addEventListener("load", e=>{
  4523. setTimeout(()=>{
  4524. try{
  4525. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  4526. }catch(e){
  4527. returnFalse("Stop as cors");
  4528. return;
  4529. }
  4530. let code=ruleParser.curSiteRule.init;
  4531. if(code){
  4532. try{
  4533. Function('doc','win','iframe','"use strict";' + code)(iframeDoc, iframeDoc.defaultView, emuIframe);
  4534. }catch(e){
  4535. debug(e);
  4536. }
  4537. }
  4538. if(loaded)return;
  4539. loaded=true;
  4540. checkPage();
  4541. },500);
  4542. });
  4543. if (!lastActiveUrl) lastActiveUrl=location.href;
  4544. emuIframe.src=lastActiveUrl.replace(/#[^#]*/,"");
  4545. document.body.appendChild(emuIframe);
  4546. }else{
  4547. checkPage();
  4548. }
  4549. }
  4550.  
  4551. var scrollToResizeInited = false;
  4552. var resizePool = [];
  4553. var scrollingToResize = false;
  4554.  
  4555. function scrollToResize(e) {
  4556. if (scrollingToResize) return;
  4557. else {
  4558. scrollingToResize = true;
  4559. let fitWidth = ruleParser.curSiteRule.fitWidth !== false;
  4560. let resizeHandler = () => {
  4561. resizePool.forEach(resizeArr => {
  4562. let iframe = resizeArr[1]();
  4563. let frameDoc = resizeArr[2]();
  4564. if(ruleParser.curSiteRule.singleUrl){
  4565. iframe.style.height=frameDoc.body.scrollHeight+"px";
  4566. iframe.style.width=frameDoc.body.scrollWidth+"px";
  4567. }else{
  4568. let pageEle = resizeArr[0]();
  4569. if(pageEle){
  4570. let targetElement = pageEle[0];
  4571. if(pageEle.length > 1){
  4572. targetElement = targetElement.parentNode;
  4573. }
  4574. if(parseInt(iframe.style.height)==targetElement.scrollHeight) return;
  4575. iframe.style.height=targetElement.scrollHeight+"px";
  4576. frameDoc.documentElement.scrollTop = 0;
  4577. frameDoc.documentElement.scrollLeft = 0;
  4578. while(targetElement && targetElement.offsetParent){
  4579. targetElement.offsetParent.scrollTop = targetElement.offsetTop;
  4580. if(targetElement.offsetParent.scrollTop == 0){
  4581. frameDoc.documentElement.scrollTop += targetElement.offsetTop;
  4582. }
  4583. if(fitWidth){
  4584. targetElement.offsetParent.scrollLeft = targetElement.offsetLeft;
  4585. if(targetElement.offsetParent.scrollLeft == 0){
  4586. frameDoc.documentElement.scrollLeft += targetElement.offsetLeft;
  4587. }
  4588. }
  4589. targetElement = targetElement.offsetParent;
  4590. }
  4591. if(!fitWidth && iframe.style.marginLeft == '0px'){
  4592. iframe.style.width = "100vw";
  4593. iframe.style.marginLeft = -iframe.getBoundingClientRect().left + "px";
  4594. }
  4595. }
  4596. }
  4597. });
  4598. };
  4599. setTimeout(() => {
  4600. resizeHandler();
  4601. scrollingToResize = false
  4602. }, 200);
  4603. resizeHandler();
  4604. }
  4605. }
  4606.  
  4607. function forceIframe(url, callback){
  4608. url=url.replace(/#[^#]*/,"");
  4609. let curIframe = document.createElement('iframe'),iframeDoc,isloaded=false,inAction=true;
  4610. let loadedHandler = ()=>{
  4611. inAction=false;
  4612. if(isloaded)return;
  4613. isloaded=true;
  4614. ruleParser.insertPage(iframeDoc, [], url, null, true);
  4615. callback(curIframe, true);
  4616. let getIframe = () => {
  4617. return curIframe;
  4618. };
  4619. let getFrameDoc = () => {
  4620. return iframeDoc;
  4621. };
  4622. if(ruleParser.curSiteRule.singleUrl){
  4623. resizePool.push([() => {}, getIframe, getFrameDoc]);
  4624. }else{
  4625. let pageElement = ruleParser.getPageElement(iframeDoc,iframeDoc.defaultView);
  4626. let getPageEle = () => {
  4627. if (!pageElement || pageElement.length===0) {
  4628. pageElement = ruleParser.getPageElement(iframeDoc,iframeDoc.defaultView);
  4629. }
  4630. return pageElement;
  4631. };
  4632. resizePool.push([getPageEle, getIframe, getFrameDoc]);
  4633. }
  4634. scrollToResize();
  4635. };
  4636. curIframe.name = 'pagetual-iframe';
  4637. curIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  4638. curIframe.frameBorder = '0';
  4639. curIframe.scrolling="no";
  4640. curIframe.style.cssText = 'display: block; visibility: visible; float: none; clear: both; width: 100%;height:0;background: initial; border: 0px; border-radius: 0px; margin: 0px 0px 2rem; padding: 0px; z-index: 2147483647;';
  4641. curIframe.addEventListener("load", e=>{
  4642. try{
  4643. iframeDoc=curIframe.contentDocument || curIframe.contentWindow.document;
  4644. }catch(e){
  4645. debug("Stop as cors");
  4646. isPause=true;
  4647. callback(false, false);
  4648. return;
  4649. }
  4650. let css=ruleParser.curSiteRule.css || rulesData.customCss;
  4651. if(css){
  4652. css = css.replace(/^inIframe:/, "");
  4653. let styleEle=iframeDoc.createElement("style");
  4654. styleEle.innerHTML=css;
  4655. iframeDoc.head.appendChild(styleEle);
  4656. }
  4657. loadedHandler();
  4658. let code=ruleParser.curSiteRule.init;
  4659. if(code){
  4660. try{
  4661. Function('doc','win','iframe','"use strict";' + code)(iframeDoc,iframeDoc.defaultView,curIframe);
  4662. }catch(e){
  4663. debug(e);
  4664. }
  4665. }
  4666. });
  4667. let checkTimes=0,findPageEle=false;
  4668. let forceRefresh=e=>{
  4669. if(inAction || !iframeDoc)return;
  4670. inAction=true;
  4671. let foundNext=()=>{
  4672. document.removeEventListener("scroll", forceRefresh);
  4673. }
  4674. setTimeout(()=>{
  4675. inAction=false;
  4676. if(!ruleParser.nextLinkHref){
  4677. checkTimes++;
  4678. ruleParser.getNextLink(iframeDoc);
  4679. if(ruleParser.nextLinkHref){
  4680. foundNext();
  4681. }else if(checkTimes>=10){
  4682. foundNext();
  4683. }else if(checkTimes>=3 && !findPageEle){
  4684. let pageElement = ruleParser.getPageElement(iframeDoc,iframeDoc.defaultView);
  4685. if(!pageElement){
  4686. inAction=true;
  4687. curIframe.contentWindow.location.reload();
  4688. }else{
  4689. findPageEle=true;
  4690. }
  4691. }
  4692. }else{
  4693. foundNext();
  4694. }
  4695. },50);
  4696. };
  4697. document.addEventListener("scroll", forceRefresh);
  4698. curIframe.src=url;
  4699. let insert=ruleParser.getInsert();
  4700. if(ruleParser.curSiteRule.singleUrl || forceState==2){
  4701. document.body.appendChild(loadingDiv);
  4702. document.body.appendChild(curIframe);
  4703. }else{
  4704. ruleParser.insertElement(curIframe);
  4705. }
  4706.  
  4707. if (!scrollToResizeInited) {
  4708. scrollToResizeInited = true;
  4709. document.addEventListener("scroll", scrollToResize);
  4710. }
  4711. return curIframe;
  4712. }
  4713.  
  4714. function loadPageOver(){
  4715. isLoading=false;
  4716. if(loadingDiv.parentNode){
  4717. loadingDiv.parentNode.removeChild(loadingDiv);
  4718. }
  4719. /*setTimeout(()=>{
  4720. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  4721. if(scrollH <= (window.innerHeight || document.documentElement.clientHeight)){
  4722. nextPage();
  4723. }
  4724. },1);*/
  4725. }
  4726.  
  4727. var tryTimes = 0;
  4728.  
  4729. function nextPage(){
  4730. if(typeof ruleParser.curSiteRule.manualMode=='undefined' ? rulesData.manualMode : ruleParser.curSiteRule.manualMode)return;
  4731. if(isPause || isLoading || forceState==1)return;
  4732. if(ruleParser.curSiteRule.delay){
  4733. try{
  4734. let checkDelay=((typeof _unsafeWindow.pagetualDelay=='undefined') ? Function('"use strict";' + ruleParser.curSiteRule.delay) : _unsafeWindow.pagetualDelay)();
  4735. if(!checkDelay)return;
  4736. }catch(e){
  4737. debug(e);
  4738. }
  4739. }
  4740. if(ruleParser.curSiteRule.pageElementCss || ruleParser.curSiteRule.pageElementStyle || rulesData.pageElementCss){
  4741. ruleParser.getPageElement(document, _unsafeWindow);
  4742. }
  4743. let nextLink=ruleParser.nextLinkHref;
  4744. if(!nextLink){
  4745. if(curPage==1){
  4746. ruleParser.getNextLink(document);
  4747. nextLink=ruleParser.nextLinkHref;
  4748. }
  4749. if(!nextLink){
  4750. isLoading=true;
  4751. if(curPage==1 && (ruleParser.curSiteRule.pinUrl || tryTimes++ <= 10)){
  4752. setTimeout(()=>{isLoading=false},500);
  4753. }
  4754. return;
  4755. }
  4756. }
  4757. let pvGallery=document.querySelector("span.pv-gallery-container");
  4758. if(pvGallery && pvGallery.style.display!="none")return;
  4759. let insert=ruleParser.getInsert();
  4760. if (insert) {
  4761. if (curPage == 1) {
  4762. /*window.postMessage({
  4763. insert: geneSelector(ruleParser.curSiteRule.insertPos == 2 ? insert : insert.parentNode, true),
  4764. command: 'pagetual.insert'
  4765. }, '*');*/
  4766. }
  4767. let isJs=/^(javascript|#)/.test(nextLink.replace(location.href,""));
  4768. if(!isJs){
  4769. emuIframe=null;
  4770. lastActiveUrl=nextLink;
  4771. }
  4772. if(location.protocol=="https:" && /^http:/.test(nextLink)){
  4773. nextLink=nextLink.replace(/^http/,"https");
  4774. }
  4775. isLoading=true;
  4776. ruleParser.insertElement(loadingDiv);
  4777. let parent=loadingDiv.parentNode;
  4778. if(parent.tagName=="TBODY"){
  4779. parent=parent.parentNode;
  4780. }
  4781. if(parent.tagName=="TABLE"){
  4782. parent.parentNode.appendChild(loadingDiv);
  4783. }
  4784. loadingDiv.style.cssText=loadingCSS;
  4785. let sleep=ruleParser.curSiteRule.sleep||0;
  4786. setTimeout(()=>{
  4787. if(ruleParser.curSiteRule.pageElementByJs){
  4788. var over=ele=>{
  4789. loadPageOver();
  4790. if(ele){
  4791. createPageBar(nextLink);
  4792. ruleParser.insertPage(null, ele, nextLink, null, true);
  4793. if(autoLoadNum>=0){
  4794. if(autoLoadNum!=0 && --autoLoadNum==0){
  4795. autoLoadNum=-1;
  4796. }else{
  4797. setTimeout(() => nextPage(), 1);
  4798. }
  4799. }
  4800. }else{
  4801. debug("Stop as no page when get by js");
  4802. isPause=true;
  4803. }
  4804. };
  4805. try{
  4806. ((typeof _unsafeWindow.pagetualPageElementByJs=='undefined') ? Function("over",'"use strict";' + ruleParser.curSiteRule.pageElementByJs) : _unsafeWindow.pagetualPageElementByJs)(over);
  4807. }catch(e){
  4808. debug(e);
  4809. }
  4810. }else if((forceState==3||ruleParser.curSiteRule.action==1) && !isJs){
  4811. requestFromIframe(nextLink, (doc, eles)=>{
  4812. loadPageOver();
  4813. if(eles){
  4814. ruleParser.insertPage(doc, eles, nextLink, ()=>{
  4815. createPageBar(nextLink);
  4816. }, true);
  4817. if(autoLoadNum>=0){
  4818. if(autoLoadNum!=0 && --autoLoadNum==0){
  4819. autoLoadNum=-1;
  4820. }else{
  4821. setTimeout(() => nextPage(), 1);
  4822. }
  4823. }
  4824. }
  4825. });
  4826. }else if((forceState==2||ruleParser.curSiteRule.action==2) && !isJs){
  4827. forceIframe(nextLink, (iframe, eles)=>{
  4828. loadPageOver();
  4829. let pageBar=createPageBar(nextLink);
  4830. if(pageBar)iframe.parentNode.insertBefore(pageBar, iframe);
  4831. if(autoLoadNum>=0){
  4832. if(autoLoadNum!=0 && --autoLoadNum==0){
  4833. autoLoadNum=-1;
  4834. }else{
  4835. setTimeout(() => nextPage(), 1);
  4836. }
  4837. }
  4838. });
  4839. }else{
  4840. if(!isJs){
  4841. requestDoc(nextLink, (eles)=>{
  4842. loadPageOver();
  4843. if(eles){
  4844. createPageBar(nextLink);
  4845. if(autoLoadNum>=0){
  4846. if(autoLoadNum!=0 && --autoLoadNum==0){
  4847. autoLoadNum=-1;
  4848. }else{
  4849. setTimeout(() => nextPage(), 1);
  4850. }
  4851. }
  4852. }
  4853. });
  4854. }else{
  4855. emuPage((doc, eles)=>{
  4856. loadPageOver();
  4857. if(eles){
  4858. ruleParser.insertPage(doc, eles, "", ()=>{
  4859. createPageBar(nextLink);
  4860. }, true);
  4861. if(autoLoadNum>=0){
  4862. if(autoLoadNum!=0 && --autoLoadNum==0){
  4863. autoLoadNum=-1;
  4864. }else{
  4865. setTimeout(() => nextPage(), 1);
  4866. }
  4867. }
  4868. }
  4869. });
  4870. }
  4871. }
  4872. },sleep);
  4873. }
  4874. }
  4875.  
  4876. function init(){
  4877. initRules(()=>{
  4878. initPage();
  4879. });
  4880. }
  4881.  
  4882. function visibilitychangeHandler(){
  4883. document.removeEventListener('visibilitychange', visibilitychangeHandler);
  4884. init();
  4885. }
  4886.  
  4887. setTimeout(()=>{
  4888. if (document.hidden) {
  4889. document.addEventListener('visibilitychange', visibilitychangeHandler);
  4890. } else {
  4891. init();
  4892. }
  4893. },100);
  4894. })();

QingJ © 2025

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