东方永页机

自动翻页

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

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

QingJ © 2025

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