东方永页机

自动翻页

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

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