东方永页机

自动翻页

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

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