东方永页机

自动翻页

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

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