东方永页机

自动翻页

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

  1. // ==UserScript==
  2. // @name Pagetual
  3. // @name:zh-CN 东方永页机
  4. // @name:zh-TW 東方永頁機
  5. // @namespace hoothin
  6. // @version 0.2
  7. // @description Simple Auto Page
  8. // @description:zh-CN 自动翻页
  9. // @description:zh-TW 自動翻頁
  10. // @author hoothin
  11. // @include http*
  12. // @license MIT
  13. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  14. // @grant GM_xmlhttpRequest
  15. // @grant GM_registerMenuCommand
  16. // @grant GM_notification
  17. // @grant GM_getValue
  18. // @grant GM_setValue
  19. // @grant GM_addStyle
  20. // @grant GM.xmlhttpRequest
  21. // @grant GM.registerMenuCommand
  22. // @grant GM.notification
  23. // @grant GM.getValue
  24. // @grant GM.setValue
  25. // @grant GM.addStyle
  26. // @connect wedata.net
  27. // @connect githubusercontent.com
  28. // ==/UserScript==
  29.  
  30. (function() {
  31. 'use strict';
  32.  
  33. if (window.name === 'pagetual-iframe') {
  34. var domloaded = function (){
  35. window.scroll(window.scrollX, 99999);
  36. window.parent.postMessage('pagetual-iframe:DOMLoaded', '*');
  37. };
  38. if(window.opera){
  39. document.addEventListener('DOMContentLoaded', domloaded, false);
  40. } else {
  41. domloaded();
  42. }
  43. return;
  44. }
  45.  
  46. if(window.top != window.self){
  47. return;
  48. }
  49.  
  50. const lang = navigator.appName=="Netscape"?navigator.language:navigator.userLanguage;
  51. var i18n=(name, param)=>{
  52. let config={};
  53. switch (lang){
  54. case "zh-CN":
  55. case "zh-SG":
  56. config={
  57. saveCurrent:"保存当前设置",
  58. disable:"暂时禁用",
  59. enable:"启用翻页",
  60. toTop:"回到顶部",
  61. toBottom:"前往页尾",
  62. current:"当前页",
  63. forceIframe:"强制拼接",
  64. configure:"打开配置页",
  65. update:"立即更新规则",
  66. passSec:"更新于 #t# 秒前",
  67. passMin:"更新于 #t# 分钟前",
  68. passHour:"更新于 #t# 小时前",
  69. passDay:"更新于 #t# 天前",
  70. cantDel:"无法删除内置规则",
  71. confirmDel:"是否确认要删除此规则?",
  72. updateSucc:"更新成功",
  73. beginUpdate:"正在更新,请稍候",
  74. customUrls:"导入规则url,一行一条,AutoPagerize 格式规则需要以\"0|\"开头",
  75. customRules:"输入【东方永页机】格式的自定义规则",
  76. save:"保存设置"
  77. };
  78. break;
  79. case "zh-TW":
  80. case "zh-HK":
  81. config={
  82. disable:"暫時禁用",
  83. enable:"啟用翻頁",
  84. toTop:"回到頂部",
  85. toBottom:"前往頁尾",
  86. current:"當前頁",
  87. forceIframe:"強制拼接",
  88. configure:"打開配置頁",
  89. update:"立即更新規則",
  90. passSec:"更新于 #t# 秒前",
  91. passMin:"更新于 #t# 分鐘前",
  92. passHour:"更新于 #t# 小時前",
  93. passDay:"更新于 #t# 天前",
  94. cantDel:"無法刪除内置規則",
  95. confirmDel:"是否確認要刪除此規則?",
  96. updateSucc:"更新成功",
  97. beginUpdate:"正在更新,請稍候",
  98. customUrls:"導入規則url,一行一條,AutoPagerize 格式規則需要以\"0|\"開頭",
  99. customRules:"輸入【東方永頁機】格式的自定義規則",
  100. save:"存儲設置"
  101. };
  102. break;
  103. default:
  104. config={
  105. disable:"Disable",
  106. enable:"Enable",
  107. toTop:"To Top",
  108. toBottom:"To Bottom",
  109. current:"Current Page",
  110. forceIframe:"Force to join",
  111. configure:"Configure",
  112. update:"Update rules from url now",
  113. passSec:"Updated #t# seconds ago",
  114. passMin:"Updated #t# minutes ago",
  115. passHour:"Updated #t# hours ago",
  116. passDay:"Updated #t# days ago",
  117. cantDel:"Can't delete buildin rules",
  118. confirmDel:"Are you sure you want to delete this rule?",
  119. updateSucc:"Update succeeded",
  120. beginUpdate:"Begin update, wait a minute please",
  121. customUrls:"Import rule url, One url per line, rules on AutoPagerize format need to start with \"0|\"",
  122. customRules:"Input custom rules with [Pagetual] format",
  123. save:"Save"
  124. };
  125. break;
  126. }
  127. return config[name]?config[name].replace("#t#",param):name;
  128. };
  129.  
  130. var enableDebug=true;
  131. var debug=str=>{
  132. if(enableDebug){
  133. console.debug(str);
  134. }
  135. };
  136.  
  137. var _GM_xmlhttpRequest,_GM_registerMenuCommand,_GM_notification,_GM_addStyle;
  138. if(typeof GM_xmlhttpRequest!='undefined'){
  139. _GM_xmlhttpRequest=GM_xmlhttpRequest;
  140. }else if(typeof GM!='undefined' && typeof GM.xmlhttpRequest!='undefined'){
  141. _GM_xmlhttpRequest=GM.xmlhttpRequest;
  142. }
  143. if(typeof GM_registerMenuCommand!='undefined'){
  144. _GM_registerMenuCommand=GM_registerMenuCommand;
  145. }else if(typeof GM!='undefined' && typeof GM.registerMenuCommand!='undefined'){
  146. _GM_registerMenuCommand=GM.registerMenuCommand;
  147. }
  148. if(typeof GM_notification!='undefined'){
  149. _GM_notification=GM_notification;
  150. }else if(typeof GM!='undefined' && typeof GM.notification!='undefined'){
  151. _GM_notification=GM.notification;
  152. }
  153. if(typeof GM_addStyle!='undefined'){
  154. _GM_addStyle=GM_addStyle;
  155. }else if(typeof GM!='undefined' && typeof GM.addStyle!='undefined'){
  156. _GM_addStyle=GM.addStyle;
  157. }
  158.  
  159. if(typeof _GM_xmlhttpRequest=='undefined')_GM_xmlhttpRequest=(f)=>{};
  160. if(typeof _GM_registerMenuCommand=='undefined')_GM_registerMenuCommand=(s,f)=>{};
  161. if(typeof _GM_notification=='undefined')_GM_notification=(s)=>{};
  162. var _unsafeWindow=(typeof unsafeWindow=='undefined')?window:unsafeWindow;
  163. var storage={
  164. supportGM: typeof GM_getValue=='function' && typeof GM_getValue('a','b')!='undefined',
  165. supportGMPromise: typeof GM!='undefined' && typeof GM.getValue=='function' && typeof GM.getValue('a','b')!='undefined',
  166. mxAppStorage:(function(){
  167. try{
  168. return window.external.mxGetRuntime().storage;
  169. }catch(e){
  170. }
  171. })(),
  172. operaUJSStorage:(function(){
  173. try{
  174. return window.opera.scriptStorage;
  175. }catch(e){
  176. }
  177. })(),
  178. setItem:function(key,value){
  179. if(this.operaUJSStorage){
  180. this.operaUJSStorage.setItem(key,value);
  181. }else if(this.mxAppStorage){
  182. this.mxAppStorage.setConfig(key,value);
  183. }else if(this.supportGM){
  184. GM_setValue(key,value);
  185. }else if(this.supportGMPromise){
  186. GM.setValue(key,value);
  187. }else if(window.localStorage){
  188. window.localStorage.setItem(key,value);
  189. }
  190. },
  191. getItem:function(key,cb){
  192. var value;
  193. if(this.operaUJSStorage){
  194. value=this.operaUJSStorage.getItem(key);
  195. }else if(this.mxAppStorage){
  196. value=this.mxAppStorage.getConfig(key);
  197. }else if(this.supportGM){
  198. value=GM_getValue(key);
  199. }else if(this.supportGMPromise){
  200. value=GM.getValue(key).then(v=>{cb(v)});
  201. return;
  202. }else if(window.localStorage){
  203. value=window.localStorage.getItem(key);
  204. };
  205. cb(value);
  206. }
  207. };
  208. _GM_registerMenuCommand(i18n("forceIframe"), ()=>{
  209. if(ruleParser.curSiteRule.action==2){
  210. ruleParser.curSiteRule.action=0;
  211. }else{
  212. ruleParser.curSiteRule.action=2;
  213. }
  214. ruleParser.saveCurSiteRule();
  215. location.reload();
  216. });
  217. _GM_registerMenuCommand(i18n("configure"), ()=>{
  218. location.href="https://github.com/hoothin/UserScripts/tree/master/Pagetual";
  219. });
  220.  
  221. function getElementByXpath(xpath, contextNode, doc){
  222. doc = doc || document;
  223. contextNode = contextNode || doc;
  224. try {
  225. var result = doc.evaluate(xpath, contextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
  226. return result.singleNodeValue && result.singleNodeValue.nodeType === 1 && result.singleNodeValue;
  227. } catch (err) {
  228. throw new Error(`Invalid xpath: ${xpath}`);
  229. }
  230. }
  231.  
  232. function getAllElementsByXpath(xpath, contextNode, doc){
  233. doc = doc || document;
  234. contextNode = contextNode || doc;
  235. var result = [];
  236. try {
  237. var query = doc.evaluate(xpath, contextNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  238. for (var i = 0; i < query.snapshotLength; i++) {
  239. var node = query.snapshotItem(i);
  240. if (node.nodeType === 1) result.push(node);
  241. }
  242. } catch (err) {
  243. throw new Error(`Invalid xpath: ${xpath}`);
  244. }
  245. return result;
  246. }
  247.  
  248. class RuleParser {
  249. /*
  250. name
  251. url
  252. enable
  253. type
  254. action 0 div 1 iframe 2強行塞入
  255. nextLink 下一頁的xpath或者selector
  256. pageElement //頁面主體的xpath或者selector
  257. lazyImgSrc //圖片延後加載的屬性直接賦值到src
  258. css //添加樣式
  259. insert: '//div[@id="res"]',
  260. insertPos: 1, 1 之前 2 裏面最後
  261. pageAction:(document, eles) //對每一個插入的頁面進行修剪
  262. init:(document) // 對主頁面進行處理
  263. */
  264. constructor() {
  265. this.customRules=[
  266. {
  267. from:2,
  268. name:"yande",
  269. type:1,
  270. action:0,
  271. url:"^https:\/\/yande\.re\/",
  272. pageElement:"ul#post-list-posts>li",
  273. nextLink:"a.next_page",
  274. css:".javascript-hide {display: inline-block !important;}"
  275. },
  276. {
  277. from:2,
  278. name:"tieba",
  279. type:1,
  280. action:1,
  281. url:"^https:\/\/tieba\.baidu.com\/f\?kw=",
  282. pageElement:"ul#thread_list>li",
  283. nextLink:".next.pagination-item "
  284. }
  285. ];
  286. this.rules=[];
  287. this.pageDoc=document;
  288. this.curUrl=location.href;
  289. this.curSiteRule={};
  290. }
  291.  
  292. initSavedRules(callback){
  293. var self=this;
  294. storage.getItem("customRules", customRules=>{
  295. if(customRules)self.customRules=customRules;
  296. storage.getItem("rules", rules=>{
  297. if(rules)this.rules=rules;
  298. callback();
  299. });
  300. });
  301. }
  302.  
  303. saveCurSiteRule(){
  304. if(!this.curSiteRule || !this.curSiteRule.url)return;
  305. this.customRules=this.customRules.filter(item=>{return item.url!=this.curSiteRule.url});
  306. this.customRules.push(this.curSiteRule);
  307. storage.setItem("customRules", this.customRules);
  308. }
  309.  
  310. requestJSON(url, callback){
  311. _GM_xmlhttpRequest({
  312. url: url,
  313. onload: function(res) {
  314. let json=null;
  315. try{
  316. json=JSON.parse(res.response);
  317. }catch(e){
  318. debug(e);
  319. }
  320. callback(json);
  321. }
  322. });
  323. }
  324.  
  325. formatRule(item, type, from){
  326. switch(type){
  327. case 0:
  328. return {
  329. from:from,
  330. type:type,
  331. name:item.name,
  332. action:item.data.forceIframe=="true"?1:0,
  333. url:item.data.url,
  334. pageElement:item.data.pageElement,
  335. nextLink:item.data.nextLink,
  336. insert:item.data.insertBefore,
  337. insertPos:1,
  338. updatedAt:item.data.updated_at,
  339. css:item.data.Stylus+item.data.CSS,
  340. pageAction:item.data.bookmarklet
  341. };
  342. break;
  343. case 1:
  344. default:
  345. item.from=from;
  346. item.type=type;
  347. return item;
  348. break;
  349. }
  350. return null;
  351. }
  352.  
  353. addRuleByUrl(url, type, from, callback) {
  354. this.requestJSON(url, json=>{
  355. this.addRules(json, type, from);
  356. storage.setItem("rules", this.rules);
  357. callback();
  358. });
  359. }
  360.  
  361. addRules(rules, type, from) {
  362. if(rules && rules.length>0){
  363. this.rules=this.rules.filter(item=>{return item.from!=from});
  364. rules.forEach(item=>{
  365. let rule=this.formatRule(item, type, from);
  366. if(rule){
  367. this.rules.push(rule);
  368. }
  369. });
  370. }
  371. }
  372.  
  373. getRule() {
  374. if(this.curSiteRule && this.curSiteRule.url){
  375. return this.curSiteRule;
  376. }
  377. var self=this;
  378. for(let i in this.customRules){
  379. let rule=this.customRules[i];
  380. if(rule.enable==0)continue;
  381. let urlReg=new RegExp(rule.url, "i");
  382. if(urlReg.test(location.href)){
  383. let pageElement,nextLink,insert;
  384. if(rule.pageElement)pageElement=document.querySelector(rule.pageElement);
  385. if(rule.nextLink)nextLink=document.querySelector(rule.nextLink);
  386. if(rule.insert)insert=document.querySelector(rule.insert);
  387. if((rule.pageElement && !pageElement) ||
  388. (rule.nextLink && !nextLink) ||
  389. (rule.insert && !insert)){
  390. continue;
  391. }
  392. this.curSiteRule=rule;
  393. debug(rule);
  394. return rule;
  395. }
  396. }
  397. for(let i in this.rules){
  398. let rule=this.rules[i];
  399. if(rule.enable==0)continue;
  400. let urlReg=new RegExp(rule.url, "i");
  401. if(urlReg.test(location.href)){
  402. let pageElement,nextLink,insert;
  403. if(rule.pageElement)pageElement=rule.type==0?getElementByXpath(rule.pageElement):document.querySelector(rule.pageElement);
  404. if(rule.nextLink)nextLink=rule.type==0?getElementByXpath(rule.nextLink):document.querySelector(rule.nextLink);
  405. if(rule.insert)insert=rule.type==0?getElementByXpath(rule.insert):document.querySelector(rule.insert);
  406. if((rule.pageElement && !pageElement) ||
  407. (rule.nextLink && !nextLink) ||
  408. (rule.insert && !insert)){
  409. continue;
  410. }
  411. this.curSiteRule=rule;
  412. debug(rule);
  413. return rule;
  414. }
  415. }
  416. this.curSiteRule={};
  417. this.curSiteRule.url=location.href.replace(/\./g,"\\.");
  418. return null;
  419. }
  420.  
  421. geneSelector(ele){
  422. let selector=ele.tagName;
  423. //Google id class都是隨機。百度更過分,style script順序都是隨機的
  424. //if(ele.id) selector += '#' + ele.id;
  425. //if(ele.classList) selector += [].map.call(ele.classList,d=>'.'+d).join('');
  426. let parent = ele.parentElement;
  427. if(parent){
  428. let i,j=0;
  429. for(i=0;i<parent.children.length;i++){
  430. if(parent.children[i].tagName==selector){
  431. j++;
  432. if(parent.children[i]==ele){
  433. break;
  434. }
  435. }
  436. }
  437. selector = this.geneSelector(parent) + ' > ' + selector + (parent.tagName=="HTML"?"":`:nth-of-type(${j})`);
  438. }
  439. return selector;
  440. }
  441.  
  442. getPageElement(doc) {
  443. let pageElement=null;
  444. let self=this;
  445. if(this.curSiteRule.pageElement){
  446. pageElement=this.curSiteRule.type==0?getAllElementsByXpath(this.curSiteRule.pageElement,doc):doc.querySelectorAll(this.curSiteRule.pageElement);
  447. }
  448. if(!pageElement && !this.curSiteRule.pageElement){
  449. let body=doc.body,bodyHeight=parseInt(_unsafeWindow.getComputedStyle(body).height);
  450. function checkElement(ele){
  451. let curHeight=parseInt(_unsafeWindow.getComputedStyle(ele).height);
  452. if(curHeight/bodyHeight<=0.6)return null;
  453. if(ele.children.length==0){
  454. self.curSiteRule.pageElement=self.geneSelector(ele.parentNode)+">"+ele.tagName;
  455. self.curSiteRule.type=1;
  456. debug(self.curSiteRule.pageElement);
  457. return [ele];
  458. }
  459. let i,maxHeight=curHeight*0.35,curMaxEle=null,curMaxArea=0;
  460. for(i=0;i<ele.children.length;i++){
  461. let curNode=ele.children[i];
  462. let h=parseInt(_unsafeWindow.getComputedStyle(curNode).height);
  463. let w=parseInt(_unsafeWindow.getComputedStyle(curNode).width);
  464. if(isNaN(h) || isNaN(w))continue;
  465. let a=h*w+h;
  466. if(curMaxEle==null || curMaxArea<a){
  467. curHeight=h;
  468. curMaxArea=a;
  469. curMaxEle=curNode;
  470. }
  471. }
  472. if(curHeight>maxHeight){
  473. return checkElement(curMaxEle);
  474. }
  475. self.curSiteRule.pageElement=self.geneSelector(ele)+">*";
  476. self.curSiteRule.type=1;
  477. debug(self.curSiteRule.pageElement);
  478. return ele.children;
  479. }
  480. pageElement=checkElement(body);
  481. if(pageElement)this.saveCurSiteRule();
  482. }
  483. return pageElement;
  484. }
  485.  
  486. getPage(){
  487. let url=this.curUrl;
  488. let doc=this.pageDoc;
  489. let pageNum=0,preStr="",afterStr="";
  490. let pageMatch1=url.match(/(.*[a-zA-Z0-9][\-_])(\d+)(\.html?$|$)/i);
  491. let pageMatch2=url.match(/(.*[\?&]p(?:age)?=)(\d+)($|#.*)/i);
  492. if(pageMatch1){
  493. preStr=pageMatch1[1];
  494. pageNum=pageMatch1[2];
  495. afterStr=pageMatch1[3];
  496. }else if(pageMatch2){
  497. preStr=pageMatch2[1];
  498. pageNum=pageMatch2[2];
  499. afterStr=pageMatch2[3];
  500. }
  501. var curPage=doc,i,cur;
  502. let next=curPage.querySelector("a.next");
  503. if(!next)next=curPage.querySelector("a#next");
  504. if(!next)next=curPage.querySelector('[rel="next"]');
  505. if(!next)next=curPage.querySelector("a#rightFix");
  506. if(next && (!next.href || /javascript:/.test(next.href)))next=null;
  507. if(!next){
  508. let aTags=curPage.querySelectorAll("a");
  509. let nextf,nexts,nextt,nextfo;
  510. for(i=0;i<aTags.length;i++){
  511. let aTag=aTags[i];
  512. if(nextf && nexts && nextt)break;
  513. if(!nextf){
  514. if(/下[一1]?[页頁张張]|next( page)?|次のページ/i.test(aTag.innerHTML)){
  515. if(!aTag.href || /javascript:/.test(aTag.href)){
  516. nextfo=aTag;
  517. }else{
  518. nextf=aTag;
  519. }
  520. }
  521. }
  522. if(!nexts){
  523. if(aTag.innerHTML=="&gt;"){
  524. if(!aTag.href || /javascript:/.test(aTag.href)){
  525. nextfo=aTag;
  526. }else{
  527. nexts=aTag;
  528. }
  529. }
  530. }
  531. if(!aTag.href || /javascript:/.test(aTag.href))continue;
  532. if(!nextt){
  533. if(aTag.innerHTML=="»"){
  534. nextt=aTag;
  535. }else if(aTag.href.replace(preStr,"").replace(afterStr,"")==parseInt(pageNum)+1){
  536. nextt=aTag;
  537. }else if(aTag.href.indexOf(url)!=-1 && /[\?&]p(age)?=/i.test(aTag.href.replace(url,""))){
  538. nextt=aTag;
  539. }
  540. }
  541. }
  542. next=nextf||nexts||nextt||nextfo;
  543. }
  544. if(!next)next=curPage.querySelector(".next>a");
  545. if(!next){
  546. let pageDiv=curPage.querySelector("div.wp-pagenavi");
  547. if(pageDiv){
  548. cur=pageDiv.querySelector("span.current");
  549. next=cur.nextSibling;
  550. }else{
  551. cur=curPage.querySelector("div.article-paging>span");
  552. if(cur){
  553. next=cur.nextElementSibling;
  554. }
  555. }
  556. }
  557. return next;
  558. }
  559.  
  560. getNextLink(doc) {
  561. let nextLink=null;
  562. let curDoc=doc||this.pageDoc;
  563. if(this.curSiteRule.nextLink)nextLink=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.nextLink,curDoc):curDoc.querySelector(this.curSiteRule.nextLink);
  564. if(!nextLink){
  565. nextLink=this.getPage();
  566. }
  567. if(nextLink){
  568. if(!this.basePageElement){
  569. this.basePageElement=this.getPageElement(document);
  570. }
  571. if(!this.curSiteRule.nextLink){
  572. this.curSiteRule.nextLink=this.geneSelector(nextLink);
  573. this.curSiteRule.type=1;
  574. this.saveCurSiteRule();
  575. }
  576. }
  577. return nextLink;
  578. }
  579.  
  580. getInsert(refresh) {
  581. if(this.insert && !refresh && this.insert.parentNode)return this.insert;
  582. if(this.curSiteRule.insert){
  583. this.insert=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.insert,document):document.querySelector(this.curSiteRule.insert);
  584. }else{
  585. let pageElement=this.basePageElement;
  586. if(pageElement && pageElement.length>0){
  587. var pELast = pageElement[pageElement.length - 1];
  588. this.insert = pELast.nextSibling ? pELast.nextSibling : pELast.parentNode.appendChild(document.createTextNode(' '));
  589. }
  590. }
  591. return this.insert;
  592. }
  593.  
  594. pageAction(document,eles){
  595. let code=this.curSiteRule.pageAction;
  596. if(code){
  597. _unsafeWindow.eval(code);
  598. }
  599. let css=this.curSiteRule.css;
  600. if(css){
  601. _GM_addStyle(css);
  602. }
  603. let lazyImgSrc=this.curSiteRule.lazyImgSrc;
  604. if(lazyImgSrc){
  605. [].forEach.call(eles, ele=>{
  606. [].forEach.call(ele.querySelectorAll("img"), img=>{
  607. if(img[lazyImgSrc]){
  608. img.src=img[lazyImgSrc];
  609. }
  610. });
  611. });
  612. }
  613. }
  614.  
  615. initPage(){
  616. this.getRule();
  617. let code=this.curSiteRule.init;
  618. if(code){
  619. _unsafeWindow.eval(code);
  620. }
  621. }
  622.  
  623. insertPage(doc, eles, url){
  624. this.pageDoc=doc;
  625. this.curUrl=url;
  626. this.pageAction(doc, eles);
  627. this.getInsert();
  628. var self=this;
  629. if(!eles || eles.length==0 || !self.insert || !self.insert.parentNode){
  630. }else{
  631. [].forEach.call(eles, ele=>{
  632. if(self.curSiteRule.insertPos==2){
  633. self.insert.appendChild(ele);
  634. }else{
  635. self.insert.parentNode.insertBefore(ele, self.insert);
  636. }
  637. });
  638. }
  639. }
  640. }
  641. var ruleParser = new RuleParser();
  642.  
  643. var rulesDate={},ruleUrls,updateDate;
  644. function initConfig(){
  645. _GM_registerMenuCommand(i18n(isDisabled?"enable":"disable"), ()=>{
  646. storage.setItem("disable_"+location.host, !isDisabled);
  647. location.reload();
  648. });
  649. var configCon;
  650. if(location.href=="https://github.com/hoothin/UserScripts/tree/master/Pagetual"){
  651. _GM_addStyle(`
  652. p>span:nth-child(1),p>span:nth-child(2),p>span:nth-child(3){
  653. cursor: pointer;
  654. user-select: none;
  655. }
  656. p>span:nth-child(1):hover,p>span:nth-child(2):hover,p>span:nth-child(3):hover{
  657. color:red;
  658. }
  659. .updateDate{
  660. cursor: pointer;
  661. user-select: none;
  662. }
  663. .updateDate:hover{
  664. color:red;
  665. }
  666. `);
  667. configCon=document.querySelector(".markdown-body");
  668. }else if(location.href=="https://github.com/hoothin/UserScripts/tree/master/Pagetual"){
  669. }else return;
  670. class Rulebar {
  671. init(ruleUrl){
  672. this.ruleUrl=ruleUrl;
  673. this.item=document.createElement("p");
  674. this.item.title=ruleUrl.type==0?"AutoPagerize Rules":"Pagetual Rules";
  675. this.item.dataset.id=this.ruleUrl.id;
  676. let url=document.createElement("span");
  677. url.innerHTML=ruleUrl.url;
  678. let up=document.createElement("span");
  679. up.innerHTML="↑ ";
  680. let down=document.createElement("span");
  681. down.innerHTML="↓ ";
  682. let del=document.createElement("span");
  683. del.innerHTML="× ";
  684. up.onclick=e=>{
  685. this.moveUp();
  686. };
  687. down.onclick=e=>{
  688. this.moveDown();
  689. };
  690. del.onclick=e=>{
  691. this.del();
  692. };
  693. this.item.appendChild(up);
  694. this.item.appendChild(down);
  695. this.item.appendChild(del);
  696. this.item.appendChild(url);
  697. configCon.appendChild(this.item);
  698. }
  699. saveSort(){
  700. let sort=[];
  701. [].forEach.call(this.item.parentNode.querySelectorAll("p[data-id]"), i=>{
  702. sort.push(i.dataset.id);
  703. });
  704. rulesDate.sort=sort;
  705. storage.setItem("importRuleUrl", rulesDate);
  706. }
  707. moveUp(){
  708. let preE=this.item.previousElementSibling;
  709. if(preE.tagName=="P" && preE.children.length>1){
  710. this.item.parentNode.insertBefore(this.item,preE);
  711. this.saveSort();
  712. }
  713. }
  714. moveDown(){
  715. let nextE=this.item.nextElementSibling;
  716. if(nextE.tagName=="P" && nextE.children.length>1){
  717. this.item.parentNode.insertBefore(nextE,this.item);
  718. this.saveSort();
  719. }
  720. }
  721. del(){
  722. if(this.ruleUrl.id<2){
  723. alert(i18n("cantDel"));
  724. }else if(window.confirm(i18n("confirmDel"))){
  725. for(let u=0;u<rulesDate.urls.length;u++){
  726. if(this.ruleUrl.id==rulesDate.urls[u].id){
  727. rulesDate.urls.splice(u,1);
  728. break;
  729. }
  730. }
  731. for(let u=0;u<rulesDate.sort.length;u++){
  732. if(this.ruleUrl.id==rulesDate.sort[u]){
  733. rulesDate.sort.splice(u,1);
  734. break;
  735. }
  736. }
  737. storage.setItem("importRuleUrl", rulesDate);
  738. ruleParser.rules=ruleParser.rules.filter(item=>{return item.from!=this.ruleUrl.id});
  739. storage.setItem("rules", ruleParser.rules);
  740. this.item.parentNode.removeChild(this.item);
  741. //location.reload();
  742. }
  743. }
  744. }
  745. let updateP=document.createElement("p"),i=0;
  746. let now=new Date().getTime(),inUpdate=false;
  747. updateP.className="updateDate";
  748. updateP.innerHTML=updateDate;
  749. updateP.title=i18n("update");
  750. updateP.onclick=e=>{
  751. if(inUpdate)return;
  752. inUpdate=true;
  753. ruleUrls.forEach(rule=>{
  754. ruleParser.addRuleByUrl(rule.url, rule.type, rule.id, ()=>{
  755. if(++i==ruleUrls.length){
  756. storage.setItem("ruleLastUpdate", now);
  757. alert(i18n("updateSucc"));
  758. inUpdate=false;
  759. }
  760. })
  761. });
  762. alert(i18n("beginUpdate"));
  763. };
  764. configCon.appendChild(updateP);
  765. if(ruleUrls){
  766. ruleUrls.forEach(ruleUrl=>{
  767. var rulebar=new Rulebar();
  768. rulebar.init(ruleUrl);
  769. });
  770. }
  771. let customUrlsTitle=document.createElement("h2");
  772. customUrlsTitle.innerHTML=i18n("customUrls")
  773. configCon.appendChild(customUrlsTitle);
  774. let customUrlsInput=document.createElement("textarea");
  775. customUrlsInput.style.width="100%";
  776. customUrlsInput.placeholder="0|http://wedata.net/databases/AutoPagerize/items_all.json";
  777. configCon.appendChild(customUrlsInput);
  778. let customRulesTitle=document.createElement("h2");
  779. customRulesTitle.innerHTML=i18n("customRules")
  780. configCon.appendChild(customRulesTitle);
  781. let customRulesInput=document.createElement("textarea");
  782. customRulesInput.style.width="100%";
  783. customRulesInput.style.height="500px";
  784. customRulesInput.placeholder=`[\n{\n "type":"1",\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 "type":"1",\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]`;
  785. customRulesInput.value=JSON.stringify(ruleParser.customRules);
  786. configCon.appendChild(customRulesInput);
  787. let saveBtn=document.createElement("button");
  788. saveBtn.innerHTML=i18n("save");
  789. saveBtn.style.width="100%";
  790. configCon.appendChild(saveBtn);
  791. saveBtn.onclick=e=>{
  792. try{
  793. let customRules=JSON.parse(customRulesInput.value);
  794. debug(customRules);
  795. storage.setItem("customRules", customRules);
  796. }catch(e){
  797. debug(e);
  798. alert("JSON error!");
  799. }
  800. let customUrls=customUrlsInput.value.trim();
  801. if(customUrls){
  802. customUrls=customUrls.split(/\n/);
  803. for(let c=0;c<customUrls.length;c++){
  804. let urlArr=customUrls[c].split("|"),url,type=1;
  805. if(urlArr.length==1){
  806. url=urlArr[0].trim();
  807. if(!/http/.test(url)){
  808. alert("Wrong url");
  809. break;
  810. }
  811. }else if(urlArr.length==2){
  812. type=urlArr[0].trim();
  813. url=urlArr[1].trim();
  814. }else{
  815. break;
  816. }
  817. let maxId=0,hasUrl=false;;
  818. if(!rulesDate.urls){
  819. rulesDate.urls=[];
  820. maxId=1;
  821. }else{
  822. rulesDate.urls.forEach(u=>{
  823. if(maxId<u.id){
  824. maxId=u.id;
  825. }
  826. if(u.url==url){
  827. hasUrl=true;
  828. }
  829. });
  830. if(hasUrl)break;
  831. }
  832. rulesDate.urls.push({id:maxId+1,url:url,type:type});
  833. rulesDate.sort.push(maxId+1);
  834. storage.setItem("importRuleUrl", rulesDate);
  835. }
  836. }
  837. alert("over");
  838. location.reload();
  839. };
  840. }
  841.  
  842. function getTimeStr(date){
  843. let now=new Date().getTime();
  844. let passTime=(now-date)/1000;
  845. if(passTime<60){
  846. updateDate=i18n("passSec", passTime);
  847. }else if(passTime<60*60){
  848. updateDate=i18n("passMin", parseInt(passTime/60));
  849. }else if(passTime<60*60*24){
  850. updateDate=i18n("passHour", parseInt(passTime/3600));
  851. }else{
  852. updateDate=i18n("passDay", parseInt(passTime/86400));
  853. }
  854. }
  855.  
  856. function initRules(callback) {
  857. /*0 wedata格式,1 pagetual格式*/
  858. ruleUrls=[
  859. {
  860. id:0,
  861. url:'http://wedata.net/databases/AutoPagerize/items_all.json',
  862. type:0,
  863. },
  864. {
  865. id:1,
  866. url:'https://raw.githubusercontent.com/hoothin/UserScripts/master/Pagetual/pagetualRules.json',
  867. type:1
  868. }
  869. ];var i=0,j=0;
  870.  
  871. ruleParser.initSavedRules(()=>{
  872. storage.getItem("importRuleUrl", data=>{
  873. if(data){
  874. rulesDate=data;
  875. if(data.urls)ruleUrls=ruleUrls.concat(data.urls);
  876. if(data.sort){
  877. let urls=[];
  878. data.sort.forEach(id=>{
  879. for(let s=0;s<ruleUrls.length;s++){
  880. if(id==ruleUrls[s].id){
  881. urls.push(ruleUrls[s]);
  882. break;
  883. }
  884. }
  885. });
  886. ruleUrls=urls;
  887. }
  888. }
  889. storage.getItem("disable_"+location.host, v=>{
  890. storage.getItem("ruleLastUpdate", date=>{
  891. isDisabled=v==true;
  892. getTimeStr(date);
  893. initConfig();
  894. if(isDisabled)return;
  895. let now=new Date().getTime();
  896. if(!date || now-date>3*24*60*60*1000){
  897. ruleUrls.forEach(rule=>{
  898. ruleParser.addRuleByUrl(rule.url, rule.type, rule.id, ()=>{
  899. if(++i==ruleUrls.length){
  900. storage.setItem("ruleLastUpdate", now);
  901. callback();
  902. }
  903. })
  904. });
  905. }else{
  906. callback();
  907. }
  908. });
  909. });
  910. });
  911. });
  912. }
  913.  
  914. function requestDoc(url, callback){
  915. _GM_xmlhttpRequest({
  916. url: url,
  917. onload: function(res) {
  918. var doc=null;
  919. try {
  920. doc=document.implementation.createHTMLDocument('');
  921. doc.documentElement.innerHTML=res.response;
  922. }
  923. catch (e) {
  924. debug('parse error'+e.toString());
  925. }
  926. let pageElement=ruleParser.getPageElement(doc);
  927. //只有1的話怕不是圖片哦
  928. if(pageElement && pageElement.length>1){
  929. callback(pageElement);
  930. ruleParser.insertPage(doc, pageElement, url);
  931. }else{
  932. requestFromIframe(url, (doc, eles)=>{
  933. callback(eles);
  934. if(eles){
  935. ruleParser.insertPage(doc, eles, url);
  936. }
  937. });
  938. }
  939. }
  940. });
  941. }
  942.  
  943. function requestFromIframe(url, callback){
  944. let orgPage,curPage;
  945. let iframe = document.createElement('iframe');
  946. iframe.name = 'pagetual-iframe';
  947. iframe.width = '100%';
  948. iframe.height = '0';
  949. iframe.frameBorder = '0';
  950. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  951. iframe.addEventListener("load", e=>{
  952. setTimeout(()=>{
  953. //可能會延遲加載
  954. let doc=iframe.contentWindow.document;
  955. let eles=ruleParser.getPageElement(doc);
  956. if(eles && eles.length>0){
  957. callback(doc, eles);
  958. }else{
  959. isPause=true;
  960. callback(false, false);
  961. }
  962. document.body.removeChild(iframe);
  963. },300);
  964. });
  965. iframe.src=url;
  966. document.body.appendChild(iframe);
  967. }
  968.  
  969. function initPage(){
  970. ruleParser.initPage()
  971. nextPage();
  972. initListener();
  973. }
  974.  
  975. function initView(){
  976. _GM_addStyle(`
  977. .pagetual_pageBar.stop {
  978. -webkit-filter: invert(100%);
  979. filter: invert(100%);
  980. opacity: 1;
  981. }
  982. .pagetual_pageBar {
  983. opacity: 0.1;
  984. }
  985. .pagetual_pageBar:hover {
  986. opacity: 1;
  987. }
  988. .pagetual_pageBar>span {
  989. vertical-align: super;
  990. }
  991.  
  992. .pagetual_pageBar>span>svg:hover {
  993. animation: touhouAni 1s infinite;
  994. }
  995.  
  996. @keyframes touhouAni{
  997. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  998. to {transform: rotate(360deg);}
  999. }
  1000. @-webkit-keyframes touhouAni{
  1001. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  1002. to {transform: rotate(360deg);}
  1003. }
  1004. `);
  1005. }
  1006. var loading=document.createElement("div");
  1007. 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;";
  1008. loading.innerHTML=`<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>`;
  1009. document.body.appendChild(loading);
  1010.  
  1011. 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>`;
  1012. 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>`;
  1013. 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;`;
  1014. 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);`;
  1015.  
  1016. var isPause=false,isLoading=false,curPage=1,isDisabled=false;
  1017.  
  1018. function changeStop(stop){
  1019. isPause=stop;
  1020. [].forEach.call(document.querySelectorAll(".pagetual_pageBar"), bar=>{
  1021. if(isPause){
  1022. bar.classList.add("stop");
  1023. }else{
  1024. bar.classList.remove("stop");
  1025. }
  1026. });
  1027. }
  1028.  
  1029. function initListener(){
  1030. document.addEventListener('scroll', e=>{
  1031. setTimeout(()=>{
  1032. if(!isPause && !isLoading){
  1033. let scrolly=window.scrollY;
  1034. let windowHeight=window.innerHeight;
  1035. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  1036. if(scrollH-scrolly-windowHeight<500){
  1037. nextPage();
  1038. }
  1039. }
  1040. },100);
  1041. }, false);
  1042. document.addEventListener('dblclick', e=>{
  1043. changeStop(!isPause);
  1044. });
  1045. }
  1046.  
  1047. function createPageBar(url){
  1048. isLoading=false;
  1049. loading.style.display="none";
  1050. let insert=ruleParser.getInsert();
  1051. if(!insert || !insert.parentNode)return;
  1052. curPage++;
  1053. let inTable=insert.tagName=="TR" || insert.previousElementSibling.tagName=="TR";
  1054. let pageBar=document.createElement(inTable?"tr":"div");
  1055. let upSpan=document.createElement("span");
  1056. let downSpan=document.createElement("span");
  1057. let pageText=document.createElement("a");
  1058. pageBar.className="pagetual_pageBar";
  1059. pageBar.id="pagetual_pageBar";
  1060. if(isPause){
  1061. pageBar.classList.add("stop");
  1062. }
  1063. pageBar.style.cssText=pageBarStyle;
  1064. pageBar.title="Disable";
  1065. upSpan.innerHTML=upSvg;
  1066. upSpan.title="To Top";
  1067. downSpan.innerHTML=downSvg;
  1068. downSpan.title="To Bottom";
  1069. pageText.href=url;
  1070. pageText.style=pageTextStyle;
  1071. pageText.innerHTML="Page "+curPage;
  1072. pageText.title="Current Page";
  1073. pageBar.appendChild(upSpan);
  1074. pageBar.appendChild(pageText);
  1075. pageBar.appendChild(downSpan);
  1076. if(inTable){
  1077. pageBar.style.display="table-row";
  1078. let td=document.createElement("td");
  1079. td.colSpan=99;
  1080. td.appendChild(upSpan);
  1081. td.appendChild(pageText);
  1082. td.appendChild(downSpan);
  1083. pageBar.appendChild(td);
  1084. }
  1085.  
  1086. upSpan.addEventListener("click", e=>{
  1087. changeStop(true);
  1088. document.body.scrollTop=0;
  1089. document.documentElement.scrollTop=0;
  1090. e.preventDefault();
  1091. e.stopPropagation();
  1092. });
  1093. downSpan.addEventListener("click", e=>{
  1094. changeStop(true);
  1095. document.body.scrollTop=9999999;
  1096. document.documentElement.scrollTop=9999999;
  1097. e.preventDefault();
  1098. e.stopPropagation();
  1099. });
  1100. pageBar.addEventListener("click", e=>{
  1101. changeStop(!isPause);
  1102. });
  1103. pageText.addEventListener("click", e=>{
  1104. e.stopPropagation();
  1105. });
  1106. pageBar.style.width=parseInt(_unsafeWindow.getComputedStyle(insert.parentNode).width)*.9+"px";
  1107. insert.parentNode.insertBefore(pageBar, insert);
  1108. return pageBar;
  1109. }
  1110.  
  1111. var emuIframe;
  1112. function emuPage(callback){
  1113. let orgPage,curPage,iframeDoc;
  1114. function checkPage(doc){
  1115. let eles=ruleParser.getPageElement(doc);
  1116. if(orgPage == eles[0]){
  1117. setTimeout(()=>{
  1118. checkPage(doc);
  1119. },500);
  1120. }else{
  1121. if(eles && eles.length>0){
  1122. callback(doc, eles);
  1123. }else{
  1124. isPause=true;
  1125. callback(false, false);
  1126. }
  1127. }
  1128. }
  1129. if(!emuIframe){
  1130. emuIframe = document.createElement('iframe');
  1131. emuIframe.name = 'pagetual-iframe';
  1132. emuIframe.width = '100%';
  1133. emuIframe.height = '0';
  1134. emuIframe.frameBorder = '0';
  1135. emuIframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1136. emuIframe.addEventListener("load", e=>{
  1137. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  1138. setTimeout(()=>{
  1139. orgPage=ruleParser.getPageElement(iframeDoc)[0];
  1140. ruleParser.getNextLink(iframeDoc).click();
  1141. checkPage(iframeDoc);
  1142. },300);
  1143. });
  1144. emuIframe.src=location.href;
  1145. document.body.appendChild(emuIframe);
  1146. }else{
  1147. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  1148. orgPage=ruleParser.getPageElement(iframeDoc)[0];
  1149. ruleParser.getNextLink(iframeDoc).click();
  1150. checkPage(iframeDoc);
  1151. }
  1152. }
  1153.  
  1154. function forceIframe(url, callback){
  1155. let curIframe = document.createElement('iframe');
  1156. curIframe.name = 'pagetual-iframe';
  1157. curIframe.frameBorder = '0';
  1158. curIframe.scrolling="no";
  1159. 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;';
  1160. curIframe.addEventListener("load", e=>{
  1161. let iframeDoc=curIframe.contentDocument || curIframe.contentWindow.document;
  1162. let eles=ruleParser.getPageElement(iframeDoc);
  1163. if(eles && eles.length>0){
  1164. ruleParser.insertPage(iframeDoc, [], url);
  1165. callback(curIframe, eles);
  1166. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  1167. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  1168. curIframe.scrollIntoView();
  1169. }else{
  1170. isPause=true;
  1171. callback(false, false);
  1172. curIframe.parentNode.removeChild(curIframe);
  1173. }
  1174. });
  1175. curIframe.src=url;
  1176. let insert=ruleParser.getInsert();
  1177. document.body.appendChild(curIframe);
  1178. return curIframe;
  1179. }
  1180.  
  1181. function nextPage(){
  1182. if(isPause || isLoading)return;
  1183. let nextLink=ruleParser.getNextLink();
  1184. let insert=ruleParser.getInsert();
  1185. if(nextLink && insert){
  1186. isLoading=true;
  1187. loading.style.display="";
  1188. if(ruleParser.curSiteRule.action==1 && nextLink.href){
  1189. requestFromIframe(nextLink.href, (doc, eles)=>{
  1190. if(eles){
  1191. createPageBar(nextLink.href);
  1192. ruleParser.insertPage(doc, eles, nextLink.href);
  1193. }
  1194. });
  1195. }else if(ruleParser.curSiteRule.action==2 && nextLink.href){
  1196. forceIframe(nextLink.href, (iframe, eles)=>{
  1197. if(!eles)return;
  1198. if(eles){
  1199. let pageBar=createPageBar(nextLink.href);
  1200. iframe.parentNode.insertBefore(pageBar, iframe);
  1201. }
  1202. });
  1203. }else{
  1204. if(nextLink.href){
  1205. requestDoc(nextLink.href, (eles)=>{
  1206. if(!eles)return;
  1207. createPageBar(nextLink.href);
  1208. });
  1209. }else{
  1210. emuPage((doc, eles)=>{
  1211. if(!eles)return;
  1212. createPageBar(nextLink.href);
  1213. if(eles){
  1214. ruleParser.insertPage(doc, eles, "");
  1215. }
  1216. });
  1217. }
  1218. }
  1219. }
  1220. }
  1221.  
  1222. function init(){
  1223. initView();
  1224. initRules(()=>{
  1225. initPage();
  1226. });
  1227. }
  1228. init();
  1229. })();

QingJ © 2025

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