东方永页机

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

当前为 2022-07-28 提交的版本,查看 最新版本

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

QingJ © 2025

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