东方永页机

自动翻页

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

  1. // ==UserScript==
  2. // @name Pagetual
  3. // @name:zh-CN 东方永页机
  4. // @name:zh-TW 東方永頁機
  5. // @namespace hoothin
  6. // @version 0.3.8.8
  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(callback) {
  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. let r=0;
  388. function searchByTime(){
  389. setTimeout(()=>{
  390. let end=r+80;
  391. end=end>self.rules.length?self.rules.length:end;
  392. for(;r<end;r++){
  393. let rule=self.rules[r];
  394. if(rule.enable==0)continue;
  395. let urlReg=new RegExp(rule.url, "i");
  396. if(urlReg.test(location.href)){
  397. let pageElement,nextLink,insert;
  398. if(rule.pageElement)pageElement=rule.type==0?getElementByXpath(rule.pageElement):document.querySelector(rule.pageElement);
  399. if(rule.nextLink)nextLink=rule.type==0?getElementByXpath(rule.nextLink):document.querySelector(rule.nextLink);
  400. if(rule.insert)insert=rule.type==0?getElementByXpath(rule.insert):document.querySelector(rule.insert);
  401. if((rule.pageElement && !pageElement) ||
  402. (rule.nextLink && !nextLink) ||
  403. (rule.insert && !insert)){
  404. continue;
  405. }
  406. self.curSiteRule=rule;
  407. debug(rule);
  408. callback();
  409. return;
  410. }
  411. }
  412. if(end>=self.rules.length){
  413. self.curSiteRule={};
  414. self.curSiteRule.url=location.origin.replace(/\./g,"\\.");
  415. callback();
  416. return;
  417. }else{
  418. searchByTime();
  419. }
  420. },20);
  421. }
  422. searchByTime();
  423. }
  424.  
  425. geneSelector(ele){
  426. let selector=ele.tagName;
  427. //Google id class都是隨機。百度更過分,style script順序都是隨機的
  428. //if(ele.id) selector += '#' + ele.id;
  429. //if(ele.classList) selector += [].map.call(ele.classList,d=>'.'+d).join('');
  430. let parent = ele.parentElement;
  431. if(parent){
  432. let i,j=0;
  433. for(i=0;i<parent.children.length;i++){
  434. if(parent.children[i].tagName==selector){
  435. j++;
  436. if(parent.children[i]==ele){
  437. break;
  438. }
  439. }
  440. }
  441. selector = this.geneSelector(parent) + ' > ' + selector + (parent.tagName=="HTML"?"":`:nth-of-type(${j})`);
  442. }
  443. return selector;
  444. }
  445.  
  446. getPageElement(doc) {
  447. let pageElement=null;
  448. let self=this;
  449. if(this.curSiteRule.pageElement){
  450. pageElement=this.curSiteRule.type==0?getAllElementsByXpath(this.curSiteRule.pageElement,doc,doc):doc.querySelectorAll(this.curSiteRule.pageElement);
  451. }
  452. if(!pageElement){
  453. let body=doc.body,bodyHeight=parseInt(_unsafeWindow.getComputedStyle(body).height);
  454. function checkElement(ele){
  455. let curHeight=parseInt(_unsafeWindow.getComputedStyle(ele).height);
  456. if(curHeight/bodyHeight<=0.35)return null;
  457. if(ele.children.length==0){
  458. self.curSiteRule.pageElement=self.geneSelector(ele.parentNode)+">"+ele.tagName;
  459. self.curSiteRule.type=1;
  460. debug(self.curSiteRule.pageElement);
  461. return [ele];
  462. }
  463. let i,maxHeight=curHeight*0.35,curMaxEle=null,curMaxArea=0;
  464. for(i=0;i<ele.children.length;i++){
  465. let curNode=ele.children[i];
  466. if(curNode.innerText=="")continue;
  467. let comStyle=_unsafeWindow.getComputedStyle(curNode);
  468. let h=parseInt(comStyle.height);
  469. let w=parseInt(comStyle.width);
  470. if(isNaN(h) || isNaN(w))continue;
  471. let a=h*w+h,moreChild=curNode.children[0];
  472. while(moreChild){
  473. comStyle=_unsafeWindow.getComputedStyle(moreChild);
  474. let ch=parseInt(comStyle.height);
  475. let cw=parseInt(comStyle.width);
  476. if(moreChild.innerText!="" && !isNaN(ch) && !isNaN(cw)){
  477. a+=ch*cw;
  478. }
  479. moreChild=moreChild.nextElementSibling;
  480. }
  481. if(curMaxEle==null || curMaxArea<a){
  482. curHeight=h;
  483. curMaxArea=a;
  484. curMaxEle=curNode;
  485. }
  486. }
  487. if(curHeight>maxHeight){
  488. return checkElement(curMaxEle);
  489. }
  490. self.curSiteRule.pageElement=self.geneSelector(ele)+">*";
  491. self.curSiteRule.type=1;
  492. debug(self.curSiteRule.pageElement);
  493. return ele.children;
  494. }
  495. pageElement=checkElement(body);
  496. //if(pageElement)this.saveCurSiteRule();
  497. }
  498. return pageElement;
  499. }
  500.  
  501. getPage(){
  502. let canSave=false;//發現頁碼選擇器在其他頁對不上,還是別保存了
  503. let url=this.curUrl;
  504. let doc=this.pageDoc;
  505. let pageNum=0,preStr="",afterStr="";
  506. let pageMatch1=url.match(/(.*[a-zA-Z0-9\/][\-_](?:p|page)?)(\d+)(\.html?$|$)/i);
  507. let pageMatch2=url.match(/(.*[\?&]p(?:age)?=)(\d+)($|[#&].*)/i);
  508. if(pageMatch1){
  509. preStr=pageMatch1[1];
  510. pageNum=pageMatch1[2];
  511. afterStr=pageMatch1[3];
  512. }else if(pageMatch2){
  513. preStr=pageMatch2[1];
  514. pageNum=pageMatch2[2];
  515. afterStr=pageMatch2[3];
  516. }
  517. var curPage=doc,i,cur;
  518. let next=curPage.querySelector("a.next");
  519. if(!next)next=curPage.querySelector("a#next");
  520. if(!next)next=curPage.querySelector("a#rightFix");
  521. if(!next)next=curPage.querySelector("a.next_page");
  522. if(next && (!next.href || /javascript:/.test(next.href)))next=null;
  523. if(!next)next=curPage.querySelector(".next>a");
  524. if(!next){
  525. let pageDiv=curPage.querySelector("div.wp-pagenavi");
  526. if(pageDiv){
  527. cur=pageDiv.querySelector("span.current");
  528. next=cur.nextSibling;
  529. }else{
  530. cur=curPage.querySelector("div.article-paging>span");
  531. if(cur){
  532. next=cur.nextElementSibling;
  533. }
  534. }
  535. }
  536. if(!next){
  537. let pageDiv=curPage.querySelector("div.pages>ul");
  538. if(pageDiv){
  539. cur=pageDiv.querySelector("li>b");
  540. if(cur)next=cur.parentNode.nextElementSibling.querySelector("a");
  541. }
  542. }
  543. if(!next){
  544. let aTags=curPage.querySelectorAll("a");
  545. let nextf,nexts,nextt,nextfo;
  546. for(i=0;i<aTags.length;i++){
  547. let aTag=aTags[i];
  548. if(nextf && nexts && nextt)break;
  549. if(!nextf){
  550. if(/(\s|^)下[一1]?[页頁张張]|^next( page)?\s*$|次のページ/i.test(aTag.innerText)){
  551. if(!aTag.href || /javascript:/.test(aTag.href)){
  552. nextfo=aTag;
  553. }else{
  554. nextf=aTag;
  555. }
  556. }
  557. }
  558. if(!nexts){
  559. if(aTag.innerText=="&gt;"){
  560. if(!aTag.href || /javascript:/.test(aTag.href)){
  561. nextfo=aTag;
  562. }else{
  563. nexts=aTag;
  564. }
  565. }
  566. }
  567. if(!aTag.href || /javascript:/.test(aTag.href))continue;
  568. if(!nextt){
  569. aTag.href=aTag.href.replace(/\?&/,"?");
  570. if(aTag.innerText=="»"){
  571. nextt=aTag;
  572. }else if(aTag.href.replace(preStr,"").replace(afterStr,"")==parseInt(pageNum)+1){
  573. nextt=aTag;
  574. }else if(aTag.href.indexOf(url)!=-1 && /^[\/\?&]?[_-]?(p|page)?=?[12](\?|&|$)/i.test(aTag.href.replace(url,""))){
  575. nextt=aTag;
  576. }
  577. }
  578. }
  579. next=nextf||nexts||nextt||nextfo;
  580. }
  581. if(!next)next=curPage.querySelector('[rel="next"]');
  582. return {next:next,canSave:canSave};
  583. }
  584.  
  585. getNextLink(doc) {
  586. let nextLink=null,page;
  587. let curDoc=doc||this.pageDoc;
  588. if(this.curSiteRule.nextLinkByUrl){
  589. let targetUrl=this.curUrl.replace(new RegExp(this.curSiteRule.nextLinkByUrl[0]), this.curSiteRule.nextLinkByUrl[1]);
  590. if(targetUrl != this.curUrl){
  591. let reps=targetUrl.match(/{.*?}/g);
  592. if(reps){
  593. reps.forEach(rep=>{
  594. let code=rep.replace("{","").replace("}","");
  595. let result=_unsafeWindow.eval(code);
  596. targetUrl=targetUrl.replace(rep, result);
  597. });
  598. }
  599. }
  600. nextLink={href:targetUrl};
  601. }else if(this.curSiteRule.nextLink){
  602. nextLink=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.nextLink,curDoc,curDoc):curDoc.querySelector(this.curSiteRule.nextLink);
  603. }
  604. if(!nextLink){
  605. page=this.getPage();
  606. nextLink=page.next;
  607. }
  608. if(nextLink){
  609. if(!this.basePageElement){
  610. this.basePageElement=this.getPageElement(document);
  611. }
  612. if(!this.curSiteRule.nextLink && page && page.canSave){
  613. this.curSiteRule.nextLink=this.geneSelector(nextLink);
  614. this.curSiteRule.type=1;
  615. this.saveCurSiteRule();
  616. }
  617. }
  618. return nextLink;
  619. }
  620.  
  621. getInsert(refresh) {
  622. if(this.insert && !refresh && this.insert.parentNode)return this.insert;
  623. if(this.curSiteRule.insert){
  624. this.insert=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.insert,document):document.querySelector(this.curSiteRule.insert);
  625. }else{
  626. let pageElement=this.basePageElement;
  627. if(pageElement && pageElement.length>0){
  628. var pELast = pageElement[pageElement.length - 1];
  629. this.insert = pELast.nextSibling ? pELast.nextSibling : pELast.parentNode.appendChild(document.createTextNode(' '));
  630. }
  631. }
  632. return this.insert;
  633. }
  634.  
  635. pageAction(document,eles){
  636. let code=this.curSiteRule.pageAction;
  637. if(code){
  638. _unsafeWindow.eval(code);
  639. }
  640. let css=this.curSiteRule.css;
  641. if(css){
  642. _GM_addStyle(css);
  643. }
  644. [].forEach.call(eles, ele=>{
  645. [].forEach.call(ele.querySelectorAll("img"), img=>{
  646. //if(img.src==""){
  647. let realSrc;
  648. if(img.dataset && img.dataset.original){
  649. realSrc=img.dataset.original;
  650. }else if(img.dataset && img.dataset.src){
  651. realSrc=img.dataset.src;
  652. }else if(img._lazyrias && img._lazyrias.srcset){
  653. realSrc=img._lazyrias.srcset[img._lazyrias.srcset.length-1];
  654. }else if(img.dataset && img.dataset.origFile){
  655. realSrc=img.dataset.origFile;
  656. }else if(img.srcset){
  657. var srcs=img.srcset.split(","),largeSize=0;
  658. srcs.forEach(srci=>{
  659. let srcInfo=srci.trim().split(" "),curSize=parseInt(srcInfo[1]);
  660. if(srcInfo[1] && curSize>largeSize){
  661. largeSize=curSize;
  662. realSrc=srcInfo[0];
  663. }
  664. });
  665. }
  666. if(realSrc)img.src=realSrc;
  667. //}
  668. });
  669. });
  670. let lazyImgSrc=this.curSiteRule.lazyImgSrc;
  671. if(lazyImgSrc){
  672. [].forEach.call(eles, ele=>{
  673. [].forEach.call(ele.querySelectorAll("img"), img=>{
  674. if(img[lazyImgSrc]){
  675. img.src=img[lazyImgSrc];
  676. }
  677. });
  678. });
  679. }
  680. }
  681.  
  682. initPage(callback){
  683. let self=this;
  684. this.getRule(()=>{
  685. callback();
  686. let code=self.curSiteRule.init;
  687. if(code){
  688. _unsafeWindow.eval(code);
  689. }
  690. });
  691. }
  692.  
  693. insertPage(doc, eles, url){
  694. this.pageDoc=doc;
  695. this.curUrl=url;
  696. this.pageAction(doc, eles);
  697. this.getInsert();
  698. var self=this;
  699. if(!eles || eles.length==0 || !self.insert || !self.insert.parentNode){
  700. }else{
  701. [].forEach.call(eles, ele=>{
  702. if(self.curSiteRule.insertPos==2){
  703. self.insert.appendChild(ele.cloneNode(true));
  704. }else{
  705. self.insert.parentNode.insertBefore(ele.cloneNode(true), self.insert);
  706. }
  707. });
  708. }
  709. }
  710. }
  711. var ruleParser = new RuleParser();
  712.  
  713. var rulesDate={},ruleUrls,updateDate;
  714. function initConfig(){
  715. _GM_registerMenuCommand(i18n(forceState==1?"enable":"disable"), ()=>{
  716. storage.setItem("forceState_"+location.host, (forceState==1?0:1));
  717. location.reload();
  718. });
  719.  
  720. _GM_registerMenuCommand(i18n(forceState==2?"cancelForceIframe":"forceIframe"), ()=>{
  721. storage.setItem("forceState_"+location.host, (forceState==2?0:2));
  722. location.reload();
  723. });
  724. var configCon,insertPos;
  725. if(location.href=="https://github.com/hoothin/UserScripts/tree/master/Pagetual"){
  726. _GM_addStyle(`
  727. p>span:nth-child(1),p>span:nth-child(2),p>span:nth-child(3){
  728. cursor: pointer;
  729. user-select: none;
  730. }
  731. p>span:nth-child(1):hover,p>span:nth-child(2):hover,p>span:nth-child(3):hover{
  732. color:red;
  733. }
  734. .updateDate{
  735. cursor: pointer;
  736. user-select: none;
  737. }
  738. .updateDate:hover{
  739. color:red;
  740. }
  741. `);
  742. configCon=document.querySelector(".markdown-body");
  743. insertPos=configCon.querySelector("hr");
  744. }else if(location.href=="https://github.com/hoothin/UserScripts/tree/master/Pagetual"){
  745. }else return;
  746. class Rulebar {
  747. init(ruleUrl){
  748. this.ruleUrl=ruleUrl;
  749. this.item=document.createElement("p");
  750. this.item.title=ruleUrl.type==0?"AutoPagerize Rules":"Pagetual Rules";
  751. this.item.dataset.id=this.ruleUrl.id;
  752. let url=document.createElement("span");
  753. url.innerHTML=ruleUrl.url;
  754. let up=document.createElement("span");
  755. up.innerHTML="↑ ";
  756. let down=document.createElement("span");
  757. down.innerHTML="↓ ";
  758. let del=document.createElement("span");
  759. del.innerHTML="× ";
  760. up.onclick=e=>{
  761. this.moveUp();
  762. };
  763. down.onclick=e=>{
  764. this.moveDown();
  765. };
  766. del.onclick=e=>{
  767. this.del();
  768. };
  769. this.item.appendChild(up);
  770. this.item.appendChild(down);
  771. this.item.appendChild(del);
  772. this.item.appendChild(url);
  773. configCon.insertBefore(this.item, insertPos);
  774. }
  775. saveSort(){
  776. let sort=[];
  777. [].forEach.call(this.item.parentNode.querySelectorAll("p[data-id]"), i=>{
  778. sort.push(i.dataset.id);
  779. });
  780. rulesDate.sort=sort;
  781. storage.setItem("importRuleUrl", rulesDate);
  782. }
  783. moveUp(){
  784. let preE=this.item.previousElementSibling;
  785. if(preE.tagName=="P" && preE.children.length>1){
  786. this.item.parentNode.insertBefore(this.item,preE);
  787. this.saveSort();
  788. }
  789. }
  790. moveDown(){
  791. let nextE=this.item.nextElementSibling;
  792. if(nextE.tagName=="P" && nextE.children.length>1){
  793. this.item.parentNode.insertBefore(nextE,this.item);
  794. this.saveSort();
  795. }
  796. }
  797. del(){
  798. if(this.ruleUrl.id<2){
  799. alert(i18n("cantDel"));
  800. }else if(window.confirm(i18n("confirmDel"))){
  801. for(let u=0;u<rulesDate.urls.length;u++){
  802. if(this.ruleUrl.id==rulesDate.urls[u].id){
  803. rulesDate.urls.splice(u,1);
  804. break;
  805. }
  806. }
  807. for(let u=0;u<rulesDate.sort.length;u++){
  808. if(this.ruleUrl.id==rulesDate.sort[u]){
  809. rulesDate.sort.splice(u,1);
  810. break;
  811. }
  812. }
  813. storage.setItem("importRuleUrl", rulesDate);
  814. ruleParser.rules=ruleParser.rules.filter(item=>{return item.from!=this.ruleUrl.id});
  815. storage.setItem("rules", ruleParser.rules);
  816. this.item.parentNode.removeChild(this.item);
  817. //location.reload();
  818. }
  819. }
  820. }
  821. let updateP=document.createElement("p"),i=0;
  822. let now=new Date().getTime(),inUpdate=false;
  823. updateP.className="updateDate";
  824. updateP.innerHTML=updateDate;
  825. updateP.title=i18n("update");
  826. updateP.onclick=e=>{
  827. if(inUpdate)return;
  828. inUpdate=true;
  829. ruleUrls.forEach(rule=>{
  830. ruleParser.addRuleByUrl(rule.url, rule.type, rule.id, ()=>{
  831. if(++i==ruleUrls.length){
  832. storage.setItem("ruleLastUpdate", now);
  833. alert(i18n("updateSucc"));
  834. inUpdate=false;
  835. }
  836. })
  837. });
  838. alert(i18n("beginUpdate"));
  839. };
  840. configCon.insertBefore(updateP, insertPos);
  841. if(ruleUrls){
  842. ruleUrls.forEach(ruleUrl=>{
  843. var rulebar=new Rulebar();
  844. rulebar.init(ruleUrl);
  845. });
  846. }
  847. let customUrlsTitle=document.createElement("h2");
  848. customUrlsTitle.innerHTML=i18n("customUrls")
  849. configCon.insertBefore(customUrlsTitle, insertPos);
  850. let customUrlsInput=document.createElement("textarea");
  851. customUrlsInput.style.width="100%";
  852. customUrlsInput.placeholder="0|http://wedata.net/databases/AutoPagerize/items_all.json";
  853. configCon.insertBefore(customUrlsInput, insertPos);
  854. let customRulesTitle=document.createElement("h2");
  855. customRulesTitle.innerHTML=i18n("customRules")
  856. configCon.insertBefore(customRulesTitle, insertPos);
  857. let customRulesInput=document.createElement("textarea");
  858. customRulesInput.style.width="100%";
  859. customRulesInput.style.height="500px";
  860. 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]`;
  861. customRulesInput.value=getFormatJSON(ruleParser.customRules);
  862. configCon.insertBefore(customRulesInput, insertPos);
  863. let saveBtn=document.createElement("button");
  864. saveBtn.innerHTML=i18n("save");
  865. saveBtn.style.width="100%";
  866. configCon.insertBefore(saveBtn, insertPos);
  867. saveBtn.onclick=e=>{
  868. try{
  869. if(customRulesInput.value==""){
  870. storage.setItem("customRules", "");
  871. }else{
  872. let customRules=JSON.parse(customRulesInput.value);
  873. debug(customRules);
  874. storage.setItem("customRules", customRules);
  875. }
  876. }catch(e){
  877. debug(e);
  878. alert("JSON error, check again!");
  879. return;
  880. }
  881. let customUrls=customUrlsInput.value.trim();
  882. if(customUrls){
  883. customUrls=customUrls.split(/\n/);
  884. for(let c=0;c<customUrls.length;c++){
  885. let urlArr=customUrls[c].split("|"),url,type=1;
  886. if(urlArr.length==1){
  887. url=urlArr[0].trim();
  888. if(!/^http/.test(url)){
  889. alert("Wrong url, check again!");
  890. return;
  891. }
  892. }else if(urlArr.length==2){
  893. type=urlArr[0].trim();
  894. url=urlArr[1].trim();
  895. if(!/^http/.test(url)){
  896. alert("Wrong url, check again!");
  897. return;
  898. }
  899. }else{
  900. break;
  901. }
  902. let maxId=0,hasUrl=false;;
  903. if(!rulesDate.urls){
  904. rulesDate.urls=[];
  905. maxId=1;
  906. }else{
  907. rulesDate.urls.forEach(u=>{
  908. if(maxId<u.id){
  909. maxId=u.id;
  910. }
  911. if(u.url==url){
  912. hasUrl=true;
  913. }
  914. });
  915. if(hasUrl)break;
  916. }
  917. rulesDate.urls.push({id:maxId+1,url:url,type:type});
  918. rulesDate.sort.push(maxId+1);
  919. storage.setItem("importRuleUrl", rulesDate);
  920. }
  921. }
  922. alert("Modified successfully");
  923. location.reload();
  924. };
  925. }
  926.  
  927. function objIsArr(obj) {
  928. return obj &&
  929. typeof obj === 'object' &&
  930. typeof obj.length === 'number' &&
  931. !(obj.propertyIsEnumerable('length'));
  932. }
  933.  
  934. function getFormatJSON(obj){
  935. if(!objIsArr(obj))return "";
  936. let ret="[\n";
  937. let len=obj.length,i=0,isLast;
  938. obj.forEach(item=>{
  939. ret+=" {\n";
  940. let iLen=Object.keys(item).length,j=0;
  941. for(let key in item){
  942. isLast=(++j)==iLen;
  943. let value=item[key];
  944. if(typeof value=="string"){
  945. value=value.replace("\\","\\\\");
  946. }
  947. ret+=" \""+key+"\":\""+value+"\""+(isLast?"":",")+"\n";
  948. }
  949. isLast=(++i)==len;
  950. ret+=" }"+(isLast?"":",")+"\n";
  951. });
  952. ret+="]";
  953. return ret;
  954. }
  955.  
  956. function getTimeStr(date){
  957. let now=new Date().getTime();
  958. let passTime=(now-date)/1000;
  959. if(passTime<60){
  960. updateDate=i18n("passSec", passTime);
  961. }else if(passTime<60*60){
  962. updateDate=i18n("passMin", parseInt(passTime/60));
  963. }else if(passTime<60*60*24){
  964. updateDate=i18n("passHour", parseInt(passTime/3600));
  965. }else{
  966. updateDate=i18n("passDay", parseInt(passTime/86400));
  967. }
  968. }
  969.  
  970. function initRules(callback) {
  971. /*0 wedata格式,1 pagetual格式*/
  972. ruleUrls=[
  973. {
  974. id:0,
  975. url:'http://wedata.net/databases/AutoPagerize/items_all.json',
  976. type:0,
  977. },
  978. {
  979. id:1,
  980. url:'https://raw.githubusercontent.com/hoothin/UserScripts/master/Pagetual/pagetualRules.json',
  981. type:1
  982. }
  983. ];var i=0,j=0;
  984.  
  985. ruleParser.initSavedRules(()=>{
  986. storage.getItem("importRuleUrl", data=>{
  987. if(data){
  988. rulesDate=data;
  989. if(data.urls)ruleUrls=ruleUrls.concat(data.urls);
  990. if(data.sort){
  991. let urls=[];
  992. data.sort.forEach(id=>{
  993. for(let s=0;s<ruleUrls.length;s++){
  994. if(id==ruleUrls[s].id){
  995. urls.push(ruleUrls[s]);
  996. break;
  997. }
  998. }
  999. });
  1000. ruleUrls=urls;
  1001. }
  1002. }
  1003. storage.getItem("forceState_"+location.host, v=>{
  1004. storage.getItem("ruleLastUpdate", date=>{
  1005. forceState=v||0;
  1006. getTimeStr(date);
  1007. initConfig();
  1008. if(forceState==1)return;
  1009. let now=new Date().getTime();
  1010. if(!date || now-date>3*24*60*60*1000){
  1011. storage.setItem("ruleLastUpdate", now);
  1012. ruleUrls.forEach(rule=>{
  1013. ruleParser.addRuleByUrl(rule.url, rule.type, rule.id, ()=>{
  1014. if(++i==ruleUrls.length){
  1015. callback();
  1016. }
  1017. })
  1018. });
  1019. }else{
  1020. callback();
  1021. }
  1022. });
  1023. });
  1024. });
  1025. });
  1026. }
  1027.  
  1028. function requestDoc(url, callback){
  1029. _GM_xmlhttpRequest({
  1030. url: url,
  1031. overrideMimeType:"text/html;charset="+document.charset,
  1032. onload: function(res) {
  1033. var doc=null;
  1034. try {
  1035. doc=document.implementation.createHTMLDocument('');
  1036. doc.documentElement.innerHTML=res.response;
  1037. }
  1038. catch (e) {
  1039. debug('parse error'+e.toString());
  1040. }
  1041. let pageElement=ruleParser.getPageElement(doc);
  1042. //只有1的話怕不是圖片哦
  1043. if(pageElement && (pageElement.length>1 || (pageElement.length==1 && pageElement[0].tagName!="IMG") )){
  1044. callback(pageElement);
  1045. ruleParser.insertPage(doc, pageElement, url);
  1046. }else{
  1047. requestFromIframe(url, (doc, eles)=>{
  1048. callback(eles);
  1049. if(eles){
  1050. ruleParser.insertPage(doc, eles, url);
  1051. }
  1052. });
  1053. }
  1054. },
  1055. onerror: function(e){
  1056. debug(e);
  1057. callback(false);
  1058. }
  1059. });
  1060. }
  1061.  
  1062. function requestFromIframe(url, callback){
  1063. let orgPage,curPage;
  1064. let iframe = document.createElement('iframe');
  1065. iframe.name = 'pagetual-iframe';
  1066. iframe.width = '100%';
  1067. iframe.height = '0';
  1068. iframe.frameBorder = '0';
  1069. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1070. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1071. iframe.addEventListener("load", e=>{
  1072. setTimeout(()=>{
  1073. //可能會延遲加載
  1074. try{
  1075. let doc=iframe.contentWindow.document;
  1076. let eles=ruleParser.getPageElement(doc);
  1077. if(eles && eles.length>0){
  1078. callback(doc, eles);
  1079. }else{
  1080. //isPause=true;
  1081. setTimeout(()=>{
  1082. callback(false, false);
  1083. },1000);
  1084. }
  1085. }catch(e){
  1086. isPause=true;
  1087. callback(false, false);
  1088. }
  1089. document.body.removeChild(iframe);
  1090. },300);
  1091. });
  1092. iframe.src=url;
  1093. document.body.appendChild(iframe);
  1094. }
  1095.  
  1096. function initPage(){
  1097. ruleParser.initPage(()=>{
  1098. initListener();
  1099. nextPage();
  1100. });
  1101. }
  1102.  
  1103. function initView(){
  1104. _GM_addStyle(`
  1105. .pagetual_pageBar.stop {
  1106. -webkit-filter: invert(100%);
  1107. filter: invert(100%);
  1108. opacity: 1;
  1109. }
  1110. .pagetual_pageBar {
  1111. opacity: 0.1;
  1112. }
  1113. .pagetual_pageBar:hover {
  1114. opacity: 1;
  1115. }
  1116. .pagetual_pageBar>span {
  1117. vertical-align: super;
  1118. }
  1119.  
  1120. .pagetual_pageBar>span>svg:hover {
  1121. animation: touhouAni 1s infinite;
  1122. }
  1123.  
  1124. @keyframes touhouAni{
  1125. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  1126. to {transform: rotate(360deg);}
  1127. }
  1128. @-webkit-keyframes touhouAni{
  1129. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  1130. to {transform: rotate(360deg);}
  1131. }
  1132. `);
  1133. }
  1134. var loading=document.createElement("div");
  1135. 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;";
  1136. 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>`;
  1137. document.body.appendChild(loading);
  1138.  
  1139. 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>`;
  1140. 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>`;
  1141. 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;`;
  1142. 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);`;
  1143.  
  1144. var isPause=false,isLoading=false,curPage=1,forceState=0;
  1145.  
  1146. function changeStop(stop){
  1147. isPause=stop;
  1148. [].forEach.call(document.querySelectorAll(".pagetual_pageBar"), bar=>{
  1149. if(isPause){
  1150. bar.classList.add("stop");
  1151. }else{
  1152. bar.classList.remove("stop");
  1153. }
  1154. });
  1155. }
  1156.  
  1157. function initListener(){
  1158. document.addEventListener('scroll', e=>{
  1159. setTimeout(()=>{
  1160. if(!isPause && !isLoading){
  1161. let scrolly=window.scrollY;
  1162. let windowHeight=window.innerHeight;
  1163. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  1164. if(scrollH-scrolly-windowHeight<800){
  1165. nextPage();
  1166. }
  1167. }
  1168. },100);
  1169. }, false);
  1170. document.addEventListener('dblclick', e=>{
  1171. changeStop(!isPause);
  1172. });
  1173. }
  1174.  
  1175. function createPageBar(url){
  1176. let insert=ruleParser.getInsert();
  1177. if(!insert || !insert.parentNode)return;
  1178. curPage++;
  1179. let inTable=insert.tagName=="TR" || insert.previousElementSibling.tagName=="TR";
  1180. let inLi=insert.tagName=="LI" || insert.previousElementSibling.tagName=="LI";
  1181. if(inLi){
  1182. let line=document.createElement("li");
  1183. line.innerHTML=curPage;
  1184. insert.parentNode.insertBefore(line, insert);
  1185. return line;
  1186. }
  1187. let pageBar=document.createElement(inTable?"tr":"div");
  1188. let upSpan=document.createElement("span");
  1189. let downSpan=document.createElement("span");
  1190. let pageText=document.createElement("a");
  1191. pageBar.className="pagetual_pageBar";
  1192. pageBar.id="pagetual_pageBar";
  1193. if(isPause){
  1194. pageBar.classList.add("stop");
  1195. }
  1196. pageBar.style.cssText=pageBarStyle;
  1197. pageBar.title=i18n(isPause?"enable":"disable");
  1198. upSpan.innerHTML=upSvg;
  1199. upSpan.title=i18n("toTop");
  1200. downSpan.innerHTML=downSvg;
  1201. downSpan.title=i18n("toBottom");
  1202. pageText.href=url;
  1203. pageText.style=pageTextStyle;
  1204. pageText.innerHTML="Page "+curPage;
  1205. pageText.title=i18n("current");
  1206. pageBar.appendChild(upSpan);
  1207. pageBar.appendChild(pageText);
  1208. pageBar.appendChild(downSpan);
  1209. if(inTable){
  1210. pageBar.style.display="table-row";
  1211. let td=document.createElement("td");
  1212. td.colSpan=99;
  1213. td.appendChild(upSpan);
  1214. td.appendChild(pageText);
  1215. td.appendChild(downSpan);
  1216. pageBar.appendChild(td);
  1217. }
  1218.  
  1219. upSpan.addEventListener("click", e=>{
  1220. changeStop(true);
  1221. document.body.scrollTop=0;
  1222. document.documentElement.scrollTop=0;
  1223. e.preventDefault();
  1224. e.stopPropagation();
  1225. });
  1226. downSpan.addEventListener("click", e=>{
  1227. changeStop(true);
  1228. document.body.scrollTop=9999999;
  1229. document.documentElement.scrollTop=9999999;
  1230. e.preventDefault();
  1231. e.stopPropagation();
  1232. });
  1233. pageBar.addEventListener("click", e=>{
  1234. changeStop(!isPause);
  1235. pageBar.title=i18n(isPause?"enable":"disable");
  1236. });
  1237. pageText.addEventListener("click", e=>{
  1238. e.stopPropagation();
  1239. });
  1240. pageBar.style.width=parseInt(_unsafeWindow.getComputedStyle(insert.parentNode).width)*.9+"px";
  1241. insert.parentNode.insertBefore(pageBar, insert);
  1242. return pageBar;
  1243. }
  1244.  
  1245. var emuIframe;
  1246. function emuPage(callback){
  1247. let orgPage,curPage,iframeDoc,times=0;
  1248. function checkPage(){
  1249. if(times++ > 20){
  1250. isPause=true;
  1251. callback(false, false);
  1252. return;
  1253. }
  1254. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  1255. let eles=ruleParser.getPageElement(iframeDoc);
  1256. if(orgPage == eles[0]){
  1257. setTimeout(()=>{
  1258. checkPage(iframeDoc);
  1259. },500);
  1260. }else{
  1261. if(eles && eles.length>0){
  1262. callback(iframeDoc, eles);
  1263. }else{
  1264. isPause=true;
  1265. callback(false, false);
  1266. }
  1267. }
  1268. }
  1269. if(!emuIframe){
  1270. emuIframe = document.createElement('iframe');
  1271. emuIframe.name = 'pagetual-iframe';
  1272. emuIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1273. emuIframe.width = '100%';
  1274. emuIframe.height = '0';
  1275. emuIframe.frameBorder = '0';
  1276. emuIframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1277. emuIframe.addEventListener("load", e=>{
  1278. setTimeout(()=>{
  1279. orgPage=ruleParser.getPageElement(iframeDoc)[0];
  1280. ruleParser.getNextLink(iframeDoc).click();
  1281. checkPage(iframeDoc);
  1282. },300);
  1283. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  1284. });
  1285. emuIframe.src=location.href;
  1286. document.body.appendChild(emuIframe);
  1287. }else{
  1288. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  1289. orgPage=ruleParser.getPageElement(iframeDoc)[0];
  1290. ruleParser.getNextLink(iframeDoc).click();
  1291. checkPage(iframeDoc);
  1292. }
  1293. }
  1294.  
  1295. function forceIframe(url, callback){
  1296. let curIframe = document.createElement('iframe');
  1297. //curIframe.name = 'pagetual-iframe';
  1298. curIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1299. curIframe.frameBorder = '0';
  1300. curIframe.scrolling="no";
  1301. 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;';
  1302. curIframe.addEventListener("load", e=>{
  1303. let iframeDoc=curIframe.contentDocument || curIframe.contentWindow.document;
  1304. let eles=ruleParser.getPageElement(iframeDoc);
  1305. if(eles && eles.length>0){
  1306. ruleParser.insertPage(iframeDoc, [], url);
  1307. callback(curIframe, eles);
  1308. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  1309. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  1310. curIframe.scrollIntoView();
  1311. }else{
  1312. isPause=true;
  1313. callback(false, false);
  1314. curIframe.parentNode.removeChild(curIframe);
  1315. }
  1316. });
  1317. curIframe.src=url;
  1318. let insert=ruleParser.getInsert();
  1319. document.body.appendChild(curIframe);
  1320. return curIframe;
  1321. }
  1322.  
  1323. function nextPage(){
  1324. if(isPause || isLoading)return;
  1325. let nextLink=ruleParser.getNextLink();
  1326. let insert=ruleParser.getInsert();
  1327. if(nextLink && insert){
  1328. debug(nextLink);
  1329. let isJs=/^(javascript|#)/.test(nextLink.href);
  1330. if(location.protocol=="https:" && /^http:/.test(nextLink.href)){
  1331. nextLink.href=nextLink.href.replace(/^http/,"https");
  1332. }
  1333. isLoading=true;
  1334. loading.style.display="";
  1335. if(ruleParser.curSiteRule.action==1 && !isJs){
  1336. requestFromIframe(nextLink.href, (doc, eles)=>{
  1337. isLoading=false;
  1338. loading.style.display="none";
  1339. if(eles){
  1340. createPageBar(nextLink.href);
  1341. ruleParser.insertPage(doc, eles, nextLink.href);
  1342. }
  1343. });
  1344. }else if(forceState==2 && !isJs){
  1345. forceIframe(nextLink.href, (iframe, eles)=>{
  1346. isLoading=false;
  1347. loading.style.display="none";
  1348. if(eles){
  1349. let pageBar=createPageBar(nextLink.href);
  1350. iframe.parentNode.insertBefore(pageBar, iframe);
  1351. }
  1352. });
  1353. }else{
  1354. if(!isJs){
  1355. requestDoc(nextLink.href, (eles)=>{
  1356. isLoading=false;
  1357. loading.style.display="none";
  1358. if(eles){
  1359. createPageBar(nextLink.href);
  1360. }
  1361. });
  1362. }else{
  1363. emuPage((doc, eles)=>{
  1364. isLoading=false;
  1365. loading.style.display="none";
  1366. if(eles){
  1367. createPageBar(nextLink.href);
  1368. ruleParser.insertPage(doc, eles, "");
  1369. }
  1370. });
  1371. }
  1372. }
  1373. }
  1374. }
  1375.  
  1376. function init(){
  1377. initView();
  1378. initRules(()=>{
  1379. initPage();
  1380. });
  1381. }
  1382. init();
  1383. })();