东方永页机

自动翻页

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

  1. // ==UserScript==
  2. // @name Pagetual
  3. // @name:zh-CN 东方永页机
  4. // @name:zh-TW 東方永頁機
  5. // @name:ja 東方永頁機
  6. // @namespace hoothin
  7. // @version 0.4.1
  8. // @description Simply auto load the next page
  9. // @description:zh-CN 自动翻页
  10. // @description:zh-TW 自動翻頁
  11. // @description:ja Webページを自動で読み込み継ぎ足し表示を行うブラウザ拡張です。
  12. // @author hoothin
  13. // @include http://*
  14. // @include https://*
  15. // @license MIT
  16. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAdVBMVEUAAADZHQbYHQXaHQbYHgbZHATYHgbYHgbZHQXYHgXZHgbZHgfYHQXYHQbXHQDYHgbYHgbYHQXZHgbYHgbYHgbYHgXaHQbYHQbYHQbZHgbZHgbZHQbZHgbYHgbYHQbYHQXYHgfaHwDZHQXZHQbYHwTVHQrYHgbCqWmRAAAAJnRSTlMAUL8oyD/el2cy1CCPcg/35euggPG6FajOr4Z617OdXkkIi1g4GcTbfAwAAAJDSURBVFjD7dbXtqpADADQ0NsA0hHQY83/f+K9rqNOCzPwfvaTugimjEH4s86739yX0+3n8dwd7dQh/seiaWbHscUqCnZEP24LvrXjXLyyaVJMp2RbeFajZInhJWCHcurB7idEVfS+89SGsS28qJFwyN59ZcgsnXeRVrwvSNLFNJEA1/jfDqW4Po8Z1+XwsX6HGA1Cft1Y0ndw0OjCrwxDj4hPDqgYXbGlZ35pj0fQ1dr0C4DM5++lZHMt/qLNXq2rAG5qtWPdoaL5/ZwXloHAP1onUKs3SOSOO5YEsFNLkJN2T/IRRt0gj6ZUUpZTyMmzUx/Vw8wVhwgEI9pog2PiHRO0OhTq2hLnytBK3yRdsKeCGjRnoagKLRbQNfwsXdGiAkLMu5ihWUSvr5S/tPWPlIV8kxvn58CKatMu7Ly1+Kzcsgwj0wqXlgnNMT7CrFPwwaTp+OsSKS4Y1UJ5Phl/BSM3F7JBQmKO78UGJWT/zWJpTae7E4CTtJcnVJ2E7dV4RAWlY36uM96gFnHQT0HFe0zOIZYbnGsVRJZHc/DZFS15pu54URfUSgYJvVJ8BgpPWWu3TwfJUxkvPahylAzy573ybXfQHVEUFt/2uC67KgWcybPp602gndMMKF647bfIUg9oQYmCH6B1PF7jHFDQk2n6PJ7gDcil1FekowdGuVBGqw7rGZXNFSweLnJRJo4pD4cENphb/CoH57O6o8q/wzbJtCBXuXVz7sqQBbBDMJ9a6e+SA/tlzjx0Q3TLL0/4Y/QPSYfEIomUUSEAAAAASUVORK5CYII=
  17. // @grant GM_xmlhttpRequest
  18. // @grant GM_registerMenuCommand
  19. // @grant GM_notification
  20. // @grant GM_getValue
  21. // @grant GM_setValue
  22. // @grant GM_addStyle
  23. // @grant GM.xmlHttpRequest
  24. // @grant GM.registerMenuCommand
  25. // @grant GM.notification
  26. // @grant GM.getValue
  27. // @grant GM.setValue
  28. // @grant GM.addStyle
  29. // @connect wedata.net
  30. // @connect githubusercontent.com
  31. // @run-at document-idle
  32. // ==/UserScript==
  33.  
  34. (function() {
  35. 'use strict';
  36.  
  37. if (window.name === 'pagetual-iframe') {
  38. var domloaded = function (){
  39. window.scroll(window.scrollX, 99999);
  40. //window.parent.postMessage('pagetual-iframe:DOMLoaded', '*');
  41. };
  42. if(window.opera){
  43. document.addEventListener('DOMContentLoaded', domloaded, false);
  44. } else {
  45. domloaded();
  46. }
  47. return;
  48. }
  49.  
  50. if(window.top != window.self){
  51. return;
  52. }
  53.  
  54. const lang = navigator.appName=="Netscape"?navigator.language:navigator.userLanguage;
  55. var i18n=(name, param)=>{
  56. let config={};
  57. switch (lang){
  58. case "zh-CN":
  59. case "zh-SG":
  60. config={
  61. disable:"暂时禁用",
  62. 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 "ja":
  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, curWin) {
  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. if(!curWin)curWin=_unsafeWindow;
  485. let body=doc.body,bodyHeight=parseInt(curWin.getComputedStyle(body).height);
  486. function checkElement(ele){
  487. let curHeight=parseInt(curWin.getComputedStyle(ele).height);
  488. if(curHeight/bodyHeight<=0.35)return null;
  489. if(ele.children.length==0){
  490. self.curSiteRule.pageElement=self.geneSelector(ele.parentNode)+">"+ele.tagName;
  491. self.curSiteRule.type=1;
  492. debug(self.curSiteRule.pageElement);
  493. return [ele];
  494. }
  495. let i,maxHeight=curHeight*0.35,curMaxEle=null,curMaxArea=0;
  496. for(i=0;i<ele.children.length;i++){
  497. let curNode=ele.children[i];
  498. if(curNode.innerText=="")continue;
  499. let comStyle=curWin.getComputedStyle(curNode);
  500. let h=parseInt(comStyle.height);
  501. let w=parseInt(comStyle.width);
  502. if(isNaN(h) || isNaN(w))continue;
  503. let a=h*w+h,moreChild=curNode.children[0];
  504. while(moreChild){
  505. comStyle=curWin.getComputedStyle(moreChild);
  506. let ch=parseInt(comStyle.height);
  507. let cw=parseInt(comStyle.width);
  508. if(moreChild.innerText!="" && !isNaN(ch) && !isNaN(cw)){
  509. a+=ch*cw;
  510. }
  511. moreChild=moreChild.nextElementSibling;
  512. }
  513. if(curMaxEle==null || curMaxArea<a){
  514. curHeight=h;
  515. curMaxArea=a;
  516. curMaxEle=curNode;
  517. }
  518. }
  519. if(curHeight>maxHeight){
  520. return checkElement(curMaxEle);
  521. }
  522. self.curSiteRule.pageElement=self.geneSelector(ele)+">*";
  523. self.curSiteRule.type=1;
  524. debug(self.curSiteRule.pageElement);
  525. return ele.children;
  526. }
  527. pageElement=checkElement(body);
  528. //if(pageElement)this.saveCurSiteRule();
  529. }
  530. return pageElement;
  531. }
  532.  
  533. getPage(){
  534. let canSave=false;//發現頁碼選擇器在其他頁對不上,還是別保存了
  535. let url=this.curUrl;
  536. let doc=this.pageDoc;
  537. let pageNum=0,preStr="",afterStr="";
  538. let pageMatch1=url.match(/(.*[a-zA-Z0-9\/][\-_](?:p|page)?)(\d+)(\.html?$|$)/i);
  539. let pageMatch2=url.match(/(.*[\?&]p(?:age)?=)(\d+)($|[#&].*)/i);
  540. if(pageMatch1){
  541. preStr=pageMatch1[1];
  542. pageNum=pageMatch1[2];
  543. afterStr=pageMatch1[3];
  544. }else if(pageMatch2){
  545. preStr=pageMatch2[1];
  546. pageNum=pageMatch2[2];
  547. afterStr=pageMatch2[3];
  548. }
  549. var curPage=doc,i,cur;
  550. let next=curPage.querySelector("a.next");
  551. if(!next)next=curPage.querySelector("a#next");
  552. if(!next)next=curPage.querySelector("a#rightFix");
  553. if(!next)next=curPage.querySelector("a.next_page");
  554. if(next && (!next.href || /javascript:/.test(next.href)))next=null;
  555. if(!next)next=curPage.querySelector(".next>a");
  556. if(!next){
  557. let pageDiv=curPage.querySelector("div.wp-pagenavi");
  558. if(pageDiv){
  559. cur=pageDiv.querySelector("span.current");
  560. next=cur.nextSibling;
  561. }else{
  562. cur=curPage.querySelector("div.article-paging>span");
  563. if(cur){
  564. next=cur.nextElementSibling;
  565. }
  566. }
  567. }
  568. if(!next){
  569. let pageDiv=curPage.querySelector("div.pages>ul");
  570. if(pageDiv){
  571. cur=pageDiv.querySelector("li>b");
  572. if(cur)next=cur.parentNode.nextElementSibling.querySelector("a");
  573. }
  574. }
  575. if(!next){
  576. let aTags=curPage.querySelectorAll("a");
  577. let nextf,nexts,nextt,nextfo;
  578. for(i=0;i<aTags.length;i++){
  579. let aTag=aTags[i];
  580. if(nextf && nexts && nextt)break;
  581. if(!nextf){
  582. if(/(\s|^)下[一1]?[页頁张張]|^next( page)?\s*$|次のページ/i.test(aTag.innerText)){
  583. if(!aTag.href || /javascript:/.test(aTag.href)){
  584. nextfo=aTag;
  585. }else{
  586. nextf=aTag;
  587. }
  588. }
  589. }
  590. if(!nexts){
  591. if(aTag.innerText=="&gt;"){
  592. if(!aTag.href || /javascript:/.test(aTag.href)){
  593. nextfo=aTag;
  594. }else{
  595. nexts=aTag;
  596. }
  597. }
  598. }
  599. if(!aTag.href || /javascript:/.test(aTag.href))continue;
  600. if(!nextt){
  601. aTag.href=aTag.href.replace(/\?&/,"?");
  602. if(aTag.innerText=="»"){
  603. nextt=aTag;
  604. }else if(aTag.href.replace(preStr,"").replace(afterStr,"")==parseInt(pageNum)+1){
  605. nextt=aTag;
  606. }else if(aTag.href.indexOf(url)!=-1 && /^[\/\?&]?[_-]?(p|page)?=?[12](\?|&|$)/i.test(aTag.href.replace(url,""))){
  607. nextt=aTag;
  608. }
  609. }
  610. }
  611. next=nextf||nexts||nextt||nextfo;
  612. }
  613. if(!next)next=curPage.querySelector('[rel="next"]');
  614. return {next:next,canSave:canSave};
  615. }
  616.  
  617. getNextLink(doc) {
  618. let nextLink=null,page;
  619. let curDoc=doc||this.pageDoc;
  620. if(this.curSiteRule.nextLinkByUrl){
  621. let targetUrl=this.curUrl.replace(new RegExp(this.curSiteRule.nextLinkByUrl[0]), this.curSiteRule.nextLinkByUrl[1]);
  622. if(targetUrl != this.curUrl){
  623. let reps=targetUrl.match(/{.*?}/g);
  624. if(reps){
  625. reps.forEach(rep=>{
  626. let code=rep.replace("{","").replace("}","");
  627. let result=_unsafeWindow.eval(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,curDoc,curDoc):curDoc.querySelector(this.curSiteRule.nextLink);
  635. }
  636. if(!nextLink){
  637. page=this.getPage();
  638. nextLink=page.next;
  639. }
  640. if(nextLink){
  641. if(!this.basePageElement){
  642. this.basePageElement=this.getPageElement(document);
  643. }
  644. if(!this.curSiteRule.nextLink && page && page.canSave){
  645. this.curSiteRule.nextLink=this.geneSelector(nextLink);
  646. this.curSiteRule.type=1;
  647. this.saveCurSiteRule();
  648. }
  649. }
  650. return nextLink;
  651. }
  652.  
  653. getInsert(refresh) {
  654. if(this.insert && !refresh && this.insert.parentNode)return this.insert;
  655. if(this.curSiteRule.insert){
  656. this.insert=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.insert,document):document.querySelector(this.curSiteRule.insert);
  657. }else{
  658. let pageElement=this.basePageElement;
  659. if(pageElement && pageElement.length>0){
  660. var pELast = pageElement[pageElement.length - 1];
  661. this.insert = pELast.nextSibling ? pELast.nextSibling : pELast.parentNode.appendChild(document.createTextNode(' '));
  662. }
  663. }
  664. return this.insert;
  665. }
  666.  
  667. pageAction(document,eles){
  668. let code=this.curSiteRule.pageAction;
  669. if(code){
  670. _unsafeWindow.eval(code);
  671. }
  672. let css=this.curSiteRule.css;
  673. if(css){
  674. _GM_addStyle(css);
  675. }
  676. [].forEach.call(eles, ele=>{
  677. [].forEach.call(ele.querySelectorAll("img"), img=>{
  678. //if(img.src==""){
  679. let realSrc;
  680. if(img.dataset && img.dataset.original){
  681. realSrc=img.dataset.original;
  682. }else if(img.dataset && img.dataset.src){
  683. realSrc=img.dataset.src;
  684. }else if(img._lazyrias && img._lazyrias.srcset){
  685. realSrc=img._lazyrias.srcset[img._lazyrias.srcset.length-1];
  686. }else if(img.dataset && img.dataset.origFile){
  687. realSrc=img.dataset.origFile;
  688. }else if(img.srcset){
  689. var srcs=img.srcset.split(","),largeSize=0;
  690. srcs.forEach(srci=>{
  691. let srcInfo=srci.trim().split(" "),curSize=parseInt(srcInfo[1]);
  692. if(srcInfo[1] && curSize>largeSize){
  693. largeSize=curSize;
  694. realSrc=srcInfo[0];
  695. }
  696. });
  697. }
  698. if(realSrc)img.src=realSrc;
  699. //}
  700. });
  701. });
  702. let lazyImgSrc=this.curSiteRule.lazyImgSrc;
  703. if(lazyImgSrc){
  704. [].forEach.call(eles, ele=>{
  705. [].forEach.call(ele.querySelectorAll("img"), img=>{
  706. if(img[lazyImgSrc]){
  707. img.src=img[lazyImgSrc];
  708. }
  709. });
  710. });
  711. }
  712. }
  713.  
  714. initPage(callback){
  715. let self=this;
  716. this.getRule(()=>{
  717. callback();
  718. let code=self.curSiteRule.init;
  719. if(code){
  720. _unsafeWindow.eval(code);
  721. }
  722. });
  723. }
  724.  
  725. insertPage(doc, eles, url){
  726. this.pageDoc=doc;
  727. this.curUrl=url;
  728. this.pageAction(doc, eles);
  729. this.getInsert();
  730. var self=this;
  731. if(!eles || eles.length==0 || !self.insert || !self.insert.parentNode){
  732. }else{
  733. [].forEach.call(eles, ele=>{
  734. if(self.curSiteRule.insertPos==2){
  735. self.insert.appendChild(ele.cloneNode(true));
  736. }else{
  737. self.insert.parentNode.insertBefore(ele.cloneNode(true), self.insert);
  738. }
  739. });
  740. }
  741. }
  742. }
  743. var ruleParser = new RuleParser();
  744.  
  745. var rulesDate={},ruleUrls,updateDate;
  746. function initConfig(){
  747. _GM_registerMenuCommand(i18n(forceState==1?"enable":"disable"), ()=>{
  748. storage.setItem("forceState_"+location.host, (forceState==1?0:1));
  749. location.reload();
  750. });
  751.  
  752. _GM_registerMenuCommand(i18n(forceState==2?"cancelForceIframe":"forceIframe"), ()=>{
  753. storage.setItem("forceState_"+location.host, (forceState==2?0:2));
  754. location.reload();
  755. });
  756. var configCon,insertPos;
  757. if(location.href=="https://github.com/hoothin/UserScripts/tree/master/Pagetual"){
  758. _GM_addStyle(`
  759. p>span:nth-child(1),p>span:nth-child(2),p>span:nth-child(3){
  760. cursor: pointer;
  761. user-select: none;
  762. }
  763. p>span:nth-child(1):hover,p>span:nth-child(2):hover,p>span:nth-child(3):hover{
  764. color:red;
  765. }
  766. .updateDate{
  767. cursor: pointer;
  768. user-select: none;
  769. }
  770. .updateDate:hover{
  771. color:red;
  772. }
  773. `);
  774. configCon=document.querySelector(".markdown-body");
  775. insertPos=configCon.querySelector("hr");
  776. }else if(location.href=="https://github.com/hoothin/UserScripts/tree/master/Pagetual"){
  777. }else return;
  778. class Rulebar {
  779. init(ruleUrl){
  780. this.ruleUrl=ruleUrl;
  781. this.item=document.createElement("p");
  782. this.item.title=ruleUrl.type==0?"AutoPagerize Rules":"Pagetual Rules";
  783. this.item.dataset.id=this.ruleUrl.id;
  784. let url=document.createElement("span");
  785. url.innerHTML=ruleUrl.url;
  786. let up=document.createElement("span");
  787. up.innerHTML="↑ ";
  788. let down=document.createElement("span");
  789. down.innerHTML="↓ ";
  790. let del=document.createElement("span");
  791. del.innerHTML="× ";
  792. up.onclick=e=>{
  793. this.moveUp();
  794. };
  795. down.onclick=e=>{
  796. this.moveDown();
  797. };
  798. del.onclick=e=>{
  799. this.del();
  800. };
  801. this.item.appendChild(up);
  802. this.item.appendChild(down);
  803. this.item.appendChild(del);
  804. this.item.appendChild(url);
  805. configCon.insertBefore(this.item, insertPos);
  806. }
  807. saveSort(){
  808. let sort=[];
  809. [].forEach.call(this.item.parentNode.querySelectorAll("p[data-id]"), i=>{
  810. sort.push(i.dataset.id);
  811. });
  812. rulesDate.sort=sort;
  813. storage.setItem("importRuleUrl", rulesDate);
  814. }
  815. moveUp(){
  816. let preE=this.item.previousElementSibling;
  817. if(preE.tagName=="P" && preE.children.length>1){
  818. this.item.parentNode.insertBefore(this.item,preE);
  819. this.saveSort();
  820. }
  821. }
  822. moveDown(){
  823. let nextE=this.item.nextElementSibling;
  824. if(nextE.tagName=="P" && nextE.children.length>1){
  825. this.item.parentNode.insertBefore(nextE,this.item);
  826. this.saveSort();
  827. }
  828. }
  829. del(){
  830. if(this.ruleUrl.id<2){
  831. alert(i18n("cantDel"));
  832. }else if(window.confirm(i18n("confirmDel"))){
  833. for(let u=0;u<rulesDate.urls.length;u++){
  834. if(this.ruleUrl.id==rulesDate.urls[u].id){
  835. rulesDate.urls.splice(u,1);
  836. break;
  837. }
  838. }
  839. for(let u=0;u<rulesDate.sort.length;u++){
  840. if(this.ruleUrl.id==rulesDate.sort[u]){
  841. rulesDate.sort.splice(u,1);
  842. break;
  843. }
  844. }
  845. storage.setItem("importRuleUrl", rulesDate);
  846. ruleParser.rules=ruleParser.rules.filter(item=>{return item.from!=this.ruleUrl.id});
  847. storage.setItem("rules", ruleParser.rules);
  848. this.item.parentNode.removeChild(this.item);
  849. //location.reload();
  850. }
  851. }
  852. }
  853. let updateP=document.createElement("p"),i=0;
  854. let now=new Date().getTime(),inUpdate=false;
  855. updateP.className="updateDate";
  856. updateP.innerHTML=updateDate;
  857. updateP.title=i18n("update");
  858. updateP.onclick=e=>{
  859. if(inUpdate)return;
  860. inUpdate=true;
  861. ruleUrls.forEach(rule=>{
  862. ruleParser.addRuleByUrl(rule.url, rule.type, rule.id, ()=>{
  863. if(++i==ruleUrls.length){
  864. storage.setItem("ruleLastUpdate", now);
  865. alert(i18n("updateSucc"));
  866. inUpdate=false;
  867. updateP.innerHTML=i18n("passSec", 0);
  868. }
  869. })
  870. });
  871. alert(i18n("beginUpdate"));
  872. };
  873. configCon.insertBefore(updateP, insertPos);
  874. if(ruleUrls){
  875. ruleUrls.forEach(ruleUrl=>{
  876. var rulebar=new Rulebar();
  877. rulebar.init(ruleUrl);
  878. });
  879. }
  880. let customUrlsTitle=document.createElement("h2");
  881. customUrlsTitle.innerHTML=i18n("customUrls")
  882. configCon.insertBefore(customUrlsTitle, insertPos);
  883. let customUrlsInput=document.createElement("textarea");
  884. customUrlsInput.style.width="100%";
  885. customUrlsInput.placeholder="0|http://wedata.net/databases/AutoPagerize/items_all.json";
  886. configCon.insertBefore(customUrlsInput, insertPos);
  887. let customRulesTitle=document.createElement("h2");
  888. customRulesTitle.innerHTML=i18n("customRules")
  889. configCon.insertBefore(customRulesTitle, insertPos);
  890. let customRulesInput=document.createElement("textarea");
  891. customRulesInput.style.width="100%";
  892. customRulesInput.style.height="500px";
  893. 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]`;
  894. customRulesInput.value=getFormatJSON(ruleParser.customRules);
  895. configCon.insertBefore(customRulesInput, insertPos);
  896. let saveBtn=document.createElement("button");
  897. saveBtn.innerHTML=i18n("save");
  898. saveBtn.style.width="100%";
  899. configCon.insertBefore(saveBtn, insertPos);
  900. saveBtn.onclick=e=>{
  901. try{
  902. if(customRulesInput.value==""){
  903. storage.setItem("customRules", "");
  904. }else{
  905. let customRules=JSON.parse(customRulesInput.value);
  906. debug(customRules);
  907. storage.setItem("customRules", customRules);
  908. }
  909. }catch(e){
  910. debug(e);
  911. alert("JSON error, check again!");
  912. return;
  913. }
  914. let customUrls=customUrlsInput.value.trim();
  915. if(customUrls){
  916. customUrls=customUrls.split(/\n/);
  917. for(let c=0;c<customUrls.length;c++){
  918. let urlArr=customUrls[c].split("|"),url,type=1;
  919. if(urlArr.length==1){
  920. url=urlArr[0].trim();
  921. if(!/^http/.test(url)){
  922. alert("Wrong url, check again!");
  923. return;
  924. }
  925. }else if(urlArr.length==2){
  926. type=urlArr[0].trim();
  927. url=urlArr[1].trim();
  928. if(!/^http/.test(url)){
  929. alert("Wrong url, check again!");
  930. return;
  931. }
  932. }else{
  933. break;
  934. }
  935. let maxId=0,hasUrl=false;;
  936. if(!rulesDate.urls){
  937. rulesDate.urls=[];
  938. maxId=1;
  939. }else{
  940. rulesDate.urls.forEach(u=>{
  941. if(maxId<u.id){
  942. maxId=u.id;
  943. }
  944. if(u.url==url){
  945. hasUrl=true;
  946. }
  947. });
  948. if(hasUrl)break;
  949. }
  950. rulesDate.urls.push({id:maxId+1,url:url,type:type});
  951. rulesDate.sort.push(maxId+1);
  952. storage.setItem("importRuleUrl", rulesDate);
  953. }
  954. }
  955. alert("Modified successfully");
  956. location.reload();
  957. };
  958. }
  959.  
  960. function objIsArr(obj) {
  961. return obj &&
  962. typeof obj === 'object' &&
  963. typeof obj.length === 'number' &&
  964. !(obj.propertyIsEnumerable('length'));
  965. }
  966.  
  967. function getFormatJSON(obj){
  968. if(!objIsArr(obj))return "";
  969. let ret="[\n";
  970. let len=obj.length,i=0,isLast;
  971. obj.forEach(item=>{
  972. ret+=" {\n";
  973. let iLen=Object.keys(item).length,j=0;
  974. for(let key in item){
  975. isLast=(++j)==iLen;
  976. let value=item[key];
  977. if(typeof value=="string"){
  978. value=value.replace(/\\/g,"\\\\");
  979. }
  980. ret+=" \""+key+"\":\""+value+"\""+(isLast?"":",")+"\n";
  981. }
  982. isLast=(++i)==len;
  983. ret+=" }"+(isLast?"":",")+"\n";
  984. });
  985. ret+="]";
  986. return ret;
  987. }
  988.  
  989. function getTimeStr(date){
  990. let now=new Date().getTime();
  991. let passTime=(now-date)/1000;
  992. if(passTime<60){
  993. updateDate=i18n("passSec", passTime);
  994. }else if(passTime<60*60){
  995. updateDate=i18n("passMin", parseInt(passTime/60));
  996. }else if(passTime<60*60*24){
  997. updateDate=i18n("passHour", parseInt(passTime/3600));
  998. }else{
  999. updateDate=i18n("passDay", parseInt(passTime/86400));
  1000. }
  1001. }
  1002.  
  1003. function initRules(callback) {
  1004. /*0 wedata格式,1 pagetual格式*/
  1005. ruleUrls=[
  1006. {
  1007. id:0,
  1008. url:'http://wedata.net/databases/AutoPagerize/items_all.json',
  1009. type:0,
  1010. },
  1011. {
  1012. id:1,
  1013. url:'https://raw.githubusercontent.com/hoothin/UserScripts/master/Pagetual/pagetualRules.json',
  1014. type:1
  1015. }
  1016. ];var i=0,j=0;
  1017.  
  1018. ruleParser.initSavedRules(()=>{
  1019. storage.getItem("importRuleUrl", data=>{
  1020. if(data){
  1021. rulesDate=data;
  1022. if(data.urls)ruleUrls=ruleUrls.concat(data.urls);
  1023. if(data.sort){
  1024. let urls=[];
  1025. data.sort.forEach(id=>{
  1026. for(let s=0;s<ruleUrls.length;s++){
  1027. if(id==ruleUrls[s].id){
  1028. urls.push(ruleUrls[s]);
  1029. break;
  1030. }
  1031. }
  1032. });
  1033. ruleUrls=urls;
  1034. }
  1035. }
  1036. storage.getItem("forceState_"+location.host, v=>{
  1037. storage.getItem("ruleLastUpdate", date=>{
  1038. forceState=v||0;
  1039. getTimeStr(date);
  1040. initConfig();
  1041. if(forceState==1)return;
  1042. let now=new Date().getTime();
  1043. if(!date || now-date>3*24*60*60*1000){
  1044. storage.setItem("ruleLastUpdate", now);
  1045. ruleUrls.forEach(rule=>{
  1046. ruleParser.addRuleByUrl(rule.url, rule.type, rule.id, ()=>{
  1047. if(++i==ruleUrls.length){
  1048. callback();
  1049. }
  1050. })
  1051. });
  1052. }else{
  1053. callback();
  1054. }
  1055. });
  1056. });
  1057. });
  1058. });
  1059. }
  1060.  
  1061. function requestDoc(url, callback){
  1062. _GM_xmlhttpRequest({
  1063. url: url,
  1064. overrideMimeType:"text/html;charset="+document.charset,
  1065. onload: function(res) {
  1066. var doc=null;
  1067. try {
  1068. doc=document.implementation.createHTMLDocument('');
  1069. doc.documentElement.innerHTML=res.response;
  1070. }
  1071. catch (e) {
  1072. debug('parse error'+e.toString());
  1073. }
  1074. let pageElement=ruleParser.getPageElement(doc);
  1075. //只有1的話怕不是圖片哦
  1076. if(pageElement && (pageElement.length>1 || (pageElement.length==1 && pageElement[0].tagName!="IMG") )){
  1077. callback(pageElement);
  1078. ruleParser.insertPage(doc, pageElement, url);
  1079. }else{
  1080. requestFromIframe(url, (doc, eles)=>{
  1081. callback(eles);
  1082. if(eles){
  1083. ruleParser.insertPage(doc, eles, url);
  1084. }
  1085. });
  1086. }
  1087. },
  1088. onerror: function(e){
  1089. debug(e);
  1090. callback(false);
  1091. }
  1092. });
  1093. }
  1094.  
  1095. var failFromIframe=0;
  1096. function requestFromIframe(url, callback){
  1097. let orgPage,curPage;
  1098. let iframe = document.createElement('iframe');
  1099. iframe.name = 'pagetual-iframe';
  1100. iframe.width = '100%';
  1101. iframe.height = '0';
  1102. iframe.frameBorder = '0';
  1103. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1104. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1105. iframe.addEventListener("load", e=>{
  1106. setTimeout(()=>{
  1107. //可能會延遲加載
  1108. try{
  1109. let doc=iframe.contentWindow.document;
  1110. let eles=ruleParser.getPageElement(doc, iframe.contentWindow);
  1111. if(eles && eles.length>0){
  1112. callback(doc, eles);
  1113. }else if(failFromIframe++ > 3){
  1114. failFromIframe=0;
  1115. isPause=true;
  1116. callback(false, false);
  1117. }else{
  1118. //isPause=true;
  1119. setTimeout(()=>{
  1120. callback(false, false);
  1121. },1000);
  1122. }
  1123. }catch(e){
  1124. isPause=true;
  1125. callback(false, false);
  1126. }
  1127. document.body.removeChild(iframe);
  1128. },300);
  1129. });
  1130. iframe.src=url;
  1131. document.body.appendChild(iframe);
  1132. }
  1133.  
  1134. function initPage(){
  1135. ruleParser.initPage(()=>{
  1136. initListener();
  1137. nextPage();
  1138. });
  1139. }
  1140.  
  1141. function initView(){
  1142. _GM_addStyle(`
  1143. .pagetual_pageBar.stop {
  1144. -webkit-filter: invert(100%);
  1145. filter: invert(100%);
  1146. opacity: 1;
  1147. }
  1148. .pagetual_pageBar.hide {
  1149. display: none!important;
  1150. }
  1151. .pagetual_pageBar {
  1152. opacity: 0.1;
  1153. }
  1154. .pagetual_pageBar:hover {
  1155. opacity: 1;
  1156. }
  1157. .pagetual_pageBar>span {
  1158. vertical-align: super;
  1159. }
  1160.  
  1161. .pagetual_pageBar>span>svg:hover {
  1162. animation: touhouAni 1s infinite;
  1163. }
  1164.  
  1165. @keyframes touhouAni{
  1166. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  1167. to {transform: rotate(360deg);}
  1168. }
  1169. @-webkit-keyframes touhouAni{
  1170. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  1171. to {transform: rotate(360deg);}
  1172. }
  1173. `);
  1174. }
  1175. var loading=document.createElement("div");
  1176. 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;";
  1177. 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>`;
  1178. document.body.appendChild(loading);
  1179.  
  1180. 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>`;
  1181. 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>`;
  1182. 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;`;
  1183. 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);`;
  1184.  
  1185. var isPause=false,isLoading=false,curPage=1,forceState=0;
  1186.  
  1187. function changeStop(stop, hide){
  1188. isPause=stop;
  1189. [].forEach.call(document.querySelectorAll(".pagetual_pageBar"), bar=>{
  1190. if(isPause){
  1191. bar.classList.add("stop");
  1192. if(hide)bar.classList.add("hide");
  1193. }else{
  1194. bar.classList.remove("stop");
  1195. if(hide)bar.classList.remove("hide");
  1196. }
  1197. });
  1198. }
  1199.  
  1200. function initListener(){
  1201. document.addEventListener('scroll', e=>{
  1202. setTimeout(()=>{
  1203. if(!isPause && !isLoading){
  1204. let scrolly=window.scrollY;
  1205. let windowHeight=window.innerHeight;
  1206. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  1207. if(scrollH-scrolly-windowHeight<1000){
  1208. nextPage();
  1209. }
  1210. }
  1211. },100);
  1212. }, false);
  1213. document.addEventListener('dblclick', e=>{
  1214. changeStop(!isPause, true);
  1215. });
  1216. }
  1217.  
  1218. function createPageBar(url){
  1219. let insert=ruleParser.getInsert();
  1220. if(!insert || !insert.parentNode)return;
  1221. curPage++;
  1222. let inTable=insert.tagName=="TR" || insert.previousElementSibling.tagName=="TR" || insert.tagName=="TBODY" || insert.previousElementSibling.tagName=="TBODY";
  1223. let inLi=insert.tagName=="LI" || insert.previousElementSibling.tagName=="LI";
  1224. let pageBar=document.createElement(inTable?"tr":"div");
  1225. let upSpan=document.createElement("span");
  1226. let downSpan=document.createElement("span");
  1227. let pageText=document.createElement("a");
  1228. pageBar.className="pagetual_pageBar";
  1229. pageBar.id="pagetual_pageBar";
  1230. if(isPause){
  1231. pageBar.classList.add("stop");
  1232. }
  1233. pageBar.style.cssText=pageBarStyle;
  1234. pageBar.title=i18n(isPause?"enable":"disable");
  1235. upSpan.innerHTML=upSvg;
  1236. upSpan.title=i18n("toTop");
  1237. downSpan.innerHTML=downSvg;
  1238. downSpan.title=i18n("toBottom");
  1239. pageText.href=url;
  1240. pageText.style=pageTextStyle;
  1241. pageText.innerHTML="Page "+curPage;
  1242. pageText.title=i18n("current");
  1243. pageBar.appendChild(upSpan);
  1244. pageBar.appendChild(pageText);
  1245. pageBar.appendChild(downSpan);
  1246. if(inTable){
  1247. let example=(insert.tagName=="TR" || insert.tagName=="TBODY")?insert:insert.previousElementSibling;
  1248. let tdNum=example.tagName=="TR"?example.children.length:example.querySelector("tr").children.length;
  1249. pageBar.style.display="table-row";
  1250. let td=document.createElement("td");
  1251. td.colSpan=tdNum;
  1252. td.appendChild(upSpan);
  1253. td.appendChild(pageText);
  1254. td.appendChild(downSpan);
  1255. pageBar.appendChild(td);
  1256. }
  1257.  
  1258. upSpan.addEventListener("click", e=>{
  1259. changeStop(true);
  1260. document.body.scrollTop=0;
  1261. document.documentElement.scrollTop=0;
  1262. e.preventDefault();
  1263. e.stopPropagation();
  1264. });
  1265. downSpan.addEventListener("click", e=>{
  1266. changeStop(true);
  1267. document.body.scrollTop=9999999;
  1268. document.documentElement.scrollTop=9999999;
  1269. e.preventDefault();
  1270. e.stopPropagation();
  1271. });
  1272. pageBar.addEventListener("click", e=>{
  1273. changeStop(!isPause);
  1274. pageBar.title=i18n(isPause?"enable":"disable");
  1275. });
  1276. pageText.addEventListener("click", e=>{
  1277. e.stopPropagation();
  1278. });
  1279. pageBar.style.width=parseInt(_unsafeWindow.getComputedStyle(insert.parentNode).width)*.9+"px";
  1280. if(inLi){
  1281. pageBar.style.width="auto";
  1282. pageBar.style.minWidth="200px";
  1283. let line=document.createElement("li");
  1284. line.appendChild(pageBar);
  1285. insert.parentNode.insertBefore(line, insert);
  1286. }else{
  1287. insert.parentNode.insertBefore(pageBar, insert);
  1288. }
  1289. return pageBar;
  1290. }
  1291.  
  1292. var emuIframe;
  1293. function emuPage(callback){
  1294. let orgPage,curPage,iframeDoc,times=0;
  1295. function checkPage(){
  1296. if(times++ > 20){
  1297. isPause=true;
  1298. callback(false, false);
  1299. return;
  1300. }
  1301. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  1302. let eles=ruleParser.getPageElement(iframeDoc, emuIframe.contentWindow);
  1303. if(orgPage == eles[0]){
  1304. setTimeout(()=>{
  1305. checkPage(iframeDoc);
  1306. },500);
  1307. }else{
  1308. if(eles && eles.length>0){
  1309. callback(iframeDoc, eles);
  1310. }else{
  1311. isPause=true;
  1312. callback(false, false);
  1313. }
  1314. }
  1315. }
  1316. if(!emuIframe){
  1317. emuIframe = document.createElement('iframe');
  1318. emuIframe.name = 'pagetual-iframe';
  1319. emuIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1320. emuIframe.width = '100%';
  1321. emuIframe.height = '0';
  1322. emuIframe.frameBorder = '0';
  1323. emuIframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1324. emuIframe.addEventListener("load", e=>{
  1325. setTimeout(()=>{
  1326. orgPage=ruleParser.getPageElement(iframeDoc, emuIframe.contentWindow)[0];
  1327. ruleParser.getNextLink(iframeDoc).click();
  1328. checkPage(iframeDoc);
  1329. },300);
  1330. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  1331. });
  1332. emuIframe.src=location.href;
  1333. document.body.appendChild(emuIframe);
  1334. }else{
  1335. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  1336. orgPage=ruleParser.getPageElement(iframeDoc, emuIframe.contentWindow)[0];
  1337. ruleParser.getNextLink(iframeDoc).click();
  1338. checkPage(iframeDoc);
  1339. }
  1340. }
  1341.  
  1342. function forceIframe(url, callback){
  1343. let curIframe = document.createElement('iframe');
  1344. curIframe.name = 'pagetual-iframe';
  1345. curIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1346. curIframe.frameBorder = '0';
  1347. curIframe.scrolling="no";
  1348. 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;';
  1349. curIframe.addEventListener("load", e=>{
  1350. let iframeDoc=curIframe.contentDocument || curIframe.contentWindow.document;
  1351. //let eles=ruleParser.getPageElement(iframeDoc, curIframe.contentWindow);
  1352. //if(eles && eles.length>0){
  1353. ruleParser.insertPage(iframeDoc, [], url);
  1354. callback(curIframe, true);
  1355. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  1356. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  1357. setTimeout(()=>{
  1358. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  1359. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  1360. },300);
  1361. //curIframe.scrollIntoView();
  1362. /*}else{
  1363. isPause=true;
  1364. callback(false, false);
  1365. curIframe.parentNode.removeChild(curIframe);
  1366. }*/
  1367. });
  1368. curIframe.src=url;
  1369. let insert=ruleParser.getInsert();
  1370. document.body.appendChild(curIframe);
  1371. return curIframe;
  1372. }
  1373.  
  1374. function nextPage(){
  1375. if(isPause || isLoading)return;
  1376. let nextLink=ruleParser.getNextLink();
  1377. let insert=ruleParser.getInsert();
  1378. if(nextLink && insert){
  1379. debug(nextLink);
  1380. let isJs=/^(javascript|#)/.test(nextLink.href);
  1381. if(location.protocol=="https:" && /^http:/.test(nextLink.href)){
  1382. nextLink.href=nextLink.href.replace(/^http/,"https");
  1383. }
  1384. isLoading=true;
  1385. loading.style.display="";
  1386. if(ruleParser.curSiteRule.action==1 && !isJs){
  1387. requestFromIframe(nextLink.href, (doc, eles)=>{
  1388. isLoading=false;
  1389. loading.style.display="none";
  1390. if(eles){
  1391. createPageBar(nextLink.href);
  1392. ruleParser.insertPage(doc, eles, nextLink.href);
  1393. }
  1394. });
  1395. }else if(forceState==2 && !isJs){
  1396. forceIframe(nextLink.href, (iframe, eles)=>{
  1397. isLoading=false;
  1398. loading.style.display="none";
  1399. //if(eles){
  1400. let pageBar=createPageBar(nextLink.href);
  1401. iframe.parentNode.insertBefore(pageBar, iframe);
  1402. //}
  1403. });
  1404. }else{
  1405. if(!isJs){
  1406. requestDoc(nextLink.href, (eles)=>{
  1407. isLoading=false;
  1408. loading.style.display="none";
  1409. if(eles){
  1410. createPageBar(nextLink.href);
  1411. }
  1412. });
  1413. }else{
  1414. emuPage((doc, eles)=>{
  1415. isLoading=false;
  1416. loading.style.display="none";
  1417. if(eles){
  1418. createPageBar(nextLink.href);
  1419. ruleParser.insertPage(doc, eles, "");
  1420. }
  1421. });
  1422. }
  1423. }
  1424. }
  1425. }
  1426.  
  1427. function init(){
  1428. initView();
  1429. initRules(()=>{
  1430. initPage();
  1431. });
  1432. }
  1433. init();
  1434. })();

QingJ © 2025

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