东方永页机

自动翻页

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

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

QingJ © 2025

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