东方永页机

自动翻页

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

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址