东方永页机

自动翻页 - 加载并拼接下一分页内容至当前页尾,无需规则自动适配任意网页

当前为 2022-10-23 提交的版本,查看 最新版本

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

QingJ © 2025

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