东方永页机

自动翻页

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

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