东方永页机

自动翻页

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

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

QingJ © 2025

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