东方永页机

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

目前为 2022-10-03 提交的版本。查看 最新版本

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