东方永页机

自动翻页

当前为 2022-01-24 提交的版本,查看 最新版本

  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:ko 東方永頁機
  9. // @namespace hoothin
  10. // @version 0.7.6
  11. // @description Simply auto load the next page
  12. // @description:zh-CN 自动翻页
  13. // @description:zh-TW 自動翻頁
  14. // @description:ja Webページを自動で読み込み継ぎ足し表示を行うブラウザ拡張です
  15. // @description:ru Просто автоматически загрузите следующую страницу
  16. // @description:de Laden Sie einfach automatisch die nächste Seite
  17. // @description:ko 다음 페이지를 자동으로 로드하세요
  18. // @author hoothin
  19. // @include http://*
  20. // @include https://*
  21. // @license MIT
  22. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAdVBMVEUAAADZHQbYHQXaHQbYHgbZHATYHgbYHgbZHQXYHgXZHgbZHgfYHQXYHQbXHQDYHgbYHgbYHQXZHgbYHgbYHgbYHgXaHQbYHQbYHQbZHgbZHgbZHQbZHgbYHgbYHQbYHQXYHgfaHwDZHQXZHQbYHwTVHQrYHgbCqWmRAAAAJnRSTlMAUL8oyD/el2cy1CCPcg/35euggPG6FajOr4Z617OdXkkIi1g4GcTbfAwAAAJDSURBVFjD7dbXtqpADADQ0NsA0hHQY83/f+K9rqNOCzPwfvaTugimjEH4s86739yX0+3n8dwd7dQh/seiaWbHscUqCnZEP24LvrXjXLyyaVJMp2RbeFajZInhJWCHcurB7idEVfS+89SGsS28qJFwyN59ZcgsnXeRVrwvSNLFNJEA1/jfDqW4Po8Z1+XwsX6HGA1Cft1Y0ndw0OjCrwxDj4hPDqgYXbGlZ35pj0fQ1dr0C4DM5++lZHMt/qLNXq2rAG5qtWPdoaL5/ZwXloHAP1onUKs3SOSOO5YEsFNLkJN2T/IRRt0gj6ZUUpZTyMmzUx/Vw8wVhwgEI9pog2PiHRO0OhTq2hLnytBK3yRdsKeCGjRnoagKLRbQNfwsXdGiAkLMu5ihWUSvr5S/tPWPlIV8kxvn58CKatMu7Ly1+Kzcsgwj0wqXlgnNMT7CrFPwwaTp+OsSKS4Y1UJ5Phl/BSM3F7JBQmKO78UGJWT/zWJpTae7E4CTtJcnVJ2E7dV4RAWlY36uM96gFnHQT0HFe0zOIZYbnGsVRJZHc/DZFS15pu54URfUSgYJvVJ8BgpPWWu3TwfJUxkvPahylAzy573ybXfQHVEUFt/2uC67KgWcybPp602gndMMKF647bfIUg9oQYmCH6B1PF7jHFDQk2n6PJ7gDcil1FekowdGuVBGqw7rGZXNFSweLnJRJo4pD4cENphb/CoH57O6o8q/wzbJtCBXuXVz7sqQBbBDMJ9a6e+SA/tlzjx0Q3TLL0/4Y/QPSYfEIomUUSEAAAAASUVORK5CYII=
  23. // @grant GM_xmlhttpRequest
  24. // @grant GM_registerMenuCommand
  25. // @grant GM_notification
  26. // @grant GM_getValue
  27. // @grant GM_setValue
  28. // @grant GM_addStyle
  29. // @grant GM_openInTab
  30. // @grant GM.xmlHttpRequest
  31. // @grant GM.registerMenuCommand
  32. // @grant GM.notification
  33. // @grant GM.getValue
  34. // @grant GM.setValue
  35. // @grant GM.addStyle
  36. // @grant GM.openInTab
  37. // @connect wedata.net
  38. // @connect githubusercontent.com
  39. // @run-at document-idle
  40. // @exclude http://www.toodledo.com/tasks/*
  41. // @exclude http*://maps.google.com*/*
  42. // @exclude *://www.google.*/_/chrome/newtab*
  43. // @exclude *://mega.*/*
  44. // @exclude *://*.mega.*/*
  45. // @exclude *://*.youku.com/v_*
  46. // @exclude *://*pan.baidu.com
  47. // @exclude *://*.iqiyi.com/v_*
  48. // @exclude *://*.iqiyi.com/w_*
  49. // @exclude *://*.iqiyi.com/a_*
  50. // @exclude *://*.le.com/ptv/vplay/*
  51. // @exclude *://v.qq.com/x/cover/*
  52. // @exclude *://v.qq.com/x/page/*
  53. // @exclude *://v.qq.com/tv/*
  54. // @exclude *://*.tudou.com/listplay/*
  55. // @exclude *://*.tudou.com/albumplay/*
  56. // @exclude *://*.tudou.com/programs/view/*
  57. // @exclude *://*.mgtv.com/b/*
  58. // @exclude *://film.sohu.com/album/*
  59. // @exclude *://tv.sohu.com/v/*
  60. // @exclude *://*.bilibili.com/video/*
  61. // @exclude *://*.bilibili.com/bangumi/play/*
  62. // @exclude *://*.baofeng.com/play/*
  63. // @exclude *://vip.pptv.com/show/*
  64. // @exclude *://v.pptv.com/show/*
  65. // @exclude *://www.le.com/ptv/vplay/*
  66. // @exclude *://www.wasu.cn/Play/show/*
  67. // @exclude *://m.v.qq.com/x/cover/*
  68. // @exclude *://m.v.qq.com/x/page/*
  69. // @exclude *://m.v.qq.com/*
  70. // @exclude *://m.iqiyi.com/*
  71. // @exclude *://m.iqiyi.com/kszt/*
  72. // @exclude *://m.youku.com/alipay_video/*
  73. // @exclude *://m.mgtv.com/b/*
  74. // @exclude *://m.tv.sohu.com/v/*
  75. // @exclude *://m.film.sohu.com/album/*
  76. // @exclude *://m.le.com/ptv/vplay/*
  77. // @exclude *://m.pptv.com/show/*
  78. // @exclude *://m.acfun.cn/v/*
  79. // @exclude *://m.bilibili.com/video/*
  80. // @exclude *://m.bilibili.com/anime/*
  81. // @exclude *://m.bilibili.com/bangumi/play/*
  82. // @exclude *://m.wasu.cn/Play/show/*
  83. // @exclude *://www.youtube.com
  84. // @exclude *://www.youtube.com/
  85. // @exclude *://www.youtube.com/watch*
  86. // ==/UserScript==
  87.  
  88. (function() {
  89. 'use strict';
  90.  
  91. if (window.name === 'pagetual-iframe') {
  92. var domloaded = function (){
  93. window.scroll(window.scrollX, 99999);
  94. //window.parent.postMessage('pagetual-iframe:DOMLoaded', '*');
  95. };
  96. if(window.opera){
  97. document.addEventListener('DOMContentLoaded', domloaded, false);
  98. } else {
  99. domloaded();
  100. }
  101. return;
  102. }
  103.  
  104. if(window.top != window.self){
  105. return;
  106. }
  107.  
  108. const lang = navigator.appName=="Netscape"?navigator.language:navigator.userLanguage;
  109. var i18n=(name, param)=>{
  110. let config={};
  111. switch (lang){
  112. case "zh-CN":
  113. case "zh-SG":
  114. config={
  115. disable:"暂时禁用",
  116. disableSite:"在此站禁用",
  117. enable:"启用翻页",
  118. toTop:"回到顶部",
  119. toBottom:"前往页尾",
  120. current:"当前页",
  121. forceIframe:"强制拼接",
  122. cancelForceIframe:"取消强制拼接",
  123. configure:"打开配置页",
  124. update:"立即更新规则",
  125. passSec:"更新于 #t# 秒前",
  126. passMin:"更新于 #t# 分钟前",
  127. passHour:"更新于 #t# 小时前",
  128. passDay:"更新于 #t# 天前",
  129. cantDel:"无法删除内置规则",
  130. confirmDel:"是否确认要删除此规则?",
  131. updateSucc:"更新成功",
  132. beginUpdate:"正在更新,请稍候",
  133. customUrls:"导入规则url,一行一条,AutoPagerize 格式规则需要以\"0|\"开头",
  134. customRules:"输入【东方永页机】格式的自定义规则",
  135. save:"保存设置",
  136. loadingText:"少女祈祷中...",
  137. opacity:"分页隔条透明值",
  138. sortTitle:"排序在下次更新规则后生效"
  139. };
  140. break;
  141. case "zh-TW":
  142. case "zh-HK":
  143. config={
  144. disable:"暫時禁用",
  145. disableSite:"在此站禁用",
  146. enable:"啟用翻頁",
  147. toTop:"回到頂部",
  148. toBottom:"前往頁尾",
  149. current:"當前頁",
  150. forceIframe:"強制拼接",
  151. cancelForceIframe:"取消强制拼接",
  152. configure:"打開配置頁",
  153. update:"立即更新規則",
  154. passSec:"更新于 #t# 秒前",
  155. passMin:"更新于 #t# 分鐘前",
  156. passHour:"更新于 #t# 小時前",
  157. passDay:"更新于 #t# 天前",
  158. cantDel:"無法刪除内置規則",
  159. confirmDel:"是否確認要刪除此規則?",
  160. updateSucc:"更新成功",
  161. beginUpdate:"正在更新,請稍候",
  162. customUrls:"導入規則url,一行一條,AutoPagerize 格式規則需要以\"0|\"開頭",
  163. customRules:"輸入【東方永頁機】格式的自定義規則",
  164. save:"存儲設置",
  165. loadingText:"少女祈禱中...",
  166. opacity:"分頁隔條透明值",
  167. sortTitle:"排序在下次更新規則後生效"
  168. };
  169. break;
  170. case "ja":
  171. config = {
  172. disable: "一時的に無効にする",
  173. disableSite:"このサイト無効",
  174. enable: "ページめくりを有効にする",
  175. toTop: "トップに戻る",
  176. toBottom: "ページの下部に移動",
  177. current: "現在のページ",
  178. forceIframe: "強制ステッチ",
  179. cancelForceIframe: "強制ステッチをキャンセル",
  180. configure: "設定ページを開く",
  181. update: "今すぐルールを更新してください",
  182. passSec: "#t#秒前に更新",
  183. passMin: "#t#分前に更新",
  184. passHour: "#t#時間前に更新",
  185. passDay: "#t#日前に更新",
  186. cantDel: "組み込みルールを削除できません",
  187. confirmDel: "このルールを削除してもよろしいですか?",
  188. updateSucc: "更新に成功しました",
  189. beginUpdate: "更新中、お待ちください",
  190. customUrls: "インポートルールのURL、1行に1つ、AutoPagerizeフォーマットルールは\"0|\"で始まる必要があります",
  191. customRules: "【東方永頁機】の形式でカスタムルールを入力してください",
  192. save: "設定を保存",
  193. loadingText: "少女祈祷中...",
  194. opacity:"ページネーションバーの透明値",
  195. sortTitle:"並べ替えは、次のルールの更新後に有効になります"
  196. };
  197. break;
  198. default:
  199. config={
  200. disable:"Disable",
  201. disableSite:"Disable in the site",
  202. enable:"Enable",
  203. toTop:"To Top",
  204. toBottom:"To Bottom",
  205. current:"Current Page",
  206. forceIframe:"Force to join",
  207. cancelForceIframe:"Cancel Force join",
  208. configure:"Configure",
  209. update:"Update rules from url now",
  210. passSec:"Updated #t# seconds ago",
  211. passMin:"Updated #t# minutes ago",
  212. passHour:"Updated #t# hours ago",
  213. passDay:"Updated #t# days ago",
  214. cantDel:"Can't delete buildin rules",
  215. confirmDel:"Are you sure you want to delete this rule?",
  216. updateSucc:"Update succeeded",
  217. beginUpdate:"Begin update, wait a minute please",
  218. customUrls:"Import rule url, One url per line, rules on AutoPagerize format need to start with \"0|\"",
  219. customRules:"Input custom rules with [Pagetual] format",
  220. save:"Save",
  221. loadingText:"Shojo Now Loading...",
  222. opacity:"Pagination spacer opacity",
  223. sortTitle:"Sorting takes effect after the next rule update"
  224. };
  225. break;
  226. }
  227. return config[name]?config[name].replace("#t#",param):name;
  228. };
  229.  
  230. var enableDebug=true;
  231. var debug=str=>{
  232. if(enableDebug){
  233. console.debug(str);
  234. }
  235. };
  236.  
  237. var _GM_xmlhttpRequest,_GM_registerMenuCommand,_GM_notification,_GM_addStyle,_GM_openInTab;
  238. if(typeof GM_xmlhttpRequest!='undefined'){
  239. _GM_xmlhttpRequest=GM_xmlhttpRequest;
  240. }else if(typeof GM!='undefined' && typeof GM.xmlHttpRequest!='undefined'){
  241. _GM_xmlhttpRequest=GM.xmlHttpRequest;
  242. }
  243. if(typeof GM_registerMenuCommand!='undefined'){
  244. _GM_registerMenuCommand=GM_registerMenuCommand;
  245. }else if(typeof GM!='undefined' && typeof GM.registerMenuCommand!='undefined'){
  246. _GM_registerMenuCommand=GM.registerMenuCommand;
  247. }
  248. if(typeof GM_notification!='undefined'){
  249. _GM_notification=GM_notification;
  250. }else if(typeof GM!='undefined' && typeof GM.notification!='undefined'){
  251. _GM_notification=GM.notification;
  252. }
  253. if(typeof GM_openInTab!='undefined'){
  254. _GM_openInTab=GM_openInTab;
  255. }else if(typeof GM!='undefined' && typeof GM.openInTab!='undefined'){
  256. _GM_openInTab=GM.openInTab;
  257. }
  258. if(typeof GM_addStyle!='undefined'){
  259. _GM_addStyle=GM_addStyle;
  260. }else if(typeof GM!='undefined' && typeof GM.addStyle!='undefined'){
  261. _GM_addStyle=GM.addStyle;
  262. }else{
  263. _GM_addStyle=cssStr=>{
  264. let styleEle=document.createElement("style");
  265. styleEle.innerHTML=cssStr;
  266. document.head.appendChild(styleEle);
  267. };
  268. }
  269.  
  270. if(typeof _GM_xmlhttpRequest=='undefined')_GM_xmlhttpRequest=(f)=>{};
  271. if(typeof _GM_registerMenuCommand=='undefined')_GM_registerMenuCommand=(s,f)=>{};
  272. if(typeof _GM_notification=='undefined')_GM_notification=(s)=>{};
  273. var _unsafeWindow=(typeof unsafeWindow=='undefined')?window:unsafeWindow;
  274. var storage={
  275. supportGM: typeof GM_getValue=='function' && typeof GM_getValue('a','b')!='undefined',
  276. supportGMPromise: typeof GM!='undefined' && typeof GM.getValue=='function' && typeof GM.getValue('a','b')!='undefined',
  277. mxAppStorage:(function(){
  278. try{
  279. return window.external.mxGetRuntime().storage;
  280. }catch(e){
  281. }
  282. })(),
  283. operaUJSStorage:(function(){
  284. try{
  285. return window.opera.scriptStorage;
  286. }catch(e){
  287. }
  288. })(),
  289. setItem:function(key,value){
  290. if(this.operaUJSStorage){
  291. this.operaUJSStorage.setItem(key,value);
  292. }else if(this.mxAppStorage){
  293. this.mxAppStorage.setConfig(key,value);
  294. }else if(this.supportGM){
  295. GM_setValue(key,value);
  296. }else if(this.supportGMPromise){
  297. GM.setValue(key,value);
  298. }else if(window.localStorage){
  299. window.localStorage.setItem(key,value);
  300. }
  301. },
  302. getItem:function(key,cb){
  303. var value;
  304. if(this.operaUJSStorage){
  305. value=this.operaUJSStorage.getItem(key);
  306. }else if(this.mxAppStorage){
  307. value=this.mxAppStorage.getConfig(key);
  308. }else if(this.supportGM){
  309. value=GM_getValue(key);
  310. }else if(this.supportGMPromise){
  311. value=GM.getValue(key).then(v=>{cb(v)});
  312. return;
  313. }else if(window.localStorage){
  314. value=window.localStorage.getItem(key);
  315. };
  316. cb(value);
  317. }
  318. };
  319. _GM_registerMenuCommand(i18n("configure"), ()=>{
  320. _GM_openInTab("https://github.com/hoothin/UserScripts/tree/master/Pagetual");
  321. });
  322.  
  323. function getElementByXpath(xpath, contextNode, doc){
  324. doc = doc || document;
  325. contextNode = contextNode || doc;
  326. try {
  327. var result = doc.evaluate(xpath, contextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
  328. return result.singleNodeValue && result.singleNodeValue.nodeType === 1 && result.singleNodeValue;
  329. } catch (err) {
  330. throw new Error(`Invalid xpath: ${xpath}`);
  331. }
  332. }
  333.  
  334. function getAllElementsByXpath(xpath, contextNode, doc){
  335. doc = doc || document;
  336. contextNode = contextNode || doc;
  337. var result = [];
  338. try {
  339. var query = doc.evaluate(xpath, contextNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  340. for (var i = 0; i < query.snapshotLength; i++) {
  341. var node = query.snapshotItem(i);
  342. if (node.nodeType === 1) result.push(node);
  343. }
  344. } catch (err) {
  345. throw new Error(`Invalid xpath: ${xpath}`);
  346. }
  347. return result;
  348. }
  349.  
  350. class RuleParser {
  351. constructor() {
  352. this.hpRules=[];
  353. this.customRules=[];
  354. this.rules=[];
  355. this.pageDoc=document;
  356. this.nextLinkHref=null;
  357. this.curUrl=location.href;
  358. this.curSiteRule={};
  359. }
  360.  
  361. initSavedRules(callback){
  362. var self=this;
  363. storage.getItem("hpRules", hpRules=>{
  364. if(hpRules)self.hpRules=hpRules;
  365. storage.getItem("customRules", customRules=>{
  366. if(customRules)self.customRules=customRules;
  367. storage.getItem("rules", rules=>{
  368. if(rules)this.rules=rules;
  369. callback();
  370. });
  371. });
  372. });
  373. }
  374.  
  375. saveCurSiteRule(){
  376. if(!this.curSiteRule || !this.curSiteRule.url)return;
  377. this.hpRules=this.hpRules.filter(item=>{return item&&item.url!=this.curSiteRule.url});
  378. this.hpRules.unshift(this.curSiteRule);
  379. if(this.hpRules.length>30){
  380. this.hpRules.pop();
  381. }
  382. storage.setItem("hpRules", this.hpRules);
  383. }
  384.  
  385. requestJSON(url, callback){
  386. _GM_xmlhttpRequest({
  387. url: url,
  388. method: 'GET',
  389. onload: function(res) {
  390. let json=null;
  391. try{
  392. json=JSON.parse(res.response);
  393. }catch(e){
  394. debug(e);
  395. }
  396. callback(json);
  397. }
  398. });
  399. }
  400.  
  401. formatRule(item, type, from){
  402. switch(type){
  403. case 0:
  404. return {
  405. from:from,
  406. type:type,
  407. name:item.name,
  408. action:item.data.forceIframe=="true"?1:0,
  409. url:item.data.url,
  410. pageElement:item.data.pageElement,
  411. nextLink:item.data.nextLink,
  412. insert:item.data.insertBefore,
  413. insertPos:1,
  414. updatedAt:item.data.updated_at,
  415. css:item.data.Stylus+item.data.CSS,
  416. pageAction:item.data.bookmarklet
  417. };
  418. break;
  419. case 1:
  420. default:
  421. item.from=from;
  422. if(typeof(item.type) == "undefined")item.type=type;
  423. return item;
  424. break;
  425. }
  426. return null;
  427. }
  428.  
  429. addRuleByUrl(url, type, from, callback) {
  430. this.requestJSON(url, json=>{
  431. this.addRules(json, type, from);
  432. storage.setItem("rules", this.rules);
  433. callback();
  434. });
  435. }
  436.  
  437. addRules(rules, type, from) {
  438. if(rules && rules.length>0){
  439. this.rules=this.rules.filter(item=>{return item.from!=from});
  440. rules.forEach(item=>{
  441. let rule=this.formatRule(item, type, from);
  442. if(rule){
  443. this.rules.push(rule);
  444. }
  445. });
  446. }
  447. }
  448.  
  449. getRule(callback) {
  450. if(this.curSiteRule && this.curSiteRule.url){
  451. return this.curSiteRule;
  452. }
  453. var self=this;
  454. for(let i in this.hpRules){
  455. let rule=this.hpRules[i];
  456. if(!rule || rule.enable==0)continue;
  457. let urlReg=new RegExp(rule.url, "i");
  458. if(urlReg.test(location.href)){
  459. this.curSiteRule=rule;
  460. debug(rule);
  461. callback();
  462. return rule;
  463. }
  464. }
  465. for(let i in this.customRules){
  466. let rule=this.customRules[i];
  467. if(rule.enable==0)continue;
  468. let urlReg=new RegExp(rule.url, "i");
  469. if(urlReg.test(location.href)){
  470. let pageElement,nextLink,insert;
  471. if(rule.pageElement)pageElement=rule.type==0?getElementByXpath(rule.pageElement):document.querySelector(rule.pageElement);
  472. if(rule.nextLink)nextLink=rule.type==0?getElementByXpath(rule.nextLink):document.querySelector(rule.nextLink);
  473. if(rule.insert)insert=rule.type==0?getElementByXpath(rule.insert):document.querySelector(rule.insert);
  474. if((rule.pageElement && !pageElement) ||
  475. (rule.nextLink && !nextLink) ||
  476. (rule.insert && !insert)){
  477. continue;
  478. }
  479. this.curSiteRule=rule;
  480. debug(rule);
  481. callback();
  482. return rule;
  483. }
  484. }
  485. let r=0;
  486. function searchByTime(){
  487. setTimeout(()=>{
  488. let end=r+80;
  489. end=end>self.rules.length?self.rules.length:end;
  490. for(;r<end;r++){
  491. let rule=self.rules[r];
  492. if(rule.enable==0)continue;
  493. let urlReg=new RegExp(rule.url, "i");
  494. if(urlReg.test(location.href)){
  495. let pageElement,nextLink,insert;
  496. if(rule.pageElement)pageElement=rule.type==0?getElementByXpath(rule.pageElement):document.querySelector(rule.pageElement);
  497. if(rule.nextLink)nextLink=rule.type==0?getElementByXpath(rule.nextLink):document.querySelector(rule.nextLink);
  498. if(rule.insert)insert=rule.type==0?getElementByXpath(rule.insert):document.querySelector(rule.insert);
  499. if((rule.pageElement && !pageElement) ||
  500. (rule.nextLink && !nextLink) ||
  501. (rule.insert && !insert)){
  502. continue;
  503. }
  504. self.curSiteRule=rule;
  505. debug(rule);
  506. callback();
  507. return;
  508. }
  509. }
  510. if(end>=self.rules.length){
  511. self.curSiteRule={};
  512. self.curSiteRule.url=(location.origin+location.pathname).replace(/\./g,"\\.");
  513. callback();
  514. return;
  515. }else{
  516. searchByTime();
  517. }
  518. },20);
  519. }
  520. searchByTime();
  521. }
  522.  
  523. geneSelector(ele){
  524. let selector=ele.tagName;
  525. //Google id class都是隨機。百度更過分,style script順序都是隨機的
  526. //if(ele.id) selector += '#' + ele.id;
  527. //if(ele.classList) selector += [].map.call(ele.classList,d=>'.'+d).join('');
  528. let parent = ele.parentElement;
  529. if(parent){
  530. let i,j=0;
  531. for(i=0;i<parent.children.length;i++){
  532. if(parent.children[i].tagName==selector){
  533. j++;
  534. if(parent.children[i]==ele){
  535. break;
  536. }
  537. }
  538. }
  539. selector = this.geneSelector(parent) + ' > ' + selector + (parent.tagName=="HTML"?"":`:nth-of-type(${j})`);
  540. }
  541. return selector;
  542. }
  543.  
  544. getPageElement(doc, curWin, dontFind) {
  545. let pageElement=null;
  546. let self=this;
  547. if(this.curSiteRule.pageElement){
  548. pageElement=this.curSiteRule.type==0?getAllElementsByXpath(this.curSiteRule.pageElement,doc,doc):doc.querySelectorAll(this.curSiteRule.pageElement);
  549. }
  550. if((!pageElement || pageElement.length==0) && curWin && !dontFind){
  551. let body=doc.body;
  552. if(!body)return null;
  553. let bodyHeight=parseInt(curWin.getComputedStyle(body).height);
  554. function checkElement(ele){
  555. let curHeight=parseInt(curWin.getComputedStyle(ele).height);
  556. if(curHeight/bodyHeight<=0.35)return null;
  557. if(ele.children.length==0 && !self.curSiteRule.pageElement){
  558. self.curSiteRule.pageElement=self.geneSelector(ele.parentNode)+">"+ele.tagName;
  559. self.curSiteRule.type=1;
  560. debug(self.curSiteRule.pageElement);
  561. return [ele];
  562. }
  563. let i,maxHeight=curHeight*0.35,curMaxEle=null,curMaxArea=0;
  564. for(i=0;i<ele.children.length;i++){
  565. let curNode=ele.children[i];
  566. let comStyle=curWin.getComputedStyle(curNode);
  567. let h=parseInt(comStyle.height);
  568. let w=parseInt(comStyle.width);
  569. if(isNaN(h) || isNaN(w))continue;
  570. let a=h*w+h,moreChild=curNode.children[0];
  571. while(moreChild){
  572. comStyle=curWin.getComputedStyle(moreChild);
  573. let ch=parseInt(comStyle.height);
  574. let cw=parseInt(comStyle.width);
  575. if(moreChild.innerText!="" && !isNaN(ch) && !isNaN(cw)){
  576. a+=ch*cw;
  577. }
  578. moreChild=moreChild.nextElementSibling;
  579. }
  580. if(curMaxEle==null || curMaxArea<a){
  581. curHeight=h;
  582. curMaxArea=a;
  583. curMaxEle=curNode;
  584. }
  585. }
  586. if(curMaxEle && curHeight>maxHeight){
  587. return checkElement(curMaxEle);
  588. }
  589. if(!self.curSiteRule.pageElement){
  590. self.curSiteRule.pageElement=self.geneSelector(ele)+">*";
  591. self.curSiteRule.type=1;
  592. debug(self.curSiteRule.pageElement);
  593. }
  594. return ele.children;
  595. }
  596. pageElement=checkElement(body);
  597. if(pageElement)this.saveCurSiteRule();
  598. }
  599. return pageElement;
  600. }
  601.  
  602. getPage(doc){
  603. let canSave=false;//發現頁碼選擇器在其他頁對不上,還是別保存了
  604. let url=this.curUrl;
  605. let pageNum=0,preStr="",afterStr="";
  606. let pageMatch1=url.match(/(.*[a-zA-Z0-9\/][\-_](?:p|page)?)(\d+)(\.html?$|$)/i);
  607. let pageMatch2=url.match(/(.*[\?&]p(?:age)?=)(\d+)($|[#&].*)/i);
  608. if(pageMatch1){
  609. preStr=pageMatch1[1];
  610. pageNum=pageMatch1[2];
  611. afterStr=pageMatch1[3];
  612. }else if(pageMatch2){
  613. preStr=pageMatch2[1];
  614. pageNum=pageMatch2[2];
  615. afterStr=pageMatch2[3];
  616. }
  617. var curPage=doc,i,cur;
  618. let next=curPage.querySelector("a.next"),jsNext;
  619. if(!next)next=curPage.querySelector("a#next");
  620. if(!next)next=curPage.querySelector("a#rightFix");
  621. if(!next)next=curPage.querySelector("a.next_page");
  622. if(!next)next=curPage.querySelector(".next>a");
  623. if(!next)next=curPage.querySelector("#next_page");
  624. if(!next)next=curPage.querySelector(".next>button");
  625. if(next && (!next.href || /javascript:/.test(next.href))){
  626. jsNext=next;
  627. next=null;
  628. }
  629. if(!next){
  630. let pageDiv=curPage.querySelector("div.wp-pagenavi");
  631. if(pageDiv){
  632. cur=pageDiv.querySelector("span.current");
  633. next=cur.nextSibling;
  634. }else{
  635. cur=curPage.querySelector("div.article-paging>span");
  636. if(cur){
  637. next=cur.nextElementSibling;
  638. }
  639. }
  640. }
  641. if(!next){
  642. let pageDiv=curPage.querySelector("div.pages>ul");
  643. if(pageDiv){
  644. cur=pageDiv.querySelector("li>b");
  645. if(cur)next=cur.parentNode.nextElementSibling.querySelector("a");
  646. }
  647. }
  648. if(!next){
  649. let aTags=curPage.querySelectorAll("a");
  650. let nextf,nexts,nextt,nextfo;
  651. for(i=0;i<aTags.length;i++){
  652. let aTag=aTags[i];
  653. if(nextf && nexts && nextt)break;
  654. if(!nextf){
  655. if(/(\s|^)下[一1]?[页頁张張]|^next( page)?\s*$|次のページ/i.test(aTag.innerText)){
  656. if(!aTag.href || /javascript:/.test(aTag.href)){
  657. nextfo=aTag;
  658. }else{
  659. nextf=aTag;
  660. }
  661. }
  662. }
  663. if(!nexts){
  664. if(aTag.innerText=="&gt;"){
  665. if(!aTag.href || /javascript:/.test(aTag.href)){
  666. nextfo=aTag;
  667. }else{
  668. nexts=aTag;
  669. }
  670. }
  671. }
  672. if(!aTag.href || /javascript:/.test(aTag.href))continue;
  673. if(!nextt){
  674. aTag.href=aTag.href.replace(/\?&/,"?");
  675. if(aTag.innerText=="»"){
  676. nextt=aTag;
  677. }else if(aTag.href.replace(preStr,"").replace(afterStr,"")==parseInt(pageNum)+1){
  678. nextt=aTag;
  679. }else if(aTag.href.indexOf(url)!=-1 && /^[\/\?&]?[_-]?(p|page)?=?2(\?|&|$)/i.test(aTag.href.replace(url,""))){
  680. nextt=aTag;
  681. }
  682. }
  683. }
  684. next=nextf||nexts||nextt||nextfo;
  685. }
  686. if(!next)next=jsNext||curPage.querySelector('[rel="next"]');
  687. return {next:next,canSave:canSave};
  688. }
  689.  
  690. getNextLink(doc) {
  691. let nextLink=null,page;
  692. if(this.curSiteRule.pageElementByJs){
  693. this.nextLinkHref="#";
  694. return true;
  695. }else if(this.curSiteRule.nextLinkByJs){
  696. let targetUrl=Function("doc",'"use strict";' + this.curSiteRule.nextLinkByJs)(doc);;
  697. nextLink={href:targetUrl};
  698. }else if(this.curSiteRule.nextLinkByUrl){
  699. let targetUrl=this.curUrl.replace(new RegExp(this.curSiteRule.nextLinkByUrl[0]), this.curSiteRule.nextLinkByUrl[1]);
  700. if(targetUrl != this.curUrl){
  701. let reps=targetUrl.match(/{.*?}/g);
  702. if(reps){
  703. reps.forEach(rep=>{
  704. let code=rep.replace("{","").replace("}","");
  705. let result=code.match(/^(\d+)\+1$/);
  706. if(result){
  707. result=parseInt(result[1])+1;
  708. }
  709. else result=Function('"use strict";return ' + code)();;
  710. targetUrl=targetUrl.replace(rep, result);
  711. });
  712. }
  713. }
  714. nextLink={href:targetUrl};
  715. }else if(this.curSiteRule.nextLink){
  716. nextLink=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.nextLink,doc,doc):doc.querySelector(this.curSiteRule.nextLink);
  717. }
  718. if(!nextLink){
  719. page=this.getPage(doc);
  720. nextLink=page.next;
  721. if(nextLink && doc==document){
  722. let nextLinkCs=_unsafeWindow.getComputedStyle(nextLink);
  723. if(nextLinkCs.cursor=="not-allowed"){
  724. self.nextLinkHref=false;
  725. return null;
  726. }
  727. }
  728. }
  729. if(nextLink){
  730. if(!this.curSiteRule.nextLink && page && page.canSave){
  731. this.curSiteRule.nextLink=this.geneSelector(nextLink);
  732. this.curSiteRule.type=1;
  733. this.saveCurSiteRule();
  734. }
  735. }
  736. if(nextLink){
  737. this.nextLinkHref=nextLink.href?nextLink.href:"#";
  738. debug(nextLink);
  739. }else{
  740. this.nextLinkHref=false;
  741. }
  742. return nextLink;
  743. }
  744.  
  745. getInsert(refresh) {
  746. if(this.insert && !refresh && this.insert.parentNode && this.insert.parentNode.parentNode)return this.insert;
  747. if(this.curSiteRule.insert){
  748. this.insert=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.insert,document):document.querySelector(this.curSiteRule.insert);
  749. }else{
  750. let pageElement=this.getPageElement(document, _unsafeWindow);
  751. if(pageElement && pageElement.length>0){
  752. var pELast = pageElement[pageElement.length - 1];
  753. this.insert = pELast.nextSibling ? pELast.nextSibling : pELast.parentNode.appendChild(document.createTextNode(' '));
  754. }
  755. }
  756. return this.insert;
  757. }
  758.  
  759. pageAction(doc,eles){
  760. let code=this.curSiteRule.pageAction;
  761. if(code){
  762. Function("doc","eles",'"use strict";' + code)(doc,eles);
  763. }
  764. let css=this.curSiteRule.css;
  765. if(css){
  766. _GM_addStyle(css);
  767. }
  768. [].forEach.call(eles, ele=>{
  769. [].forEach.call(ele.querySelectorAll("img"), img=>{
  770. //if(img.src==""){
  771. let realSrc;
  772. if(img.dataset && img.dataset.original){
  773. realSrc=img.dataset.original;
  774. }else if(img.dataset && img.dataset.src){
  775. realSrc=img.dataset.src;
  776. }else if(img._lazyrias && img._lazyrias.srcset){
  777. realSrc=img._lazyrias.srcset[img._lazyrias.srcset.length-1];
  778. }else if(img.dataset && img.dataset.origFile){
  779. realSrc=img.dataset.origFile;
  780. }else if(img.srcset){
  781. var srcs=img.srcset.split(","),largeSize=0;
  782. srcs.forEach(srci=>{
  783. let srcInfo=srci.trim().split(" "),curSize=parseInt(srcInfo[1]);
  784. if(srcInfo[1] && curSize>largeSize){
  785. largeSize=curSize;
  786. realSrc=srcInfo[0];
  787. }
  788. });
  789. }
  790. if(realSrc)img.src=realSrc;
  791. //}
  792. });
  793. });
  794. let lazyImgSrc=this.curSiteRule.lazyImgSrc;
  795. if(lazyImgSrc){
  796. [].forEach.call(eles, ele=>{
  797. [].forEach.call(ele.querySelectorAll("img"), img=>{
  798. if(img[lazyImgSrc]){
  799. img.src=img[lazyImgSrc];
  800. }
  801. });
  802. });
  803. }
  804. }
  805.  
  806. initPage(callback){
  807. let self=this;
  808. this.getRule(()=>{
  809. if(self.curSiteRule){
  810. self.hpRules=self.hpRules.filter(item=>{return item&&item.url!=self.curSiteRule.url});
  811. self.hpRules.unshift(self.curSiteRule);
  812. if(self.hpRules.length>30){
  813. self.hpRules.pop();
  814. }
  815. storage.setItem("hpRules", self.hpRules);
  816. }
  817. let code=self.curSiteRule.init;
  818. if(code){
  819. Function('"use strict";' + code)();
  820. }
  821. self.getNextLink(document);
  822. callback();
  823. });
  824. }
  825.  
  826. insertPage(doc, eles, url){
  827. this.pageDoc=doc;
  828. this.curUrl=url;
  829. this.pageAction(doc, eles);
  830. this.getNextLink(doc);
  831. this.getInsert();
  832. var self=this;
  833. if(!eles || eles.length==0 || !self.insert || !self.insert.parentNode){
  834. }else{
  835. [].forEach.call(eles, ele=>{
  836. if(self.curSiteRule.insertPos==2){
  837. self.insert.appendChild(ele.cloneNode(true));
  838. }else{
  839. self.insert.parentNode.insertBefore(ele.cloneNode(true), self.insert);
  840. }
  841. });
  842. }
  843. }
  844. }
  845. var ruleParser = new RuleParser();
  846.  
  847. var rulesData={},ruleUrls,updateDate;
  848. function initConfig(){
  849. _GM_registerMenuCommand(i18n(forceState==1?"enable":"disableSite"), ()=>{
  850. storage.setItem("forceState_"+location.host, (forceState==1?0:1));
  851. location.reload();
  852. });
  853.  
  854. _GM_registerMenuCommand(i18n(forceState==2?"cancelForceIframe":"forceIframe"), ()=>{
  855. storage.setItem("forceState_"+location.host, (forceState==2?0:2));
  856. location.reload();
  857. });
  858. var configCon,insertPos;
  859. if(location.href=="https://github.com/hoothin/UserScripts/tree/master/Pagetual"){
  860. _GM_addStyle(`
  861. p>span:nth-child(1),p>span:nth-child(2),p>span:nth-child(3){
  862. cursor: pointer;
  863. user-select: none;
  864. }
  865. p>span:nth-child(1):hover,p>span:nth-child(2):hover,p>span:nth-child(3):hover{
  866. color:red;
  867. }
  868. .updateDate{
  869. cursor: pointer;
  870. user-select: none;
  871. }
  872. .updateDate:hover{
  873. color:red;
  874. }
  875. `);
  876. configCon=document.querySelector(".markdown-body");
  877. insertPos=configCon.querySelector("hr");
  878. }else if(location.href=="https://github.com/hoothin/UserScripts/tree/master/Pagetual"){
  879. }else return;
  880. class Rulebar {
  881. init(ruleUrl){
  882. this.ruleUrl=ruleUrl;
  883. this.item=document.createElement("p");
  884. this.item.title=ruleUrl.type==0?"AutoPagerize Rules":"Pagetual Rules";
  885. this.item.dataset.id=this.ruleUrl.id;
  886. let url=document.createElement("span");
  887. url.innerHTML=ruleUrl.url;
  888. let up=document.createElement("span");
  889. up.innerHTML="↑ ";
  890. up.title=i18n("sortTitle");
  891. let down=document.createElement("span");
  892. down.innerHTML="↓ ";
  893. down.title=i18n("sortTitle");
  894. let del=document.createElement("span");
  895. del.innerHTML="× ";
  896. up.onclick=e=>{
  897. this.moveUp();
  898. };
  899. down.onclick=e=>{
  900. this.moveDown();
  901. };
  902. del.onclick=e=>{
  903. this.del();
  904. };
  905. this.item.appendChild(up);
  906. this.item.appendChild(down);
  907. this.item.appendChild(del);
  908. this.item.appendChild(url);
  909. configCon.insertBefore(this.item, insertPos);
  910. }
  911. saveSort(){
  912. let sort=[];
  913. [].forEach.call(this.item.parentNode.querySelectorAll("p[data-id]"), i=>{
  914. sort.push(i.dataset.id);
  915. });
  916. rulesData.sort=sort;
  917. storage.setItem("importRuleUrl", rulesData);
  918. }
  919. moveUp(){
  920. let preE=this.item.previousElementSibling;
  921. if(preE.tagName=="P" && preE.children.length>1){
  922. this.item.parentNode.insertBefore(this.item,preE);
  923. this.saveSort();
  924. }
  925. }
  926. moveDown(){
  927. let nextE=this.item.nextElementSibling;
  928. if(nextE.tagName=="P" && nextE.children.length>1){
  929. this.item.parentNode.insertBefore(nextE,this.item);
  930. this.saveSort();
  931. }
  932. }
  933. del(){
  934. if(this.ruleUrl.id<2){
  935. alert(i18n("cantDel"));
  936. }else if(window.confirm(i18n("confirmDel"))){
  937. for(let u=0;u<rulesData.urls.length;u++){
  938. if(this.ruleUrl.id==rulesData.urls[u].id){
  939. rulesData.urls.splice(u,1);
  940. break;
  941. }
  942. }
  943. for(let u=0;u<rulesData.sort.length;u++){
  944. if(this.ruleUrl.id==rulesData.sort[u]){
  945. rulesData.sort.splice(u,1);
  946. break;
  947. }
  948. }
  949. storage.setItem("importRuleUrl", rulesData);
  950. ruleParser.rules=ruleParser.rules.filter(item=>{return item.from!=this.ruleUrl.id});
  951. storage.setItem("rules", ruleParser.rules);
  952. this.item.parentNode.removeChild(this.item);
  953. //location.reload();
  954. }
  955. }
  956. }
  957. let updateP=document.createElement("p"),i=0;
  958. let now=new Date().getTime(),inUpdate=false;
  959.  
  960.  
  961. let pastDate=(new Date(updateDate)).toString(),passStr;
  962. let passTime=(now-updateDate)/1000;
  963. if(passTime<60){
  964. passStr=i18n("passSec", passTime);
  965. }else if(passTime<60*60){
  966. passStr=i18n("passMin", parseInt(passTime/60));
  967. }else if(passTime<60*60*24){
  968. passStr=i18n("passHour", parseInt(passTime/3600));
  969. }else{
  970. passStr=i18n("passDay", parseInt(passTime/86400));
  971. }
  972.  
  973.  
  974. updateP.className="updateDate";
  975. updateP.innerHTML=passStr;
  976. updateP.title=i18n("update")+" - "+pastDate;
  977. updateP.onclick=e=>{
  978. if(inUpdate)return;
  979. inUpdate=true;
  980. let ruleIndex=0;
  981. storage.setItem("hpRules", []);
  982. function addNextRule(){
  983. if(ruleIndex>=ruleUrls.length){
  984. storage.setItem("ruleLastUpdate", now);
  985. alert(i18n("updateSucc"));
  986. inUpdate=false;
  987. updateP.innerHTML=i18n("passSec", 0);
  988. updateP.title=i18n("update");
  989. }else{
  990. let rule=ruleUrls[ruleIndex++];
  991. ruleParser.addRuleByUrl(rule.url, rule.type, rule.id, ()=>{
  992. addNextRule();
  993. })
  994. }
  995. }
  996. addNextRule();
  997. alert(i18n("beginUpdate"));
  998. };
  999. configCon.insertBefore(updateP, insertPos);
  1000. if(ruleUrls){
  1001. ruleUrls.forEach(ruleUrl=>{
  1002. var rulebar=new Rulebar();
  1003. rulebar.init(ruleUrl);
  1004. });
  1005. }
  1006. let customUrlsTitle=document.createElement("h2");
  1007. customUrlsTitle.innerHTML=i18n("customUrls");
  1008. configCon.insertBefore(customUrlsTitle, insertPos);
  1009. let customUrlsInput=document.createElement("textarea");
  1010. customUrlsInput.style.width="100%";
  1011. customUrlsInput.placeholder="0|http://wedata.net/databases/AutoPagerize/items_all.json";
  1012. configCon.insertBefore(customUrlsInput, insertPos);
  1013.  
  1014. let opacityTitle=document.createElement("h2");
  1015. opacityTitle.innerHTML=i18n("opacity");
  1016. let opacityInput=document.createElement("input");
  1017. opacityInput.value=rulesData.opacity*100;
  1018. opacityInput.type="number";
  1019. opacityInput.style.width="50px";
  1020. opacityInput.style.margin="0 0 0 10px";
  1021. opacityTitle.appendChild(opacityInput);
  1022. configCon.insertBefore(opacityTitle, insertPos);
  1023.  
  1024. let customRulesTitle=document.createElement("h2");
  1025. customRulesTitle.innerHTML=i18n("customRules")
  1026. configCon.insertBefore(customRulesTitle, insertPos);
  1027. let customRulesInput=document.createElement("textarea");
  1028. customRulesInput.style.width="100%";
  1029. customRulesInput.style.height="500px";
  1030. 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]`;
  1031. customRulesInput.value=getFormatJSON(ruleParser.customRules);
  1032. configCon.insertBefore(customRulesInput, insertPos);
  1033. let saveBtn=document.createElement("button");
  1034. saveBtn.innerHTML=i18n("save");
  1035. saveBtn.style.width="100%";
  1036. configCon.insertBefore(saveBtn, insertPos);
  1037. saveBtn.onclick=e=>{
  1038. try{
  1039. storage.setItem("hpRules", []);
  1040. if(customRulesInput.value==""){
  1041. storage.setItem("customRules", "");
  1042. }else{
  1043. let customRules=JSON.parse(customRulesInput.value);
  1044. debug(customRules);
  1045. storage.setItem("customRules", customRules);
  1046. }
  1047. }catch(e){
  1048. debug(e);
  1049. alert("JSON error, check again!");
  1050. return;
  1051. }
  1052. rulesData.opacity=opacityInput.value/100;
  1053. storage.setItem("importRuleUrl", rulesData);
  1054. let customUrls=customUrlsInput.value.trim();
  1055. if(customUrls){
  1056. customUrls=customUrls.split(/\n/);
  1057. for(let c=0;c<customUrls.length;c++){
  1058. let urlArr=customUrls[c].split("|"),url,type=1;
  1059. if(urlArr.length==1){
  1060. url=urlArr[0].trim();
  1061. if(!/^http/.test(url)){
  1062. alert("Wrong url, check again!");
  1063. return;
  1064. }
  1065. }else if(urlArr.length==2){
  1066. type=urlArr[0].trim();
  1067. url=urlArr[1].trim();
  1068. if(!/^http/.test(url)){
  1069. alert("Wrong url, check again!");
  1070. return;
  1071. }
  1072. }else{
  1073. break;
  1074. }
  1075. let maxId=0,hasUrl=false;;
  1076. if(!rulesData.urls){
  1077. rulesData.urls=[];
  1078. maxId=1;
  1079. }else{
  1080. rulesData.urls.forEach(u=>{
  1081. if(maxId<u.id){
  1082. maxId=u.id;
  1083. }
  1084. if(u.url==url){
  1085. hasUrl=true;
  1086. }
  1087. });
  1088. if(hasUrl)break;
  1089. }
  1090. rulesData.urls.push({id:maxId+1,url:url,type:type});
  1091. rulesData.sort.push(maxId+1);
  1092. storage.setItem("importRuleUrl", rulesData);
  1093. }
  1094. }
  1095. alert("Modified successfully");
  1096. location.reload();
  1097. };
  1098. }
  1099.  
  1100. function objIsArr(obj) {
  1101. return obj &&
  1102. typeof obj === 'object' &&
  1103. typeof obj.length === 'number' &&
  1104. !(obj.propertyIsEnumerable('length'));
  1105. }
  1106.  
  1107. function getFormatJSON(obj){
  1108. if(!objIsArr(obj))return "";
  1109. let ret="[\n";
  1110. let len=obj.length,i=0,isLast;
  1111. obj.forEach(item=>{
  1112. ret+=" {\n";
  1113. let iLen=Object.keys(item).length,j=0;
  1114. for(let key in item){
  1115. isLast=(++j)==iLen;
  1116. let value=item[key];
  1117. if(objIsArr(value)){
  1118. let vstr="[",v=0,vIsLast=false;
  1119. value.forEach(vi=>{
  1120. vIsLast=(++v)==value.length;
  1121. vstr+="\""+vi.replace(/\\/g,"\\\\")+"\""+(vIsLast?"":",");
  1122. });
  1123. vstr+="]";
  1124. ret+=" \""+key+"\":"+vstr+""+(isLast?"":",")+"\n";
  1125. }else{
  1126. if(typeof value=="string"){
  1127. value=value.replace(/\\/g,"\\\\");
  1128. }
  1129. ret+=" \""+key+"\":\""+value+"\""+(isLast?"":",")+"\n";
  1130. }
  1131. }
  1132. isLast=(++i)==len;
  1133. ret+=" }"+(isLast?"":",")+"\n";
  1134. });
  1135. ret+="]";
  1136. return ret;
  1137. }
  1138.  
  1139. function initRules(callback) {
  1140. /*0 wedata格式,1 pagetual格式*/
  1141. ruleUrls=[
  1142. {
  1143. id:0,
  1144. url:'https://raw.githubusercontent.com/hoothin/UserScripts/master/Pagetual/pagetualRules.json',
  1145. type:1
  1146. },
  1147. {
  1148. id:1,
  1149. url:'http://wedata.net/databases/AutoPagerize/items_all.json',
  1150. type:0,
  1151. }
  1152. ];var i=0,j=0;
  1153.  
  1154. ruleParser.initSavedRules(()=>{
  1155. storage.getItem("importRuleUrl", data=>{
  1156. if(data){
  1157. rulesData=data;
  1158. if(data.urls)ruleUrls=ruleUrls.concat(data.urls);
  1159. if(data.sort){
  1160. let urls=[];
  1161. data.sort.forEach(id=>{
  1162. for(let s=0;s<ruleUrls.length;s++){
  1163. if(id==ruleUrls[s].id){
  1164. urls.push(ruleUrls[s]);
  1165. break;
  1166. }
  1167. }
  1168. });
  1169. ruleUrls=urls;
  1170. }
  1171. }
  1172. if(typeof(rulesData.opacity)=="undefined"){
  1173. rulesData.opacity=0.3;
  1174. }
  1175. storage.getItem("forceState_"+location.host, v=>{
  1176. storage.getItem("ruleLastUpdate", date=>{
  1177. forceState=v||0;
  1178. updateDate=date;
  1179. initConfig();
  1180. if(forceState==1)return;
  1181. let now=new Date().getTime();
  1182. if(!date || now-date>3*24*60*60*1000){
  1183. storage.setItem("ruleLastUpdate", now);
  1184. storage.setItem("hpRules", []);
  1185. let ruleIndex=0;
  1186. function addNextRule(){
  1187. if(ruleIndex>=ruleUrls.length){
  1188. callback();
  1189. }else{
  1190. let rule=ruleUrls[ruleIndex++];
  1191. ruleParser.addRuleByUrl(rule.url, rule.type, rule.id, ()=>{
  1192. addNextRule();
  1193. })
  1194. }
  1195. }
  1196. addNextRule();
  1197. }else{
  1198. callback();
  1199. }
  1200. });
  1201. });
  1202. });
  1203. });
  1204. }
  1205.  
  1206. function requestDoc(url, callback){
  1207. _GM_xmlhttpRequest({
  1208. url: url,
  1209. method: 'GET',
  1210. overrideMimeType:"text/html;charset="+document.charset,
  1211. onload: function(res) {
  1212. var doc=null;
  1213. try {
  1214. doc=document.implementation.createHTMLDocument('');
  1215. doc.documentElement.innerHTML=res.response;
  1216. }
  1217. catch (e) {
  1218. debug('parse error'+e.toString());
  1219. }
  1220. let pageElement=ruleParser.getPageElement(doc);
  1221. //只有1的話怕不是圖片哦
  1222. if(pageElement && (pageElement.length>1 || (pageElement.length==1 && pageElement[0].tagName!="IMG") )){
  1223. callback(pageElement);
  1224. ruleParser.insertPage(doc, pageElement, url);
  1225. }else{
  1226. requestFromIframe(url, (doc, eles)=>{
  1227. callback(eles);
  1228. if(eles){
  1229. ruleParser.insertPage(doc, eles, url);
  1230. }
  1231. });
  1232. }
  1233. },
  1234. onerror: function(e){
  1235. debug(e);
  1236. callback(false);
  1237. }
  1238. });
  1239. }
  1240.  
  1241. var failFromIframe=0;
  1242. function requestFromIframe(url, callback){
  1243. let orgPage,curPage;
  1244. let iframe = document.createElement('iframe');
  1245. iframe.name = 'pagetual-iframe';
  1246. iframe.width = '100%';
  1247. iframe.height = '0';
  1248. iframe.frameBorder = '0';
  1249. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1250. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1251. iframe.addEventListener("load", e=>{
  1252. setTimeout(()=>{
  1253. let tryTimes=0;
  1254. function checkIframe(){
  1255. try{
  1256. let doc=iframe.contentWindow.document;
  1257. let eles=ruleParser.getPageElement(doc, iframe.contentWindow);
  1258. if(eles && eles.length>0){
  1259. callback(doc, eles);
  1260. }else if(tryTimes++ < 2){
  1261. setTimeout(()=>{
  1262. checkIframe();
  1263. },500);
  1264. return;
  1265. }else{
  1266. if(failFromIframe++ > 2){
  1267. failFromIframe=0;
  1268. isPause=true;
  1269. callback(false, false);
  1270. }else{
  1271. callback(false, false);
  1272. }
  1273. }
  1274. }catch(e){
  1275. isPause=true;
  1276. callback(false, false);
  1277. }
  1278. document.body.removeChild(iframe);
  1279. }
  1280. checkIframe();
  1281. },300);
  1282. });
  1283. iframe.src=url;
  1284. document.body.appendChild(iframe);
  1285. }
  1286.  
  1287. function initPage(){
  1288. ruleParser.initPage(()=>{
  1289. initListener();
  1290. nextPage();
  1291. });
  1292. }
  1293.  
  1294. function initView(){
  1295. _GM_addStyle(`
  1296. .pagetual_pageBar.stop {
  1297. -webkit-filter: invert(100%);
  1298. filter: invert(100%);
  1299. opacity: 1;
  1300. }
  1301. .pagetual_pageBar.hide {
  1302. display: none!important;
  1303. }
  1304. .pagetual_pageBar {
  1305. opacity: ${rulesData.opacity};
  1306. display: ${rulesData.opacity==0?"none!important":"unset"};
  1307. }
  1308. .pagetual_pageBar:hover {
  1309. opacity: 1;
  1310. }
  1311. .pagetual_pageBar>span {
  1312. vertical-align: super;
  1313. }
  1314.  
  1315. .pagetual_pageBar>span>svg:hover {
  1316. animation: touhouAni 1s infinite;
  1317. }
  1318.  
  1319. @keyframes touhouAni{
  1320. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  1321. to {transform: rotate(360deg);}
  1322. }
  1323. @-webkit-keyframes touhouAni{
  1324. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  1325. to {transform: rotate(360deg);}
  1326. }
  1327. `);
  1328. }
  1329. var loading=document.createElement("div");
  1330. loading.style.cssText="display:none;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;";
  1331. loading.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><svg width="120" height="30" viewBox="0 0 120 30" fill="#000000A0" style="display: block;position: initial;margin: auto;shape-rendering: auto;vertical-align: middle;visibility: visible;width: initial;height: initial;"><circle cx="15" cy="15" r="15"><animate attributeName="r" from="15" to="15" begin="0s" dur="0.8s" values="15;9;15" calcMode="linear" repeatCount="indefinite"></animate><animate attributeName="fill-opacity" from="1" to="1" begin="0s" dur="0.8s" values="1;.5;1" calcMode="linear" repeatCount="indefinite"></animate></circle><circle cx="60" cy="15" r="9" fill-opacity="0.3"><animate attributeName="r" from="9" to="9" begin="0s" dur="0.8s" values="9;15;9" calcMode="linear" repeatCount="indefinite"></animate><animate attributeName="fill-opacity" from="0.5" to="0.5" begin="0s" dur="0.8s" values=".5;1;.5" calcMode="linear" repeatCount="indefinite"></animate></circle><circle cx="105" cy="15" r="15"><animate attributeName="r" from="15" to="15" begin="0s" dur="0.8s" values="15;9;15" calcMode="linear" repeatCount="indefinite"></animate><animate attributeName="fill-opacity" from="1" to="1" begin="0s" dur="0.8s" values="1;.5;1" calcMode="linear" repeatCount="indefinite"></animate></circle></svg>`;
  1332. document.body.appendChild(loading);
  1333.  
  1334. var upSvg=`<svg style="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>`;
  1335. var downSvg=`<svg style="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>`;
  1336. var pageBarStyle=`box-shadow: 0px 0px 10px 0px #000000aa;border-radius: 20px;background-color: rgb(240 240 240 / 80%);visibility: visible; position: initial; width: auto; height: 30px; float: none; clear: both; margin: 20px auto; text-align: center; display: block;`;
  1337. 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);`;
  1338.  
  1339. var isPause=false,isLoading=false,curPage=1,forceState=0;
  1340.  
  1341. function changeStop(stop, hide){
  1342. isPause=stop;
  1343. [].forEach.call(document.querySelectorAll(".pagetual_pageBar"), bar=>{
  1344. if(isPause){
  1345. bar.classList.add("stop");
  1346. if(hide)bar.classList.add("hide");
  1347. }else{
  1348. bar.classList.remove("stop");
  1349. if(hide)bar.classList.remove("hide");
  1350. }
  1351. });
  1352. }
  1353.  
  1354. function initListener(){
  1355. document.addEventListener('scroll', e=>{
  1356. setTimeout(()=>{
  1357. if(!isPause && !isLoading){
  1358. let scrolly=window.scrollY;
  1359. let windowHeight=window.innerHeight;
  1360. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  1361. if(scrollH-scrolly-windowHeight<1000){
  1362. nextPage();
  1363. }
  1364. }
  1365. },100);
  1366. }, false);
  1367. document.addEventListener('dblclick', e=>{
  1368. setTimeout(()=>{
  1369. changeStop(!isPause, true);
  1370. },300);
  1371. });
  1372. }
  1373.  
  1374. function createPageBar(url){
  1375. let insert=ruleParser.getInsert();
  1376. if(!insert || !insert.parentNode)return;
  1377. curPage++;
  1378. let inTable=insert.tagName=="TR" || insert.previousElementSibling.tagName=="TR" || insert.tagName=="TBODY" || insert.previousElementSibling.tagName=="TBODY";
  1379. let inLi=insert.tagName=="LI" || insert.previousElementSibling.tagName=="LI";
  1380. let pageBar=document.createElement(inTable?"tr":"div");
  1381. let upSpan=document.createElement("span");
  1382. let downSpan=document.createElement("span");
  1383. let pageText=document.createElement("a");
  1384. pageBar.className="pagetual_pageBar";
  1385. pageBar.id="pagetual_pageBar";
  1386. if(isPause){
  1387. pageBar.classList.add("stop");
  1388. }
  1389. pageBar.style.cssText=pageBarStyle;
  1390. pageBar.title=i18n(isPause?"enable":"disable");
  1391. upSpan.innerHTML=upSvg;
  1392. upSpan.title=i18n("toTop");
  1393. downSpan.innerHTML=downSvg;
  1394. downSpan.title=i18n("toBottom");
  1395. pageText.href=url;
  1396. pageText.style=pageTextStyle;
  1397. pageText.innerHTML="Page "+curPage;
  1398. pageText.title=i18n("current");
  1399. pageBar.appendChild(upSpan);
  1400. pageBar.appendChild(pageText);
  1401. pageBar.appendChild(downSpan);
  1402. if(inTable){
  1403. let example=(insert.tagName=="TR" || insert.tagName=="TBODY")?insert:insert.previousElementSibling;
  1404. let tdNum=example.tagName=="TR"?example.children.length:example.querySelector("tr").children.length;
  1405. pageBar.style.display="table-row";
  1406. let td=document.createElement("td");
  1407. td.colSpan=tdNum;
  1408. td.appendChild(upSpan);
  1409. td.appendChild(pageText);
  1410. td.appendChild(downSpan);
  1411. pageBar.appendChild(td);
  1412. }
  1413.  
  1414. upSpan.addEventListener("click", e=>{
  1415. changeStop(true);
  1416. document.body.scrollTop=0;
  1417. document.documentElement.scrollTop=0;
  1418. e.preventDefault();
  1419. e.stopPropagation();
  1420. });
  1421. downSpan.addEventListener("click", e=>{
  1422. changeStop(true);
  1423. document.body.scrollTop=9999999;
  1424. document.documentElement.scrollTop=9999999;
  1425. e.preventDefault();
  1426. e.stopPropagation();
  1427. });
  1428. pageBar.addEventListener("click", e=>{
  1429. changeStop(!isPause);
  1430. pageBar.title=i18n(isPause?"enable":"disable");
  1431. });
  1432. pageText.addEventListener("click", e=>{
  1433. e.stopPropagation();
  1434. });
  1435. pageBar.style.width=parseInt(_unsafeWindow.getComputedStyle(insert.parentNode).width)*.9+"px";
  1436. if(inLi){
  1437. pageBar.style.width="auto";
  1438. pageBar.style.minWidth="200px";
  1439. let line=document.createElement("li");
  1440. line.appendChild(pageBar);
  1441. if(ruleParser.curSiteRule.insertPos==2){
  1442. insert.appendChild(line);
  1443. }else{
  1444. insert.parentNode.insertBefore(line, insert);
  1445. }
  1446. }else{
  1447. if(ruleParser.curSiteRule.insertPos==2){
  1448. insert.appendChild(pageBar);
  1449. }else{
  1450. insert.parentNode.insertBefore(pageBar, insert);
  1451. }
  1452. }
  1453. return pageBar;
  1454. }
  1455.  
  1456. var emuIframe;
  1457. function emuPage(callback){
  1458. let orgPage,curPage,iframeDoc,times=0;
  1459. function checkPage(){
  1460. if(isPause)return;
  1461. try{
  1462. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  1463. }catch(e){
  1464. isPause=true;
  1465. callback(false, false);
  1466. return;
  1467. }
  1468. if(!orgPage){
  1469. orgPage=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true);
  1470. if(orgPage)orgPage=orgPage[0];
  1471. let nextLink=ruleParser.getNextLink(iframeDoc);
  1472. if(orgPage && nextLink){
  1473. let display=iframeDoc.defaultView.getComputedStyle(nextLink).display;
  1474. if(display=="none"){
  1475. isPause=true;
  1476. callback(false, false);
  1477. }else{
  1478. nextLink.click();
  1479. setTimeout(()=>{
  1480. checkPage();
  1481. },1000);
  1482. }
  1483. }else{
  1484. isPause=true;
  1485. callback(false, false);
  1486. }
  1487. return;
  1488. }
  1489. if(times++ > 10){
  1490. isPause=true;
  1491. callback(false, false);
  1492. return;
  1493. }
  1494. let eles=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true);
  1495. if(!eles || eles.length==0){
  1496. isPause=true;
  1497. callback(false, false);
  1498. }else if(orgPage == eles[0]){
  1499. setTimeout(()=>{
  1500. checkPage();
  1501. },500);
  1502. }else{
  1503. callback(iframeDoc, eles);
  1504. }
  1505. }
  1506. if(!emuIframe){
  1507. emuIframe = document.createElement('iframe');
  1508. emuIframe.name = 'pagetual-iframe';
  1509. emuIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1510. emuIframe.width = '100%';
  1511. emuIframe.height = '0';
  1512. emuIframe.frameBorder = '0';
  1513. emuIframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1514. emuIframe.addEventListener("load", e=>{
  1515. setTimeout(()=>{
  1516. checkPage();
  1517. },300);
  1518. });
  1519. emuIframe.src=location.href;
  1520. document.body.appendChild(emuIframe);
  1521. }else{
  1522. checkPage();
  1523. }
  1524. }
  1525.  
  1526. function forceIframe(url, callback){
  1527. let curIframe = document.createElement('iframe');
  1528. curIframe.name = 'pagetual-iframe';
  1529. curIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1530. curIframe.frameBorder = '0';
  1531. curIframe.scrolling="no";
  1532. 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;';
  1533. curIframe.addEventListener("load", e=>{
  1534. let iframeDoc=curIframe.contentDocument || curIframe.contentWindow.document;
  1535. //let eles=ruleParser.getPageElement(iframeDoc, curIframe.contentWindow);
  1536. //if(eles && eles.length>0){
  1537. ruleParser.insertPage(iframeDoc, [], url);
  1538. callback(curIframe, true);
  1539. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  1540. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  1541. setTimeout(()=>{
  1542. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  1543. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  1544. },300);
  1545. //curIframe.scrollIntoView();
  1546. /*}else{
  1547. isPause=true;
  1548. callback(false, false);
  1549. curIframe.parentNode.removeChild(curIframe);
  1550. }*/
  1551. });
  1552. curIframe.src=url;
  1553. let insert=ruleParser.getInsert();
  1554. document.body.appendChild(curIframe);
  1555. return curIframe;
  1556. }
  1557.  
  1558. function nextPage(){
  1559. if(isPause || isLoading)return;
  1560. let nextLink=ruleParser.nextLinkHref;
  1561. let insert=ruleParser.getInsert();
  1562. if(nextLink && insert){
  1563. let isJs=/^(javascript|#)/.test(nextLink.replace(location.href,""));
  1564. if(location.protocol=="https:" && /^http:/.test(nextLink)){
  1565. nextLink=nextLink.replace(/^http/,"https");
  1566. }
  1567. isLoading=true;
  1568. loading.style.display="";
  1569. if(ruleParser.curSiteRule.pageElementByJs){
  1570. var over=ele=>{
  1571. isLoading=false;
  1572. loading.style.display="none";
  1573. if(ele){
  1574. createPageBar(nextLink);
  1575. ruleParser.insertPage(null, ele, null);
  1576. }else{
  1577. isPause=true;
  1578. }
  1579. };
  1580. Function("over",'"use strict";' + ruleParser.curSiteRule.pageElementByJs)(over);
  1581. }else if(ruleParser.curSiteRule.action==1 && !isJs){
  1582. requestFromIframe(nextLink, (doc, eles)=>{
  1583. isLoading=false;
  1584. loading.style.display="none";
  1585. if(eles){
  1586. createPageBar(nextLink);
  1587. ruleParser.insertPage(doc, eles, nextLink);
  1588. }
  1589. });
  1590. }else if(forceState==2 && !isJs){
  1591. forceIframe(nextLink, (iframe, eles)=>{
  1592. isLoading=false;
  1593. loading.style.display="none";
  1594. //if(eles){
  1595. let pageBar=createPageBar(nextLink);
  1596. iframe.parentNode.insertBefore(pageBar, iframe);
  1597. //}
  1598. });
  1599. }else{
  1600. if(!isJs){
  1601. requestDoc(nextLink, (eles)=>{
  1602. isLoading=false;
  1603. loading.style.display="none";
  1604. if(eles){
  1605. createPageBar(nextLink);
  1606. }
  1607. });
  1608. }else{
  1609. emuPage((doc, eles)=>{
  1610. isLoading=false;
  1611. loading.style.display="none";
  1612. if(eles){
  1613. createPageBar(nextLink);
  1614. ruleParser.insertPage(doc, eles, "");
  1615. }
  1616. });
  1617. }
  1618. }
  1619. }
  1620. }
  1621.  
  1622. function init(){
  1623. initRules(()=>{
  1624. initView();
  1625. initPage();
  1626. });
  1627. }
  1628. init();
  1629. })();