东方永页机

自动翻页

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

QingJ © 2025

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