东方永页机

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

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

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

QingJ © 2025

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