东方永页机

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

当前为 2022-05-25 提交的版本,查看 最新版本

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

QingJ © 2025

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