东方永页机

自动翻页

当前为 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.7
  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. let urlReg=new RegExp(rule.url, "i");
  462. if(urlReg.test(location.href)){
  463. this.curSiteRule=rule;
  464. debug(rule);
  465. callback();
  466. return rule;
  467. }
  468. }
  469. for(let i in this.customRules){
  470. let rule=this.customRules[i];
  471. if(rule.enable==0)continue;
  472. let urlReg=new RegExp(rule.url, "i");
  473. if(urlReg.test(location.href)){
  474. let pageElement,nextLink,insert;
  475. if(rule.pageElement)pageElement=rule.type==0?getElementByXpath(rule.pageElement):document.querySelector(rule.pageElement);
  476. if(rule.nextLink)nextLink=rule.type==0?getElementByXpath(rule.nextLink):document.querySelector(rule.nextLink);
  477. if(rule.insert)insert=rule.type==0?getElementByXpath(rule.insert):document.querySelector(rule.insert);
  478. if((rule.pageElement && !pageElement) ||
  479. (rule.nextLink && !nextLink) ||
  480. (rule.insert && !insert)){
  481. continue;
  482. }
  483. this.curSiteRule=rule;
  484. debug(rule);
  485. callback();
  486. return rule;
  487. }
  488. }
  489. let r=0;
  490. function searchByTime(){
  491. setTimeout(()=>{
  492. let end=r+80;
  493. end=end>self.rules.length?self.rules.length:end;
  494. for(;r<end;r++){
  495. let rule=self.rules[r];
  496. if(rule.enable==0)continue;
  497. let urlReg=new RegExp(rule.url, "i");
  498. if(urlReg.test(location.href)){
  499. let pageElement,nextLink,insert;
  500. if(rule.pageElement)pageElement=rule.type==0?getElementByXpath(rule.pageElement):document.querySelector(rule.pageElement);
  501. if(rule.nextLink)nextLink=rule.type==0?getElementByXpath(rule.nextLink):document.querySelector(rule.nextLink);
  502. if(rule.insert)insert=rule.type==0?getElementByXpath(rule.insert):document.querySelector(rule.insert);
  503. if((rule.pageElement && !pageElement) ||
  504. (rule.nextLink && !nextLink) ||
  505. (rule.insert && !insert)){
  506. continue;
  507. }
  508. self.curSiteRule=rule;
  509. debug(rule);
  510. callback();
  511. return;
  512. }
  513. }
  514. if(end>=self.rules.length){
  515. self.curSiteRule={};
  516. self.curSiteRule.url=(location.origin+location.pathname).replace(/\./g,"\\.");
  517. callback();
  518. return;
  519. }else{
  520. searchByTime();
  521. }
  522. },20);
  523. }
  524. searchByTime();
  525. }
  526.  
  527. geneSelector(ele){
  528. let selector=ele.tagName;
  529. //Google id class都是隨機。百度更過分,style script順序都是隨機的
  530. //if(ele.id) selector += '#' + ele.id;
  531. //if(ele.classList) selector += [].map.call(ele.classList,d=>'.'+d).join('');
  532. let parent = ele.parentElement;
  533. if(parent){
  534. let i,j=0;
  535. for(i=0;i<parent.children.length;i++){
  536. if(parent.children[i].tagName==selector){
  537. j++;
  538. if(parent.children[i]==ele){
  539. break;
  540. }
  541. }
  542. }
  543. selector = this.geneSelector(parent) + ' > ' + selector + (parent.tagName=="HTML"?"":`:nth-of-type(${j})`);
  544. }
  545. return selector;
  546. }
  547.  
  548. getPageElement(doc, curWin, dontFind) {
  549. let pageElement=null;
  550. let self=this;
  551. if(this.curSiteRule.pageElement){
  552. pageElement=this.curSiteRule.type==0?getAllElementsByXpath(this.curSiteRule.pageElement,doc,doc):doc.querySelectorAll(this.curSiteRule.pageElement);
  553. }
  554. if((!pageElement || pageElement.length==0) && curWin && !dontFind){
  555. let body=doc.body;
  556. if(!body)return null;
  557. let bodyHeight=parseInt(curWin.getComputedStyle(body).height);
  558. function checkElement(ele){
  559. let curHeight=parseInt(curWin.getComputedStyle(ele).height);
  560. if(curHeight/bodyHeight<=0.35)return null;
  561. if(ele.children.length==0 && !self.curSiteRule.pageElement){
  562. self.curSiteRule.pageElement=self.geneSelector(ele.parentNode)+">"+ele.tagName;
  563. self.curSiteRule.type=1;
  564. debug(self.curSiteRule.pageElement);
  565. return [ele];
  566. }
  567. let i,maxHeight=curHeight*0.35,curMaxEle=null,curMaxArea=0;
  568. for(i=0;i<ele.children.length;i++){
  569. let curNode=ele.children[i];
  570. let comStyle=curWin.getComputedStyle(curNode);
  571. let h=parseInt(comStyle.height);
  572. let w=parseInt(comStyle.width);
  573. if(isNaN(h) || isNaN(w))continue;
  574. let a=h*w+h,moreChild=curNode.children[0];
  575. while(moreChild){
  576. comStyle=curWin.getComputedStyle(moreChild);
  577. let ch=parseInt(comStyle.height);
  578. let cw=parseInt(comStyle.width);
  579. if(moreChild.innerText!="" && !isNaN(ch) && !isNaN(cw)){
  580. a+=ch*cw;
  581. }
  582. moreChild=moreChild.nextElementSibling;
  583. }
  584. if(curMaxEle==null || curMaxArea<a){
  585. curHeight=h;
  586. curMaxArea=a;
  587. curMaxEle=curNode;
  588. }
  589. }
  590. if(curMaxEle && curHeight>maxHeight){
  591. return checkElement(curMaxEle);
  592. }
  593. if(!self.curSiteRule.pageElement){
  594. self.curSiteRule.pageElement=self.geneSelector(ele)+">*";
  595. self.curSiteRule.type=1;
  596. debug(self.curSiteRule.pageElement);
  597. }
  598. return ele.children;
  599. }
  600. pageElement=checkElement(body);
  601. if(pageElement)this.saveCurSiteRule();
  602. }
  603. return pageElement;
  604. }
  605.  
  606. getPage(doc){
  607. let canSave=false;//發現頁碼選擇器在其他頁對不上,還是別保存了
  608. let url=this.curUrl;
  609. let pageNum=0,preStr="",afterStr="";
  610. let pageMatch1=url.match(/(.*[a-zA-Z0-9\/][\-_](?:p|page)?)(\d+)(\.html?$|$)/i);
  611. let pageMatch2=url.match(/(.*[\?&]p(?:age)?=)(\d+)($|[#&].*)/i);
  612. if(pageMatch1){
  613. preStr=pageMatch1[1];
  614. pageNum=pageMatch1[2];
  615. afterStr=pageMatch1[3];
  616. }else if(pageMatch2){
  617. preStr=pageMatch2[1];
  618. pageNum=pageMatch2[2];
  619. afterStr=pageMatch2[3];
  620. }
  621. var curPage=doc,i,cur;
  622. let next=curPage.querySelector("a.next"),jsNext;
  623. if(!next)next=curPage.querySelector("a#next");
  624. if(!next)next=curPage.querySelector("a#rightFix");
  625. if(!next)next=curPage.querySelector("a.next_page");
  626. if(!next)next=curPage.querySelector(".next>a");
  627. if(!next)next=curPage.querySelector("#next_page");
  628. if(!next)next=curPage.querySelector(".next>button");
  629. if(next && (!next.href || /javascript:/.test(next.href))){
  630. jsNext=next;
  631. next=null;
  632. }
  633. if(!next){
  634. let pageDiv=curPage.querySelector("div.wp-pagenavi");
  635. if(pageDiv){
  636. cur=pageDiv.querySelector("span.current");
  637. next=cur.nextSibling;
  638. }else{
  639. cur=curPage.querySelector("div.article-paging>span");
  640. if(cur){
  641. next=cur.nextElementSibling;
  642. }
  643. }
  644. }
  645. if(!next){
  646. let pageDiv=curPage.querySelector("div.pages>ul");
  647. if(pageDiv){
  648. cur=pageDiv.querySelector("li>b");
  649. if(cur)next=cur.parentNode.nextElementSibling.querySelector("a");
  650. }
  651. }
  652. if(!next){
  653. let aTags=curPage.querySelectorAll("a");
  654. let nextf,nexts,nextt,nextfo;
  655. for(i=0;i<aTags.length;i++){
  656. let aTag=aTags[i];
  657. if(nextf && nexts && nextt)break;
  658. if(!nextf){
  659. if(/(\s|^)下[一1]?[页頁张張]|^next( page)?\s*$|次のページ/i.test(aTag.innerText)){
  660. if(!aTag.href || /javascript:/.test(aTag.href)){
  661. nextfo=aTag;
  662. }else{
  663. nextf=aTag;
  664. }
  665. }
  666. }
  667. if(!nexts){
  668. if(aTag.innerText=="&gt;"){
  669. if(!aTag.href || /javascript:/.test(aTag.href)){
  670. nextfo=aTag;
  671. }else{
  672. nexts=aTag;
  673. }
  674. }
  675. }
  676. if(!aTag.href || /javascript:/.test(aTag.href))continue;
  677. if(!nextt){
  678. aTag.href=aTag.href.replace(/\?&/,"?");
  679. if(aTag.innerText=="»"){
  680. nextt=aTag;
  681. }else if(aTag.href.replace(preStr,"").replace(afterStr,"")==parseInt(pageNum)+1){
  682. nextt=aTag;
  683. }else if(aTag.href.indexOf(url)!=-1 && /^[\/\?&]?[_-]?(p|page)?=?2(\?|&|$)/i.test(aTag.href.replace(url,""))){
  684. nextt=aTag;
  685. }
  686. }
  687. }
  688. next=nextf||nexts||nextt||nextfo;
  689. }
  690. if(!next)next=jsNext||curPage.querySelector('[rel="next"]');
  691. return {next:next,canSave:canSave};
  692. }
  693.  
  694. getNextLink(doc) {
  695. let nextLink=null,page;
  696. if(this.curSiteRule.pageElementByJs){
  697. this.nextLinkHref="#";
  698. return true;
  699. }else if(this.curSiteRule.nextLinkByJs){
  700. try{
  701. let targetUrl=Function("doc",'"use strict";' + this.curSiteRule.nextLinkByJs)(doc);;
  702. nextLink={href:targetUrl};
  703. }catch(e){}
  704. }else if(this.curSiteRule.nextLinkByUrl){
  705. let targetUrl=this.curUrl.replace(new RegExp(this.curSiteRule.nextLinkByUrl[0]), this.curSiteRule.nextLinkByUrl[1]);
  706. if(targetUrl != this.curUrl){
  707. let reps=targetUrl.match(/{.*?}/g);
  708. if(reps){
  709. reps.forEach(rep=>{
  710. let code=rep.replace("{","").replace("}","");
  711. let result=code.match(/^(\d+)\+1$/);
  712. if(result){
  713. result=parseInt(result[1])+1;
  714. }else{
  715. try{
  716. result=Function('"use strict";return ' + code)();;
  717. }catch(e){}
  718. }
  719. targetUrl=targetUrl.replace(rep, result);
  720. });
  721. }
  722. }
  723. nextLink={href:targetUrl};
  724. }else if(this.curSiteRule.nextLink){
  725. nextLink=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.nextLink,doc,doc):doc.querySelector(this.curSiteRule.nextLink);
  726. }
  727. if(!nextLink){
  728. page=this.getPage(doc);
  729. nextLink=page.next;
  730. if(nextLink && doc==document){
  731. let nextLinkCs=_unsafeWindow.getComputedStyle(nextLink);
  732. if(nextLinkCs.cursor=="not-allowed"){
  733. self.nextLinkHref=false;
  734. return null;
  735. }
  736. }
  737. }
  738. if(nextLink){
  739. if(!this.curSiteRule.nextLink && page && page.canSave){
  740. this.curSiteRule.nextLink=this.geneSelector(nextLink);
  741. this.curSiteRule.type=1;
  742. this.saveCurSiteRule();
  743. }
  744. }
  745. if(nextLink){
  746. this.nextLinkHref=nextLink.href?nextLink.href:"#";
  747. debug(nextLink);
  748. }else{
  749. this.nextLinkHref=false;
  750. }
  751. return nextLink;
  752. }
  753.  
  754. getInsert(refresh) {
  755. if(this.insert && !refresh && this.insert.parentNode && this.insert.parentNode.parentNode)return this.insert;
  756. if(this.curSiteRule.insert){
  757. this.insert=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.insert,document):document.querySelector(this.curSiteRule.insert);
  758. }else{
  759. let pageElement=this.getPageElement(document, _unsafeWindow);
  760. if(pageElement && pageElement.length>0){
  761. var pELast = pageElement[pageElement.length - 1];
  762. this.insert = pELast.nextSibling ? pELast.nextSibling : pELast.parentNode.appendChild(document.createTextNode(' '));
  763. }
  764. }
  765. return this.insert;
  766. }
  767.  
  768. pageAction(doc,eles){
  769. let code=this.curSiteRule.pageAction;
  770. if(code){
  771. try{
  772. Function("doc","eles",'"use strict";' + code)(doc,eles);
  773. }catch(e){}
  774. }
  775. let css=this.curSiteRule.css;
  776. if(css){
  777. _GM_addStyle(css);
  778. }
  779. [].forEach.call(eles, ele=>{
  780. [].forEach.call(ele.querySelectorAll("img"), img=>{
  781. //if(img.src==""){
  782. let realSrc;
  783. if(img.dataset && img.dataset.original){
  784. realSrc=img.dataset.original;
  785. }else if(img.dataset && img.dataset.src){
  786. realSrc=img.dataset.src;
  787. }else if(img._lazyrias && img._lazyrias.srcset){
  788. realSrc=img._lazyrias.srcset[img._lazyrias.srcset.length-1];
  789. }else if(img.dataset && img.dataset.origFile){
  790. realSrc=img.dataset.origFile;
  791. }else if(img.srcset){
  792. var srcs=img.srcset.split(","),largeSize=0;
  793. srcs.forEach(srci=>{
  794. let srcInfo=srci.trim().split(" "),curSize=parseInt(srcInfo[1]);
  795. if(srcInfo[1] && curSize>largeSize){
  796. largeSize=curSize;
  797. realSrc=srcInfo[0];
  798. }
  799. });
  800. }
  801. if(realSrc)img.src=realSrc;
  802. //}
  803. });
  804. });
  805. let lazyImgSrc=this.curSiteRule.lazyImgSrc;
  806. if(lazyImgSrc){
  807. [].forEach.call(eles, ele=>{
  808. [].forEach.call(ele.querySelectorAll("img"), img=>{
  809. if(img[lazyImgSrc]){
  810. img.src=img[lazyImgSrc];
  811. }
  812. });
  813. });
  814. }
  815. }
  816.  
  817. initPage(callback){
  818. let self=this;
  819. this.getRule(()=>{
  820. if(self.curSiteRule){
  821. self.hpRules=self.hpRules.filter(item=>{return item&&item.url!=self.curSiteRule.url});
  822. self.hpRules.unshift(self.curSiteRule);
  823. if(self.hpRules.length>30){
  824. self.hpRules.pop();
  825. }
  826. storage.setItem("hpRules", self.hpRules);
  827. }
  828. let code=self.curSiteRule.init;
  829. if(code){
  830. try{
  831. Function('"use strict";' + code)();
  832. }catch(e){}
  833. }
  834. self.getNextLink(document);
  835. callback();
  836. });
  837. }
  838.  
  839. insertPage(doc, eles, url){
  840. this.pageDoc=doc;
  841. this.curUrl=url;
  842. this.pageAction(doc, eles);
  843. this.getNextLink(doc);
  844. this.getInsert();
  845. var self=this;
  846. if(!eles || eles.length==0 || !self.insert || !self.insert.parentNode){
  847. }else{
  848. [].forEach.call(eles, ele=>{
  849. if(self.curSiteRule.insertPos==2){
  850. self.insert.appendChild(ele.cloneNode(true));
  851. }else{
  852. self.insert.parentNode.insertBefore(ele.cloneNode(true), self.insert);
  853. }
  854. });
  855. }
  856. }
  857. }
  858. var ruleParser = new RuleParser();
  859.  
  860. var rulesData={},ruleUrls,updateDate;
  861. function initConfig(){
  862. _GM_registerMenuCommand(i18n(forceState==1?"enable":"disableSite"), ()=>{
  863. storage.setItem("forceState_"+location.host, (forceState==1?0:1));
  864. location.reload();
  865. });
  866.  
  867. _GM_registerMenuCommand(i18n(forceState==2?"cancelForceIframe":"forceIframe"), ()=>{
  868. storage.setItem("forceState_"+location.host, (forceState==2?0:2));
  869. location.reload();
  870. });
  871. var configCon,insertPos;
  872. if(location.href=="https://github.com/hoothin/UserScripts/tree/master/Pagetual"){
  873. _GM_addStyle(`
  874. p>span:nth-child(1),p>span:nth-child(2),p>span:nth-child(3){
  875. cursor: pointer;
  876. user-select: none;
  877. }
  878. p>span:nth-child(1):hover,p>span:nth-child(2):hover,p>span:nth-child(3):hover{
  879. color:red;
  880. }
  881. .updateDate{
  882. cursor: pointer;
  883. user-select: none;
  884. }
  885. .updateDate:hover{
  886. color:red;
  887. }
  888. `);
  889. configCon=document.querySelector(".markdown-body");
  890. insertPos=configCon.querySelector("hr");
  891. }else if(location.href=="https://github.com/hoothin/UserScripts/tree/master/Pagetual"){
  892. }else return;
  893. class Rulebar {
  894. init(ruleUrl){
  895. this.ruleUrl=ruleUrl;
  896. this.item=document.createElement("p");
  897. this.item.title=ruleUrl.type==0?"AutoPagerize Rules":"Pagetual Rules";
  898. this.item.dataset.id=this.ruleUrl.id;
  899. let url=document.createElement("span");
  900. url.innerHTML=ruleUrl.url;
  901. let up=document.createElement("span");
  902. up.innerHTML="↑ ";
  903. up.title=i18n("sortTitle");
  904. let down=document.createElement("span");
  905. down.innerHTML="↓ ";
  906. down.title=i18n("sortTitle");
  907. let del=document.createElement("span");
  908. del.innerHTML="× ";
  909. up.onclick=e=>{
  910. this.moveUp();
  911. };
  912. down.onclick=e=>{
  913. this.moveDown();
  914. };
  915. del.onclick=e=>{
  916. this.del();
  917. };
  918. this.item.appendChild(up);
  919. this.item.appendChild(down);
  920. this.item.appendChild(del);
  921. this.item.appendChild(url);
  922. configCon.insertBefore(this.item, insertPos);
  923. }
  924. saveSort(){
  925. let sort=[];
  926. [].forEach.call(this.item.parentNode.querySelectorAll("p[data-id]"), i=>{
  927. sort.push(i.dataset.id);
  928. });
  929. rulesData.sort=sort;
  930. storage.setItem("importRuleUrl", rulesData);
  931. }
  932. moveUp(){
  933. let preE=this.item.previousElementSibling;
  934. if(preE.tagName=="P" && preE.children.length>1){
  935. this.item.parentNode.insertBefore(this.item,preE);
  936. this.saveSort();
  937. }
  938. }
  939. moveDown(){
  940. let nextE=this.item.nextElementSibling;
  941. if(nextE.tagName=="P" && nextE.children.length>1){
  942. this.item.parentNode.insertBefore(nextE,this.item);
  943. this.saveSort();
  944. }
  945. }
  946. del(){
  947. if(this.ruleUrl.id<2){
  948. alert(i18n("cantDel"));
  949. }else if(window.confirm(i18n("confirmDel"))){
  950. for(let u=0;u<rulesData.urls.length;u++){
  951. if(this.ruleUrl.id==rulesData.urls[u].id){
  952. rulesData.urls.splice(u,1);
  953. break;
  954. }
  955. }
  956. for(let u=0;u<rulesData.sort.length;u++){
  957. if(this.ruleUrl.id==rulesData.sort[u]){
  958. rulesData.sort.splice(u,1);
  959. break;
  960. }
  961. }
  962. storage.setItem("importRuleUrl", rulesData);
  963. ruleParser.rules=ruleParser.rules.filter(item=>{return item.from!=this.ruleUrl.id});
  964. storage.setItem("rules", ruleParser.rules);
  965. this.item.parentNode.removeChild(this.item);
  966. //location.reload();
  967. }
  968. }
  969. }
  970. let updateP=document.createElement("p"),i=0;
  971. let now=new Date().getTime(),inUpdate=false;
  972.  
  973.  
  974. let pastDate=(new Date(updateDate)).toString(),passStr;
  975. let passTime=(now-updateDate)/1000;
  976. if(passTime<60){
  977. passStr=i18n("passSec", passTime);
  978. }else if(passTime<60*60){
  979. passStr=i18n("passMin", parseInt(passTime/60));
  980. }else if(passTime<60*60*24){
  981. passStr=i18n("passHour", parseInt(passTime/3600));
  982. }else{
  983. passStr=i18n("passDay", parseInt(passTime/86400));
  984. }
  985.  
  986.  
  987. updateP.className="updateDate";
  988. updateP.innerHTML=passStr;
  989. updateP.title=i18n("update")+" - "+pastDate;
  990. updateP.onclick=e=>{
  991. if(inUpdate)return;
  992. inUpdate=true;
  993. let ruleIndex=0;
  994. storage.setItem("hpRules", []);
  995. function addNextRule(){
  996. if(ruleIndex>=ruleUrls.length){
  997. storage.setItem("ruleLastUpdate", now);
  998. alert(i18n("updateSucc"));
  999. inUpdate=false;
  1000. updateP.innerHTML=i18n("passSec", 0);
  1001. updateP.title=i18n("update");
  1002. }else{
  1003. let rule=ruleUrls[ruleIndex++];
  1004. ruleParser.addRuleByUrl(rule.url, rule.type, rule.id, ()=>{
  1005. addNextRule();
  1006. })
  1007. }
  1008. }
  1009. addNextRule();
  1010. alert(i18n("beginUpdate"));
  1011. };
  1012. configCon.insertBefore(updateP, insertPos);
  1013. if(ruleUrls){
  1014. ruleUrls.forEach(ruleUrl=>{
  1015. var rulebar=new Rulebar();
  1016. rulebar.init(ruleUrl);
  1017. });
  1018. }
  1019. let customUrlsTitle=document.createElement("h2");
  1020. customUrlsTitle.innerHTML=i18n("customUrls");
  1021. configCon.insertBefore(customUrlsTitle, insertPos);
  1022. let customUrlsInput=document.createElement("textarea");
  1023. customUrlsInput.style.width="100%";
  1024. customUrlsInput.placeholder="0|http://wedata.net/databases/AutoPagerize/items_all.json";
  1025. configCon.insertBefore(customUrlsInput, insertPos);
  1026.  
  1027. let opacityTitle=document.createElement("h2");
  1028. opacityTitle.innerHTML=i18n("opacity");
  1029. let opacityInput=document.createElement("input");
  1030. opacityInput.value=rulesData.opacity*100;
  1031. opacityInput.type="number";
  1032. opacityInput.style.width="50px";
  1033. opacityInput.style.margin="0 0 0 10px";
  1034. opacityTitle.appendChild(opacityInput);
  1035. configCon.insertBefore(opacityTitle, insertPos);
  1036.  
  1037.  
  1038. let hideBarTitle=document.createElement("h2");
  1039. hideBarTitle.innerHTML=i18n("hideBar");
  1040. let hideBarInput=document.createElement("input");
  1041. hideBarInput.type="checkbox";
  1042. hideBarInput.style.width="50px";
  1043. hideBarInput.style.height="20px";
  1044. hideBarInput.checked=rulesData.hideBar;
  1045. hideBarTitle.appendChild(hideBarInput);
  1046. configCon.insertBefore(hideBarTitle, insertPos);
  1047.  
  1048. let customRulesTitle=document.createElement("h2");
  1049. customRulesTitle.innerHTML=i18n("customRules")
  1050. configCon.insertBefore(customRulesTitle, insertPos);
  1051. let customRulesInput=document.createElement("textarea");
  1052. customRulesInput.style.width="100%";
  1053. customRulesInput.style.height="500px";
  1054. 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]`;
  1055. customRulesInput.value=getFormatJSON(ruleParser.customRules);
  1056. configCon.insertBefore(customRulesInput, insertPos);
  1057. let saveBtn=document.createElement("button");
  1058. saveBtn.innerHTML=i18n("save");
  1059. saveBtn.style.width="100%";
  1060. configCon.insertBefore(saveBtn, insertPos);
  1061. saveBtn.onclick=e=>{
  1062. try{
  1063. storage.setItem("hpRules", []);
  1064. if(customRulesInput.value==""){
  1065. storage.setItem("customRules", "");
  1066. }else{
  1067. let customRules=JSON.parse(customRulesInput.value);
  1068. debug(customRules);
  1069. storage.setItem("customRules", customRules);
  1070. }
  1071. }catch(e){
  1072. debug(e);
  1073. alert("JSON error, check again!");
  1074. return;
  1075. }
  1076. rulesData.opacity=opacityInput.value/100;
  1077. rulesData.hideBar=hideBarInput.checked;
  1078. storage.setItem("importRuleUrl", rulesData);
  1079. let customUrls=customUrlsInput.value.trim();
  1080. if(customUrls){
  1081. customUrls=customUrls.split(/\n/);
  1082. for(let c=0;c<customUrls.length;c++){
  1083. let urlArr=customUrls[c].split("|"),url,type=1;
  1084. if(urlArr.length==1){
  1085. url=urlArr[0].trim();
  1086. if(!/^http/.test(url)){
  1087. alert("Wrong url, check again!");
  1088. return;
  1089. }
  1090. }else if(urlArr.length==2){
  1091. type=urlArr[0].trim();
  1092. url=urlArr[1].trim();
  1093. if(!/^http/.test(url)){
  1094. alert("Wrong url, check again!");
  1095. return;
  1096. }
  1097. }else{
  1098. break;
  1099. }
  1100. let maxId=0,hasUrl=false;;
  1101. if(!rulesData.urls){
  1102. rulesData.urls=[];
  1103. maxId=1;
  1104. }else{
  1105. rulesData.urls.forEach(u=>{
  1106. if(maxId<u.id){
  1107. maxId=u.id;
  1108. }
  1109. if(u.url==url){
  1110. hasUrl=true;
  1111. }
  1112. });
  1113. if(hasUrl)break;
  1114. }
  1115. rulesData.urls.push({id:maxId+1,url:url,type:type});
  1116. rulesData.sort.push(maxId+1);
  1117. storage.setItem("importRuleUrl", rulesData);
  1118. }
  1119. }
  1120. alert("Modified successfully");
  1121. location.reload();
  1122. };
  1123. }
  1124.  
  1125. function objIsArr(obj) {
  1126. return obj &&
  1127. typeof obj === 'object' &&
  1128. typeof obj.length === 'number' &&
  1129. !(obj.propertyIsEnumerable('length'));
  1130. }
  1131.  
  1132. function getFormatJSON(obj){
  1133. if(!objIsArr(obj))return "";
  1134. let ret="[\n";
  1135. let len=obj.length,i=0,isLast;
  1136. obj.forEach(item=>{
  1137. ret+=" {\n";
  1138. let iLen=Object.keys(item).length,j=0;
  1139. for(let key in item){
  1140. isLast=(++j)==iLen;
  1141. let value=item[key];
  1142. if(objIsArr(value)){
  1143. let vstr="[",v=0,vIsLast=false;
  1144. value.forEach(vi=>{
  1145. vIsLast=(++v)==value.length;
  1146. vstr+="\""+vi.replace(/\\/g,"\\\\")+"\""+(vIsLast?"":",");
  1147. });
  1148. vstr+="]";
  1149. ret+=" \""+key+"\":"+vstr+""+(isLast?"":",")+"\n";
  1150. }else{
  1151. if(typeof value=="string"){
  1152. value=value.replace(/\\/g,"\\\\");
  1153. }
  1154. ret+=" \""+key+"\":\""+value+"\""+(isLast?"":",")+"\n";
  1155. }
  1156. }
  1157. isLast=(++i)==len;
  1158. ret+=" }"+(isLast?"":",")+"\n";
  1159. });
  1160. ret+="]";
  1161. return ret;
  1162. }
  1163.  
  1164. function initRules(callback) {
  1165. /*0 wedata格式,1 pagetual格式*/
  1166. ruleUrls=[
  1167. {
  1168. id:0,
  1169. url:'https://raw.githubusercontent.com/hoothin/UserScripts/master/Pagetual/pagetualRules.json',
  1170. type:1
  1171. },
  1172. {
  1173. id:1,
  1174. url:'http://wedata.net/databases/AutoPagerize/items_all.json',
  1175. type:0,
  1176. }
  1177. ];var i=0,j=0;
  1178.  
  1179. ruleParser.initSavedRules(()=>{
  1180. storage.getItem("importRuleUrl", data=>{
  1181. if(data){
  1182. rulesData=data;
  1183. if(data.urls)ruleUrls=ruleUrls.concat(data.urls);
  1184. if(data.sort){
  1185. let urls=[];
  1186. data.sort.forEach(id=>{
  1187. for(let s=0;s<ruleUrls.length;s++){
  1188. if(id==ruleUrls[s].id){
  1189. urls.push(ruleUrls[s]);
  1190. break;
  1191. }
  1192. }
  1193. });
  1194. ruleUrls=urls;
  1195. }
  1196. }
  1197. if(typeof(rulesData.opacity)=="undefined"){
  1198. rulesData.opacity=0.3;
  1199. }
  1200. if(typeof(rulesData.hideBar)=="undefined"){
  1201. rulesData.hideBar=true;
  1202. }
  1203. storage.getItem("forceState_"+location.host, v=>{
  1204. storage.getItem("ruleLastUpdate", date=>{
  1205. forceState=v||0;
  1206. updateDate=date;
  1207. initConfig();
  1208. if(forceState==1)return;
  1209. let now=new Date().getTime();
  1210. if(!date || now-date>3*24*60*60*1000){
  1211. storage.setItem("ruleLastUpdate", now);
  1212. storage.setItem("hpRules", []);
  1213. let ruleIndex=0;
  1214. function addNextRule(){
  1215. if(ruleIndex>=ruleUrls.length){
  1216. callback();
  1217. }else{
  1218. let rule=ruleUrls[ruleIndex++];
  1219. ruleParser.addRuleByUrl(rule.url, rule.type, rule.id, ()=>{
  1220. addNextRule();
  1221. })
  1222. }
  1223. }
  1224. addNextRule();
  1225. }else{
  1226. callback();
  1227. }
  1228. });
  1229. });
  1230. });
  1231. });
  1232. }
  1233.  
  1234. function requestDoc(url, callback){
  1235. _GM_xmlhttpRequest({
  1236. url: url,
  1237. method: 'GET',
  1238. overrideMimeType:"text/html;charset="+document.charset,
  1239. onload: function(res) {
  1240. var doc=null;
  1241. try {
  1242. doc=document.implementation.createHTMLDocument('');
  1243. doc.documentElement.innerHTML=res.response;
  1244. }
  1245. catch (e) {
  1246. debug('parse error'+e.toString());
  1247. }
  1248. let pageElement=ruleParser.getPageElement(doc);
  1249. //只有1的話怕不是圖片哦
  1250. if(pageElement && (pageElement.length>1 || (pageElement.length==1 && pageElement[0].tagName!="IMG") )){
  1251. callback(pageElement);
  1252. ruleParser.insertPage(doc, pageElement, url);
  1253. }else{
  1254. requestFromIframe(url, (doc, eles)=>{
  1255. callback(eles);
  1256. if(eles){
  1257. ruleParser.insertPage(doc, eles, url);
  1258. }
  1259. });
  1260. }
  1261. },
  1262. onerror: function(e){
  1263. debug(e);
  1264. callback(false);
  1265. }
  1266. });
  1267. }
  1268.  
  1269. var failFromIframe=0;
  1270. function requestFromIframe(url, callback){
  1271. let orgPage,curPage;
  1272. let iframe = document.createElement('iframe');
  1273. iframe.name = 'pagetual-iframe';
  1274. iframe.width = '100%';
  1275. iframe.height = '0';
  1276. iframe.frameBorder = '0';
  1277. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1278. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1279. iframe.addEventListener("load", e=>{
  1280. setTimeout(()=>{
  1281. let tryTimes=0;
  1282. function checkIframe(){
  1283. try{
  1284. let doc=iframe.contentWindow.document;
  1285. let eles=ruleParser.getPageElement(doc, iframe.contentWindow);
  1286. if(eles && eles.length>0){
  1287. callback(doc, eles);
  1288. }else if(tryTimes++ < 2){
  1289. setTimeout(()=>{
  1290. checkIframe();
  1291. },500);
  1292. return;
  1293. }else{
  1294. if(failFromIframe++ > 2){
  1295. failFromIframe=0;
  1296. isPause=true;
  1297. callback(false, false);
  1298. }else{
  1299. callback(false, false);
  1300. }
  1301. }
  1302. }catch(e){
  1303. isPause=true;
  1304. callback(false, false);
  1305. }
  1306. document.body.removeChild(iframe);
  1307. }
  1308. checkIframe();
  1309. },300);
  1310. });
  1311. iframe.src=url;
  1312. document.body.appendChild(iframe);
  1313. }
  1314.  
  1315. function initPage(){
  1316. ruleParser.initPage(()=>{
  1317. initListener();
  1318. nextPage();
  1319. });
  1320. }
  1321.  
  1322. function initView(){
  1323. _GM_addStyle(`
  1324. .pagetual_pageBar.stop {
  1325. -webkit-filter: invert(100%);
  1326. filter: invert(100%);
  1327. opacity: 1;
  1328. }
  1329. .pagetual_pageBar.hide {
  1330. display: none!important;
  1331. }
  1332. .pagetual_pageBar {
  1333. opacity: ${rulesData.opacity};
  1334. display: ${rulesData.opacity==0?"none!important":"unset"};
  1335. }
  1336. .pagetual_pageBar:hover {
  1337. opacity: 1;
  1338. }
  1339. .pagetual_pageBar>span {
  1340. vertical-align: super;
  1341. }
  1342.  
  1343. .pagetual_pageBar>span>svg:hover {
  1344. animation: touhouAni 1s infinite;
  1345. }
  1346.  
  1347. @keyframes touhouAni{
  1348. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  1349. to {transform: rotate(360deg);}
  1350. }
  1351. @-webkit-keyframes touhouAni{
  1352. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  1353. to {transform: rotate(360deg);}
  1354. }
  1355. `);
  1356. }
  1357. var loading=document.createElement("div");
  1358. 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;";
  1359. 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>`;
  1360. document.body.appendChild(loading);
  1361.  
  1362. 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>`;
  1363. 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>`;
  1364. 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;`;
  1365. 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);`;
  1366.  
  1367. var isPause=false,isLoading=false,curPage=1,forceState=0;
  1368.  
  1369. function changeStop(stop, hide){
  1370. isPause=stop;
  1371. [].forEach.call(document.querySelectorAll(".pagetual_pageBar"), bar=>{
  1372. if(isPause){
  1373. bar.classList.add("stop");
  1374. if(hide)bar.classList.add("hide");
  1375. }else{
  1376. bar.classList.remove("stop");
  1377. if(hide)bar.classList.remove("hide");
  1378. }
  1379. });
  1380. }
  1381.  
  1382. function initListener(){
  1383. document.addEventListener('scroll', e=>{
  1384. setTimeout(()=>{
  1385. if(!isPause && !isLoading){
  1386. let scrolly=window.scrollY;
  1387. let windowHeight=window.innerHeight;
  1388. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  1389. if(scrollH-scrolly-windowHeight<1000){
  1390. nextPage();
  1391. }
  1392. }
  1393. },100);
  1394. }, false);
  1395. document.addEventListener('dblclick', e=>{
  1396. setTimeout(()=>{
  1397. changeStop(!isPause, rulesData.hideBar);
  1398. },200);
  1399. });
  1400. }
  1401.  
  1402. function createPageBar(url){
  1403. let insert=ruleParser.getInsert();
  1404. if(!insert || !insert.parentNode)return;
  1405. curPage++;
  1406. let inTable=insert.tagName=="TR" || insert.previousElementSibling.tagName=="TR" || insert.tagName=="TBODY" || insert.previousElementSibling.tagName=="TBODY";
  1407. let inLi=insert.tagName=="LI" || insert.previousElementSibling.tagName=="LI";
  1408. let pageBar=document.createElement(inTable?"tr":"div");
  1409. let upSpan=document.createElement("span");
  1410. let downSpan=document.createElement("span");
  1411. let pageText=document.createElement("a");
  1412. pageBar.className="pagetual_pageBar";
  1413. pageBar.id="pagetual_pageBar";
  1414. if(isPause){
  1415. pageBar.classList.add("stop");
  1416. }
  1417. pageBar.style.cssText=pageBarStyle;
  1418. pageBar.title=i18n(isPause?"enable":"disable");
  1419. upSpan.innerHTML=upSvg;
  1420. upSpan.title=i18n("toTop");
  1421. downSpan.innerHTML=downSvg;
  1422. downSpan.title=i18n("toBottom");
  1423. pageText.href=url;
  1424. pageText.style=pageTextStyle;
  1425. pageText.innerHTML="Page "+curPage;
  1426. pageText.title=i18n("current");
  1427. pageBar.appendChild(upSpan);
  1428. pageBar.appendChild(pageText);
  1429. pageBar.appendChild(downSpan);
  1430. if(inTable){
  1431. let example=(insert.tagName=="TR" || insert.tagName=="TBODY")?insert:insert.previousElementSibling;
  1432. let tdNum=example.tagName=="TR"?example.children.length:example.querySelector("tr").children.length;
  1433. pageBar.style.display="table-row";
  1434. let td=document.createElement("td");
  1435. td.colSpan=tdNum;
  1436. td.appendChild(upSpan);
  1437. td.appendChild(pageText);
  1438. td.appendChild(downSpan);
  1439. pageBar.appendChild(td);
  1440. }
  1441.  
  1442. upSpan.addEventListener("click", e=>{
  1443. changeStop(true);
  1444. document.body.scrollTop=0;
  1445. document.documentElement.scrollTop=0;
  1446. e.preventDefault();
  1447. e.stopPropagation();
  1448. });
  1449. downSpan.addEventListener("click", e=>{
  1450. changeStop(true);
  1451. document.body.scrollTop=9999999;
  1452. document.documentElement.scrollTop=9999999;
  1453. e.preventDefault();
  1454. e.stopPropagation();
  1455. });
  1456. pageBar.addEventListener("click", e=>{
  1457. changeStop(!isPause);
  1458. pageBar.title=i18n(isPause?"enable":"disable");
  1459. });
  1460. pageText.addEventListener("click", e=>{
  1461. e.stopPropagation();
  1462. });
  1463. pageBar.style.width=parseInt(_unsafeWindow.getComputedStyle(insert.parentNode).width)*.9+"px";
  1464. if(inLi){
  1465. pageBar.style.width="auto";
  1466. pageBar.style.minWidth="200px";
  1467. let line=document.createElement("li");
  1468. line.appendChild(pageBar);
  1469. if(ruleParser.curSiteRule.insertPos==2){
  1470. insert.appendChild(line);
  1471. }else{
  1472. insert.parentNode.insertBefore(line, insert);
  1473. }
  1474. }else{
  1475. if(ruleParser.curSiteRule.insertPos==2){
  1476. insert.appendChild(pageBar);
  1477. }else{
  1478. insert.parentNode.insertBefore(pageBar, insert);
  1479. }
  1480. }
  1481. return pageBar;
  1482. }
  1483.  
  1484. var emuIframe;
  1485. function emuPage(callback){
  1486. let orgPage,curPage,iframeDoc,times=0;
  1487. function checkPage(){
  1488. if(isPause)return;
  1489. try{
  1490. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  1491. }catch(e){
  1492. isPause=true;
  1493. callback(false, false);
  1494. return;
  1495. }
  1496. if(!orgPage){
  1497. orgPage=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true);
  1498. if(orgPage)orgPage=orgPage[0];
  1499. let nextLink=ruleParser.getNextLink(iframeDoc);
  1500. if(orgPage && nextLink){
  1501. let display=iframeDoc.defaultView.getComputedStyle(nextLink).display;
  1502. if(display=="none"){
  1503. isPause=true;
  1504. callback(false, false);
  1505. }else{
  1506. nextLink.click();
  1507. setTimeout(()=>{
  1508. checkPage();
  1509. },1000);
  1510. }
  1511. }else{
  1512. isPause=true;
  1513. callback(false, false);
  1514. }
  1515. return;
  1516. }
  1517. if(times++ > 10){
  1518. isPause=true;
  1519. callback(false, false);
  1520. return;
  1521. }
  1522. let eles=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true);
  1523. if(!eles || eles.length==0){
  1524. isPause=true;
  1525. callback(false, false);
  1526. }else if(orgPage == eles[0]){
  1527. setTimeout(()=>{
  1528. checkPage();
  1529. },500);
  1530. }else{
  1531. callback(iframeDoc, eles);
  1532. }
  1533. }
  1534. if(!emuIframe){
  1535. emuIframe = document.createElement('iframe');
  1536. emuIframe.name = 'pagetual-iframe';
  1537. emuIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1538. emuIframe.width = '100%';
  1539. emuIframe.height = '0';
  1540. emuIframe.frameBorder = '0';
  1541. emuIframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1542. emuIframe.addEventListener("load", e=>{
  1543. setTimeout(()=>{
  1544. checkPage();
  1545. },300);
  1546. });
  1547. emuIframe.src=location.href;
  1548. document.body.appendChild(emuIframe);
  1549. }else{
  1550. checkPage();
  1551. }
  1552. }
  1553.  
  1554. function forceIframe(url, callback){
  1555. let curIframe = document.createElement('iframe');
  1556. curIframe.name = 'pagetual-iframe';
  1557. curIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1558. curIframe.frameBorder = '0';
  1559. curIframe.scrolling="no";
  1560. 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;';
  1561. curIframe.addEventListener("load", e=>{
  1562. let iframeDoc=curIframe.contentDocument || curIframe.contentWindow.document;
  1563. //let eles=ruleParser.getPageElement(iframeDoc, curIframe.contentWindow);
  1564. //if(eles && eles.length>0){
  1565. ruleParser.insertPage(iframeDoc, [], url);
  1566. callback(curIframe, true);
  1567. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  1568. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  1569. setTimeout(()=>{
  1570. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  1571. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  1572. },300);
  1573. //curIframe.scrollIntoView();
  1574. /*}else{
  1575. isPause=true;
  1576. callback(false, false);
  1577. curIframe.parentNode.removeChild(curIframe);
  1578. }*/
  1579. });
  1580. curIframe.src=url;
  1581. let insert=ruleParser.getInsert();
  1582. document.body.appendChild(curIframe);
  1583. return curIframe;
  1584. }
  1585.  
  1586. function nextPage(){
  1587. if(isPause || isLoading)return;
  1588. let nextLink=ruleParser.nextLinkHref;
  1589. let insert=ruleParser.getInsert();
  1590. if(nextLink && insert){
  1591. let isJs=/^(javascript|#)/.test(nextLink.replace(location.href,""));
  1592. if(location.protocol=="https:" && /^http:/.test(nextLink)){
  1593. nextLink=nextLink.replace(/^http/,"https");
  1594. }
  1595. isLoading=true;
  1596. loading.style.display="";
  1597. if(ruleParser.curSiteRule.pageElementByJs){
  1598. var over=ele=>{
  1599. isLoading=false;
  1600. loading.style.display="none";
  1601. if(ele){
  1602. createPageBar(nextLink);
  1603. ruleParser.insertPage(null, ele, null);
  1604. }else{
  1605. isPause=true;
  1606. }
  1607. };
  1608. try{
  1609. Function("over",'"use strict";' + ruleParser.curSiteRule.pageElementByJs)(over);
  1610. }catch(e){}
  1611. }else if(ruleParser.curSiteRule.action==1 && !isJs){
  1612. requestFromIframe(nextLink, (doc, eles)=>{
  1613. isLoading=false;
  1614. loading.style.display="none";
  1615. if(eles){
  1616. createPageBar(nextLink);
  1617. ruleParser.insertPage(doc, eles, nextLink);
  1618. }
  1619. });
  1620. }else if(forceState==2 && !isJs){
  1621. forceIframe(nextLink, (iframe, eles)=>{
  1622. isLoading=false;
  1623. loading.style.display="none";
  1624. //if(eles){
  1625. let pageBar=createPageBar(nextLink);
  1626. iframe.parentNode.insertBefore(pageBar, iframe);
  1627. //}
  1628. });
  1629. }else{
  1630. if(!isJs){
  1631. requestDoc(nextLink, (eles)=>{
  1632. isLoading=false;
  1633. loading.style.display="none";
  1634. if(eles){
  1635. createPageBar(nextLink);
  1636. }
  1637. });
  1638. }else{
  1639. emuPage((doc, eles)=>{
  1640. isLoading=false;
  1641. loading.style.display="none";
  1642. if(eles){
  1643. createPageBar(nextLink);
  1644. ruleParser.insertPage(doc, eles, "");
  1645. }
  1646. });
  1647. }
  1648. }
  1649. }
  1650. }
  1651.  
  1652. function init(){
  1653. initRules(()=>{
  1654. initView();
  1655. initPage();
  1656. });
  1657. }
  1658. init();
  1659. })();