东方永页机

自动翻页

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

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

QingJ © 2025

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