东方永页机

自动翻页

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