东方永页机

自动翻页

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

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