东方永页机

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

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

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

QingJ © 2025

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