东方永页机

自动翻页

当前为 2022-02-15 提交的版本,查看 最新版本

  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 1.1.2
  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_deleteValue
  37. // @grant GM.xmlHttpRequest
  38. // @grant GM.registerMenuCommand
  39. // @grant GM.notification
  40. // @grant GM.getValue
  41. // @grant GM.setValue
  42. // @grant GM.addStyle
  43. // @grant GM.openInTab
  44. // @grant GM.deleteValue
  45. // @supportURL https://github.com/hoothin/UserScripts/issues
  46. // @connect wedata.net
  47. // @connect githubusercontent.com
  48. // @run-at document-idle
  49. // @exclude http://www.toodledo.com/tasks/*
  50. // @exclude http*://maps.google.com*/*
  51. // @exclude *://www.google.*/_/chrome/newtab*
  52. // @exclude *://mega.*/*
  53. // @exclude *://*.mega.*/*
  54. // @exclude *://*.youku.com/v_*
  55. // @exclude *://*pan.baidu.com
  56. // @exclude *://*.iqiyi.com/v_*
  57. // @exclude *://*.iqiyi.com/w_*
  58. // @exclude *://*.iqiyi.com/a_*
  59. // @exclude *://*.le.com/ptv/vplay/*
  60. // @exclude *://v.qq.com/x/cover/*
  61. // @exclude *://v.qq.com/x/page/*
  62. // @exclude *://v.qq.com/tv/*
  63. // @exclude *://*.tudou.com/listplay/*
  64. // @exclude *://*.tudou.com/albumplay/*
  65. // @exclude *://*.tudou.com/programs/view/*
  66. // @exclude *://*.mgtv.com/b/*
  67. // @exclude *://film.sohu.com/album/*
  68. // @exclude *://tv.sohu.com/v/*
  69. // @exclude *://*.bilibili.com/video/*
  70. // @exclude *://*.bilibili.com/bangumi/play/*
  71. // @exclude *://*.baofeng.com/play/*
  72. // @exclude *://vip.pptv.com/show/*
  73. // @exclude *://v.pptv.com/show/*
  74. // @exclude *://www.le.com/ptv/vplay/*
  75. // @exclude *://www.wasu.cn/Play/show/*
  76. // @exclude *://m.v.qq.com/*
  77. // @exclude *://m.iqiyi.com/*
  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. // @exclude *://baike.baidu.com/*
  93. // @exclude *://*.instagram.com/*
  94. // @exclude *://pagetual.hoothin.com/*
  95. // @exclude *://hoothin.github.io/PagetualGuide/*
  96. // @connect *
  97. // ==/UserScript==
  98.  
  99. (function() {
  100. 'use strict';
  101.  
  102. if (window.name === 'pagetual-iframe') {
  103. var domloaded = function (){
  104. window.scroll(window.scrollX, 999999);
  105. //window.parent.postMessage('pagetual-iframe:DOMLoaded', '*');
  106. };
  107. if(window.opera){
  108. document.addEventListener('DOMContentLoaded', domloaded, false);
  109. } else {
  110. domloaded();
  111. }
  112. return;
  113. }
  114.  
  115. if(window.top != window.self){
  116. return;
  117. }
  118.  
  119. const lang = navigator.appName=="Netscape"?navigator.language:navigator.userLanguage;
  120. var i18n=(name, param)=>{
  121. let config={};
  122. switch (lang){
  123. case "zh-CN":
  124. case "zh-SG":
  125. config={
  126. disable:"暂时禁用",
  127. disableSite:"在此站禁用",
  128. enable:"启用翻页",
  129. toTop:"回到顶部",
  130. toBottom:"前往页尾",
  131. current:"当前页",
  132. forceIframe:"强制拼接",
  133. cancelForceIframe:"取消强制拼接",
  134. configure:"打开配置页",
  135. update:"立即更新规则",
  136. passSec:"更新于 #t# 秒前",
  137. passMin:"更新于 #t# 分钟前",
  138. passHour:"更新于 #t# 小时前",
  139. passDay:"更新于 #t# 天前",
  140. cantDel:"无法删除内置规则",
  141. confirmDel:"是否确认要删除此规则?",
  142. updateSucc:"更新成功",
  143. beginUpdate:"正在更新,请稍候",
  144. customUrls:"导入规则url,一行一条,AutoPagerize 格式规则需要以\"0|\"开头",
  145. customRules:"输入【东方永页机】格式的自定义规则",
  146. save:"保存设置",
  147. loadingText:"少女祈祷中...",
  148. opacity:"分页隔条不透明值",
  149. hideBar:"空白处双击隐藏分页隔条",
  150. dbClick2Stop:"空白处双击暂停翻页",
  151. sortTitle:"排序在下次更新规则后生效",
  152. autoRun:"自动启用"
  153. };
  154. break;
  155. case "zh-TW":
  156. case "zh-HK":
  157. config={
  158. disable:"暫時禁用",
  159. disableSite:"在此站禁用",
  160. enable:"啟用翻頁",
  161. toTop:"回到頂部",
  162. toBottom:"前往頁尾",
  163. current:"當前頁",
  164. forceIframe:"強制拼接",
  165. cancelForceIframe:"取消强制拼接",
  166. configure:"打開配置頁",
  167. update:"立即更新規則",
  168. passSec:"更新于 #t# 秒前",
  169. passMin:"更新于 #t# 分鐘前",
  170. passHour:"更新于 #t# 小時前",
  171. passDay:"更新于 #t# 天前",
  172. cantDel:"無法刪除内置規則",
  173. confirmDel:"是否確認要刪除此規則?",
  174. updateSucc:"更新成功",
  175. beginUpdate:"正在更新,請稍候",
  176. customUrls:"導入規則url,一行一條,AutoPagerize 格式規則需要以\"0|\"開頭",
  177. customRules:"輸入【東方永頁機】格式的自定義規則",
  178. save:"存儲設置",
  179. loadingText:"少女祈禱中...",
  180. opacity:"分頁隔條不透明值",
  181. hideBar:"空白處雙擊隱藏分頁隔條",
  182. dbClick2Stop:"空白處雙擊暫停翻頁",
  183. sortTitle:"排序在下次更新規則後生效",
  184. autoRun:"自動啓用"
  185. };
  186. break;
  187. case "ja":
  188. config = {
  189. disable: "一時的に無効にする",
  190. disableSite:"このサイト無効",
  191. enable: "ページめくりを有効にする",
  192. toTop: "トップに戻る",
  193. toBottom: "ページの下部に移動",
  194. current: "現在のページ",
  195. forceIframe: "強制ステッチ",
  196. cancelForceIframe: "強制ステッチをキャンセル",
  197. configure: "設定ページを開く",
  198. update: "今すぐルールを更新してください",
  199. passSec: "#t#秒前に更新",
  200. passMin: "#t#分前に更新",
  201. passHour: "#t#時間前に更新",
  202. passDay: "#t#日前に更新",
  203. cantDel: "組み込みルールを削除できません",
  204. confirmDel: "このルールを削除してもよろしいですか?",
  205. updateSucc: "更新に成功しました",
  206. beginUpdate: "更新中、お待ちください",
  207. customUrls: "インポートルールのURL、1行に1つ、AutoPagerizeフォーマットルールは\"0|\"で始まる必要があります",
  208. customRules: "【東方永頁機】の形式でカスタムルールを入力してください",
  209. save: "設定を保存",
  210. loadingText: "少女祈祷中...",
  211. opacity:"ページネーションバーの不透明値",
  212. hideBar:"空白部分をダブルクリックして、ページ区切り文字を非表示にします",
  213. dbClick2Stop:"空白部分をダブルクリックしてページめくりを一時停止します",
  214. sortTitle:"並べ替えは、次のルールの更新後に有効になります",
  215. autoRun:"自動的に有効"
  216. };
  217. break;
  218. default:
  219. config={
  220. disable:"Disable",
  221. disableSite:"Disable on the site",
  222. enable:"Enable",
  223. toTop:"To Top",
  224. toBottom:"To Bottom",
  225. current:"Current Page",
  226. forceIframe:"Force to join",
  227. cancelForceIframe:"Cancel Force join",
  228. configure:"Configure",
  229. update:"Update rules from url now",
  230. passSec:"Updated #t# seconds ago",
  231. passMin:"Updated #t# minutes ago",
  232. passHour:"Updated #t# hours ago",
  233. passDay:"Updated #t# days ago",
  234. cantDel:"Can't delete buildin rules",
  235. confirmDel:"Are you sure you want to delete this rule?",
  236. updateSucc:"Update succeeded",
  237. beginUpdate:"Begin update, wait a minute please",
  238. customUrls:"Import rule url, One url per line, rules on AutoPagerize format need to start with \"0|\"",
  239. customRules:"Input custom rules with [Pagetual] format",
  240. save:"Save",
  241. loadingText:"Shojo Now Loading...",
  242. opacity:"Pagination spacer opacity",
  243. hideBar:"Double-click on the blank space to hide the paging spacer",
  244. dbClick2Stop:"Double-click on the blank space to stop",
  245. sortTitle:"Sorting takes effect after the next rule update",
  246. autoRun:"Auto run"
  247. };
  248. break;
  249. }
  250. return config[name]?config[name].replace("#t#",param):name;
  251. };
  252.  
  253. var enableDebug=true;
  254. var debug=str=>{
  255. if(enableDebug){
  256. console.debug(str);
  257. }
  258. };
  259.  
  260. var _GM_xmlhttpRequest,_GM_registerMenuCommand,_GM_notification,_GM_addStyle,_GM_openInTab;
  261. if(typeof GM_xmlhttpRequest!='undefined'){
  262. _GM_xmlhttpRequest=GM_xmlhttpRequest;
  263. }else if(typeof GM!='undefined' && typeof GM.xmlHttpRequest!='undefined'){
  264. _GM_xmlhttpRequest=GM.xmlHttpRequest;
  265. }
  266. if(typeof GM_registerMenuCommand!='undefined'){
  267. _GM_registerMenuCommand=GM_registerMenuCommand;
  268. }else if(typeof GM!='undefined' && typeof GM.registerMenuCommand!='undefined'){
  269. _GM_registerMenuCommand=GM.registerMenuCommand;
  270. }
  271. if(typeof GM_notification!='undefined'){
  272. _GM_notification=GM_notification;
  273. }else if(typeof GM!='undefined' && typeof GM.notification!='undefined'){
  274. _GM_notification=GM.notification;
  275. }
  276. if(typeof GM_openInTab!='undefined'){
  277. _GM_openInTab=GM_openInTab;
  278. }else if(typeof GM!='undefined' && typeof GM.openInTab!='undefined'){
  279. _GM_openInTab=GM.openInTab;
  280. }
  281. if(typeof GM_addStyle!='undefined'){
  282. _GM_addStyle=GM_addStyle;
  283. }else if(typeof GM!='undefined' && typeof GM.addStyle!='undefined'){
  284. _GM_addStyle=GM.addStyle;
  285. }else{
  286. _GM_addStyle=cssStr=>{
  287. let styleEle=document.createElement("style");
  288. styleEle.innerHTML=cssStr;
  289. document.head.appendChild(styleEle);
  290. };
  291. }
  292.  
  293. if(typeof _GM_xmlhttpRequest=='undefined')_GM_xmlhttpRequest=(f)=>{};
  294. if(typeof _GM_registerMenuCommand=='undefined')_GM_registerMenuCommand=(s,f)=>{};
  295. if(typeof _GM_notification=='undefined')_GM_notification=(s)=>{};
  296. if(typeof _GM_openInTab=='undefined')_GM_openInTab=(s)=>{window.open(s)};
  297. var _unsafeWindow=(typeof unsafeWindow=='undefined')?window:unsafeWindow;
  298. var storage={
  299. supportGM: typeof GM_getValue=='function' && typeof GM_getValue('a','b')!='undefined',
  300. supportGMPromise: typeof GM!='undefined' && typeof GM.getValue=='function' && typeof GM.getValue('a','b')!='undefined',
  301. mxAppStorage:(function(){
  302. try{
  303. return window.external.mxGetRuntime().storage;
  304. }catch(e){
  305. }
  306. })(),
  307. operaUJSStorage:(function(){
  308. try{
  309. return window.opera.scriptStorage;
  310. }catch(e){
  311. }
  312. })(),
  313. setItem:function(key,value){
  314. if(this.operaUJSStorage){
  315. this.operaUJSStorage.setItem(key,value);
  316. }else if(this.mxAppStorage){
  317. this.mxAppStorage.setConfig(key,value);
  318. }else if(this.supportGM){
  319. GM_setValue(key,value);
  320. if(value==="" && typeof GM_deleteValue!='undefined'){
  321. GM_deleteValue(key);
  322. }
  323. }else if(this.supportGMPromise){
  324. GM.setValue(key,value);
  325. if(value==="" && typeof GM!='undefined' && typeof GM.deleteValue!='undefined'){
  326. GM.deleteValue(key);
  327. }
  328. }else if(window.localStorage){
  329. window.localStorage.setItem(key,value);
  330. }
  331. },
  332. getItem:function(key,cb){
  333. var value;
  334. if(this.operaUJSStorage){
  335. value=this.operaUJSStorage.getItem(key);
  336. }else if(this.mxAppStorage){
  337. value=this.mxAppStorage.getConfig(key);
  338. }else if(this.supportGM){
  339. value=GM_getValue(key);
  340. }else if(this.supportGMPromise){
  341. value=GM.getValue(key).then(v=>{cb(v)});
  342. return;
  343. }else if(window.localStorage){
  344. value=window.localStorage.getItem(key);
  345. };
  346. cb(value);
  347. }
  348. };
  349. var rulesData={},ruleUrls,updateDate,configPage="https://github.com/hoothin/UserScripts/tree/master/Pagetual";
  350. _GM_registerMenuCommand(i18n("configure"), ()=>{
  351. _GM_openInTab(configPage,{active:true});
  352. });
  353.  
  354. function getElementByXpath(xpath, contextNode, doc){
  355. doc = doc || document;
  356. contextNode = contextNode || doc;
  357. try {
  358. var result = doc.evaluate(xpath, contextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
  359. return result.singleNodeValue && result.singleNodeValue.nodeType === 1 && result.singleNodeValue;
  360. } catch (err) {
  361. throw new Error(`Invalid xpath: ${xpath}`);
  362. }
  363. }
  364.  
  365. function getAllElementsByXpath(xpath, contextNode, doc){
  366. doc = doc || document;
  367. contextNode = contextNode || doc;
  368. var result = [];
  369. try {
  370. var query = doc.evaluate(xpath, contextNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  371. for (var i = 0; i < query.snapshotLength; i++) {
  372. var node = query.snapshotItem(i);
  373. if (node.nodeType === 1) result.push(node);
  374. }
  375. } catch (err) {
  376. throw new Error(`Invalid xpath: ${xpath}`);
  377. }
  378. return result;
  379. }
  380.  
  381. class RuleParser {
  382. constructor() {
  383. this.hpRules=[];
  384. this.customRules=[];
  385. this.rules=[];
  386. this.pageDoc=document;
  387. this.nextLinkHref=null;
  388. this.curUrl=location.href;
  389. this.curSiteRule={};
  390. }
  391.  
  392. initSavedRules(callback){
  393. var self=this;
  394. storage.getItem("hpRules", hpRules=>{
  395. if(hpRules)self.hpRules=hpRules;
  396. storage.getItem("customRules", customRules=>{
  397. if(customRules)self.customRules=customRules;
  398. storage.getItem("rules", rules=>{
  399. if(rules)this.rules=rules;
  400. callback();
  401. });
  402. });
  403. });
  404. }
  405.  
  406. saveCurSiteRule(){
  407. if(!this.curSiteRule || !this.curSiteRule.url || this.curSiteRule.singleUrl)return;
  408. this.hpRules=this.hpRules.filter(item=>{return item&&item.url!=this.curSiteRule.url});
  409. this.hpRules.unshift(this.curSiteRule);
  410. if(this.hpRules.length>30){
  411. this.hpRules.pop();
  412. }
  413. storage.setItem("hpRules", this.hpRules);
  414. }
  415.  
  416. requestJSON(url, callback){
  417. _GM_xmlhttpRequest({
  418. url: url,
  419. method: 'GET',
  420. timeout: 10000,
  421. onload: function(res) {
  422. let json=null;
  423. try{
  424. json=JSON.parse(res.response);
  425. }catch(e){
  426. debug(e);
  427. }
  428. callback(json);
  429. },
  430. onerror: function() {
  431. callback(null);
  432. }
  433. });
  434. }
  435.  
  436. formatRule(item, type, from){
  437. switch(type){
  438. case 0:
  439. return {
  440. from:from,
  441. type:type,
  442. name:item.name,
  443. action:item.data.forceIframe=="true"?1:0,
  444. url:item.data.url,
  445. pageElement:item.data.pageElement,
  446. nextLink:item.data.nextLink,
  447. insert:item.data.insertBefore,
  448. insertPos:1,
  449. updatedAt:item.data.updated_at,
  450. css:item.data.Stylus+item.data.CSS,
  451. pageAction:item.data.bookmarklet
  452. };
  453. break;
  454. case 1:
  455. default:
  456. item.from=from;
  457. if(typeof(item.type) == "undefined")item.type=type;
  458. return item;
  459. break;
  460. }
  461. return null;
  462. }
  463.  
  464. addRuleByUrl(url, type, from, callback) {
  465. this.requestJSON(url, json=>{
  466. this.addRules(json, type, from);
  467. storage.setItem("rules", this.rules);
  468. callback();
  469. });
  470. }
  471.  
  472. addRules(rules, type, from) {
  473. if(rules && rules.length>0){
  474. this.rules=this.rules.filter(item=>{return item.from!=from});
  475. rules.forEach(item=>{
  476. let rule=this.formatRule(item, type, from);
  477. if(rule){
  478. this.rules.push(rule);
  479. }
  480. });
  481. }
  482. }
  483.  
  484. getRule(callback) {
  485. if(this.curSiteRule && this.curSiteRule.url){
  486. return this.curSiteRule;
  487. }
  488. var self=this;
  489.  
  490. function setRule(r){
  491. self.curSiteRule=r;
  492. debug(r);
  493. callback();
  494. }
  495.  
  496. function ruleMatch(r){
  497. let pageElement,nextLink,insert;
  498. if(r.pageElement)pageElement=r.type==0?getElementByXpath(r.pageElement):document.querySelector(r.pageElement);
  499. if(r.nextLink)nextLink=r.type==0?getElementByXpath(r.nextLink):document.querySelector(r.nextLink);
  500. if(r.insert)insert=r.type==0?getElementByXpath(r.insert):document.querySelector(r.insert);
  501. return !((r.pageElement && !pageElement) ||
  502. (r.nextLink && !nextLink) ||
  503. (r.insert && !insert));
  504. }
  505.  
  506. function checkRule(r){
  507. let urlReg=new RegExp(r.url, "i");
  508. if(urlReg.test(location.href)){
  509. if(r.wait){
  510. let waitTime=500,checkEval;
  511. if(isNaN(r.wait)){
  512. try{
  513. checkEval=Function("doc",'"use strict";' + r.wait);
  514. }catch(e){
  515. debug(e);
  516. }
  517. }else{
  518. waitTime=r.wait;
  519. }
  520. let waitTimes=10;
  521. let checkReady=()=>{
  522. if(waitTimes--<=0)return true;
  523. setTimeout(()=>{
  524. if(!ruleMatch(r) || (checkEval && !checkEval(document))){
  525. checkReady();
  526. }else{
  527. setRule(r);
  528. }
  529. },parseInt(waitTime));
  530. };
  531. checkReady();
  532. return true;
  533. }
  534. if(r.pinUrl){
  535. setRule(r);
  536. return true;
  537. }
  538. if(!ruleMatch(r)){
  539. return false;
  540. }
  541. setRule(r);
  542. return true;
  543. }
  544. return false;
  545. }
  546.  
  547. for(let i in this.hpRules){
  548. let rule=this.hpRules[i];
  549. if(!rule || !rule.url)continue;
  550. if(rule.singleUrl){
  551. if(location.origin+location.pathname==rule.url){
  552. setRule(rule);
  553. return;
  554. }
  555. continue;
  556. }
  557. if(checkRule(rule))return;
  558. }
  559. for(let i in this.customRules){
  560. let rule=this.customRules[i];
  561. if(!rule || !rule.url)continue;
  562. if(checkRule(rule))return;
  563. }
  564. let r=0;
  565. function searchByTime(){
  566. setTimeout(()=>{
  567. let end=r+80;
  568. end=end>self.rules.length?self.rules.length:end;
  569. for(;r<end;r++){
  570. let rule=self.rules[r];
  571. if(checkRule(rule))return;
  572. }
  573. if(end>=self.rules.length){
  574. self.curSiteRule={};
  575. self.curSiteRule.url=location.origin+location.pathname;
  576. self.curSiteRule.singleUrl=true;
  577. callback();
  578. return;
  579. }else{
  580. searchByTime();
  581. }
  582. },20);
  583. }
  584. searchByTime();
  585. }
  586.  
  587. geneSelector(ele){
  588. let selector=ele.tagName;
  589. //Google id class都是隨機。百度更過分,style script順序都是隨機的
  590. //if(ele.id) selector += '#' + ele.id;
  591. //if(ele.classList) selector += [].map.call(ele.classList,d=>'.'+d).join('');
  592. let parent = ele.parentElement;
  593. if(parent){
  594. let i,j=0;
  595. for(i=0;i<parent.children.length;i++){
  596. if(parent.children[i].tagName==selector){
  597. j++;
  598. if(parent.children[i]==ele){
  599. break;
  600. }
  601. }
  602. }
  603. selector = this.geneSelector(parent) + ' > ' + selector + (parent.tagName=="HTML"?"":`:nth-of-type(${j})`);
  604. }
  605. return selector;
  606. }
  607.  
  608. getPageElement(doc, curWin, dontFind) {
  609. let pageElement=null;
  610. let self=this;
  611. if(this.curSiteRule.pageElement){
  612. pageElement=this.curSiteRule.type==0?getAllElementsByXpath(this.curSiteRule.pageElement,doc,doc):doc.querySelectorAll(this.curSiteRule.pageElement);
  613. }
  614. if((!pageElement || pageElement.length==0) && curWin && !dontFind){
  615. let body=doc.body;
  616. if(!body)return null;
  617. let bodyHeight=parseInt(body.scrollHeight);
  618. let curHeight=bodyHeight;
  619. function checkElement(ele){
  620. if(curHeight/bodyHeight<=0.30)return null;
  621. if(ele.children.length==0 && !self.curSiteRule.pageElement){
  622. if(ele.parentNode.tagName=="P")ele=ele.parentNode;
  623. self.curSiteRule.pageElement=self.geneSelector(ele.parentNode)+">"+ele.tagName;
  624. self.curSiteRule.type=1;
  625. debug(self.curSiteRule.pageElement);
  626. return [ele];
  627. }
  628. let i,maxHeight=curHeight*0.6,curMaxEle=null,curMaxArea=0,maxWidth=0;
  629. let isHori=true;
  630. let offsetTop=ele.children[0].offsetTop;
  631. for(i=0;i<ele.children.length;i++){
  632. if(ele.children[i].offsetTop!=offsetTop){
  633. isHori=false;
  634. break;
  635. }
  636. }
  637. for(i=0;i<ele.children.length;i++){
  638. let curNode=ele.children[i];
  639. let comStyle=curWin.getComputedStyle(curNode);
  640. let h=parseInt(curNode.scrollHeight);
  641. let w=parseInt(curNode.scrollWidth);
  642. if(isNaN(h) || isNaN(w))continue;
  643. if(isHori && h==0)continue;
  644. let a=h*w+h,moreChild=curNode.children[0];
  645. while(moreChild){
  646. comStyle=curWin.getComputedStyle(moreChild);
  647. let ch=parseInt(moreChild.scrollHeight);
  648. let cw=parseInt(moreChild.scrollWidth);
  649. if(h<ch)h=ch;
  650. if(moreChild.innerText!="" && !isNaN(ch) && !isNaN(cw)){
  651. a+=ch*cw;
  652. }
  653. moreChild=moreChild.nextElementSibling;
  654. }
  655. let isMax=false;
  656. if(isHori){
  657. if(maxWidth<w){
  658. isMax=true;
  659. }
  660. if(maxWidth==w && curMaxArea<a){
  661. isMax=true;
  662. }
  663. }else{
  664. isMax=curMaxArea<a;
  665. }
  666. if(curMaxEle==null || isMax){
  667. if(h>0)curHeight=h;
  668. curMaxArea=a;
  669. maxWidth=w;
  670. curMaxEle=curNode;
  671. }
  672. }
  673. if(curMaxEle && (isHori || curHeight>maxHeight)){
  674. return checkElement(curMaxEle);
  675. }
  676. if(!self.curSiteRule.pageElement){
  677. if(ele.tagName=="P")ele=ele.parentNode;
  678. self.curSiteRule.pageElement=self.geneSelector(ele);
  679. if(ele.children.length>1 && ele.tagName!="UL")self.curSiteRule.pageElement+=">*";
  680. self.curSiteRule.type=1;
  681. debug(self.curSiteRule.pageElement);
  682. }
  683. return (ele.tagName=="UL"||ele.children.length==1)?[ele]:ele.children;
  684. }
  685. pageElement=checkElement(body);
  686. if(pageElement)this.saveCurSiteRule();
  687. }
  688. return pageElement;
  689. }
  690.  
  691. getPage(doc){
  692. if(_unsafeWindow.Discourse)return {};
  693. let canSave=false;//發現頁碼選擇器在其他頁對不上,還是別保存了
  694. let url=this.curUrl.replace("#!","");
  695. let pageNum=1,preStr="",afterStr="";
  696. let pageMatch1=url.match(/(.*[a-z\/\-_](?:p|page)?\/?)(\d+)(\.s?html?$|\/?$)/i);
  697. let pageMatch2=url.match(/(.*[\?&]p(?:age)?=)(\d+)($|[#&].*)/i);
  698. if(pageMatch1){
  699. preStr=pageMatch1[1];
  700. pageNum=pageMatch1[2];
  701. afterStr=pageMatch1[3];
  702. }else if(pageMatch2){
  703. preStr=pageMatch2[1];
  704. pageNum=pageMatch2[2];
  705. afterStr=pageMatch2[3];
  706. }
  707. let curPage=doc,i,cur,jsNext;
  708. let next=curPage.querySelector("a.next");
  709. if(!next)next=curPage.querySelector("a#next");
  710. if(!next)next=curPage.querySelector("a#rightFix");
  711. if(!next)next=curPage.querySelector("a.next_page");
  712. if(!next)next=curPage.querySelector(".next>a");
  713. if(!next)next=curPage.querySelector("#next_page");
  714. if(!next)next=curPage.querySelector(".next>button");
  715. if(!next)next=curPage.querySelector("a[alt=next]");
  716. if(!next)next=curPage.querySelector("[title=next]");
  717. if(!next){
  718. next=curPage.querySelectorAll("[aria-label='Next']");
  719. if(next && next.length==1){
  720. next=next[0];
  721. }else{
  722. next=null;
  723. }
  724. }
  725. if(!next){
  726. next=curPage.querySelectorAll("[aria-label='Next page']");
  727. if(next && next.length==1){
  728. next=next[0];
  729. }else{
  730. next=null;
  731. }
  732. }
  733. if(!next)next=curPage.querySelector(".nextPage");
  734. if(next && (!next.href || /^javascript:/.test(next.href))){
  735. jsNext=next;
  736. next=null;
  737. }
  738. if(!next){
  739. let pageDiv=curPage.querySelector("div.wp-pagenavi");
  740. if(pageDiv){
  741. cur=pageDiv.querySelector("span.current");
  742. next=cur.nextSibling;
  743. }else{
  744. cur=curPage.querySelector("div.article-paging>span");
  745. if(cur){
  746. next=cur.nextElementSibling;
  747. }
  748. }
  749. }
  750. if(!next){
  751. let pageDiv=curPage.querySelector("div.pages>ul");
  752. if(pageDiv){
  753. cur=pageDiv.querySelector("li>b");
  754. if(cur)next=cur.parentNode.nextElementSibling.querySelector("a");
  755. }
  756. }
  757. if(!next){
  758. let aTags=curPage.querySelectorAll("a");
  759. let next1,next2,next3,next4,nextJs1,nextJs2,nextJs3;
  760. for(i=aTags.length-1;i>=0;i--){
  761. let aTag=aTags[i];
  762. if(aTag.style.display=="none")continue;
  763. if(next1 && next2 && next3 && next4)break;
  764. if(!next1){
  765. if(/^\s*[下后後][一1]?[页頁张張]|^next( page)?\s*$|次のページ/i.test(aTag.innerText)){
  766. if(!aTag.href || /^javascript:/.test(aTag.href)){
  767. if(!nextJs1)nextJs1=aTag;
  768. }else{
  769. next1=aTag;
  770. }
  771. }
  772. }
  773. if(!next2){
  774. if(/^\s*[下后後][一1]?[章话話]/i.test(aTag.innerText)){
  775. if(!aTag.href || /^javascript:/.test(aTag.href)){
  776. if(!nextJs2)nextJs2=aTag;
  777. }else{
  778. next2=aTag;
  779. }
  780. }
  781. }
  782. if(!next3){
  783. if(aTag.innerText=="&gt;" || aTag.innerText=="▶" || aTag.innerText=="»"){
  784. if(!aTag.href || /^javascript:/.test(aTag.href)){
  785. if(!nextJs3)nextJs3=aTag;
  786. }else{
  787. next3=aTag;
  788. }
  789. }
  790. }
  791. if(!aTag.href || /^javascript:/.test(aTag.href))continue;
  792. if(!next4){
  793. if(aTag.href.replace("?&","?").replace("#!","").replace(preStr,"").replace(afterStr,"")==parseInt(pageNum)+1){
  794. next4=aTag;
  795. }else if(aTag.href.replace("?&","?").indexOf(url)!=-1 && /^[\/\?&]?[_-]?(p|page)?=?\/?2(\/|\?|&|$)/i.test(aTag.href.replace(url,"").replace(/\.s?html?$/i,""))){
  796. next4=aTag;
  797. }
  798. }
  799. }
  800. next=next1||next3||next4||next2||nextJs1||nextJs3||nextJs2;
  801. }
  802. if(!next)next=jsNext;
  803. return {next:next,canSave:canSave};
  804. }
  805.  
  806. getNextLink(doc) {
  807. let nextLink=null,page;
  808. if(this.curSiteRule.pageElementByJs){
  809. this.nextLinkHref="#";
  810. return true;
  811. }else if(this.curSiteRule.nextLinkByJs){
  812. try{
  813. let targetUrl=Function("doc",'"use strict";' + this.curSiteRule.nextLinkByJs)(doc);
  814. if(targetUrl)nextLink={href:targetUrl};
  815. }catch(e){
  816. debug(e);
  817. }
  818. }else if(this.curSiteRule.nextLinkByUrl){
  819. let targetUrl=this.curUrl.replace(new RegExp(this.curSiteRule.nextLinkByUrl[0]), this.curSiteRule.nextLinkByUrl[1]);
  820. if(targetUrl != this.curUrl){
  821. let reps=targetUrl.match(/{.*?}/g);
  822. if(reps){
  823. reps.forEach(rep=>{
  824. let code=rep.replace("{","").replace("}","");
  825. let result=code.match(/^(\d+)\+1$/);
  826. if(result){
  827. result=parseInt(result[1])+1;
  828. }else{
  829. try{
  830. result=Function('"use strict";return ' + code)();;
  831. }catch(e){
  832. debug(e);
  833. }
  834. }
  835. targetUrl=targetUrl.replace(rep, result);
  836. });
  837. }
  838. }
  839. nextLink={href:targetUrl};
  840. }else if(this.curSiteRule.nextLink){
  841. nextLink=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.nextLink,doc,doc):doc.querySelector(this.curSiteRule.nextLink);
  842. }else{
  843. page=this.getPage(doc);
  844. nextLink=page.next;
  845. if(nextLink && nextLink.classList.contains("noClick")){
  846. self.nextLinkHref=false;
  847. return null;
  848. }else if(nextLink && doc==document){
  849. if((!nextLink.href || /^javascript:/.test(nextLink.href)) && !isVisible(nextLink, _unsafeWindow)){
  850. self.nextLinkHref=false;
  851. return null;
  852. }else{
  853. let nextLinkCs=_unsafeWindow.getComputedStyle(nextLink);
  854. if(nextLinkCs.cursor=="not-allowed"){
  855. self.nextLinkHref=false;
  856. return null;
  857. }
  858. }
  859. }
  860. }
  861. if(nextLink){
  862. if(nextLink.href=="javascript:;" && (this.curSiteRule.action==0 || this.curSiteRule.action==1)){
  863. nextLink=null;
  864. }
  865. /*if(!this.curSiteRule.nextLink && page && page.canSave){
  866. this.curSiteRule.nextLink=this.geneSelector(nextLink);
  867. this.curSiteRule.type=1;
  868. this.saveCurSiteRule();
  869. }*/
  870. }
  871. if(nextLink){
  872. this.nextLinkHref=nextLink.href?nextLink.href:"#";
  873. debug(nextLink);
  874. }else{
  875. this.nextLinkHref=false;
  876. }
  877. return nextLink;
  878. }
  879.  
  880. getInsert(refresh) {
  881. if(this.insert && !refresh){
  882. let parent=this.insert;
  883. while(parent && parent.nodeName!="BODY"){
  884. parent=parent.parentNode;
  885. }
  886. if(parent && parent.nodeName=="BODY"){
  887. return this.insert;
  888. }
  889. }
  890. if(this.curSiteRule.insert){
  891. this.insert=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.insert,document):document.querySelector(this.curSiteRule.insert);
  892. }else{
  893. let pageElement=this.getPageElement(document, _unsafeWindow);
  894. if(pageElement && pageElement.length>0){
  895. var pELast = pageElement[pageElement.length - 1];
  896. this.insert = pELast.nextSibling ? pELast.nextSibling : pELast.parentNode.appendChild(document.createTextNode(' '));
  897. }
  898. }
  899. return this.insert;
  900. }
  901.  
  902. pageAction(doc,eles){
  903. let code=this.curSiteRule.pageAction;
  904. if(code){
  905. try{
  906. Function("doc","eles",'"use strict";' + code)(doc,eles);
  907. }catch(e){
  908. debug(e);
  909. }
  910. }
  911. [].forEach.call(eles, ele=>{
  912. [].forEach.call(ele.querySelectorAll("img"), img=>{
  913. let realSrc;
  914. if(img.dataset && img.dataset.original){
  915. realSrc=img.dataset.original;
  916. }else if(img.dataset && img.dataset.src){
  917. realSrc=img.dataset.src;
  918. }else if(img._lazyrias && img._lazyrias.srcset){
  919. realSrc=img._lazyrias.srcset[img._lazyrias.srcset.length-1];
  920. }else if(img.dataset && img.dataset.origFile){
  921. realSrc=img.dataset.origFile;
  922. }else if(img.srcset){
  923. var srcs=img.srcset.split(","),largeSize=0;
  924. srcs.forEach(srci=>{
  925. let srcInfo=srci.trim().split(" "),curSize=parseInt(srcInfo[1]);
  926. if(srcInfo[1] && curSize>largeSize){
  927. largeSize=curSize;
  928. realSrc=srcInfo[0];
  929. }
  930. });
  931. }
  932. if(realSrc)img.src=realSrc;
  933. });
  934. [].forEach.call(ele.querySelectorAll("a.lazyload"), a=>{
  935. if(a.dataset.original){
  936. a.style.backgroundImage='url("'+a.dataset.original+'")';
  937. }
  938. });
  939. });
  940. let lazyImgSrc=this.curSiteRule.lazyImgSrc;
  941. if(lazyImgSrc){
  942. [].forEach.call(eles, ele=>{
  943. [].forEach.call(ele.querySelectorAll("img"), img=>{
  944. if(img[lazyImgSrc]){
  945. img.src=img[lazyImgSrc];
  946. }
  947. });
  948. });
  949. }
  950. }
  951.  
  952. initPage(callback){
  953. let self=this;
  954. curPage=1;
  955. //if(this.curSiteRule.url && !this.curSiteRule.singleUrl)return;
  956. this.curSiteRule={};
  957. this.pageDoc=document;
  958. this.nextLinkHref=null;
  959. this.curUrl=location.href;
  960. this.getRule(()=>{
  961. if(self.curSiteRule.enable==0){
  962. debug("Stop as rule disable");
  963. isPause=true;
  964. return;
  965. }
  966. if(self.curSiteRule && !self.curSiteRule.singleUrl){
  967. self.hpRules=self.hpRules.filter(item=>{return item&&item.url!=self.curSiteRule.url});
  968. self.hpRules.unshift(self.curSiteRule);
  969. if(self.hpRules.length>30){
  970. self.hpRules.pop();
  971. }
  972. storage.setItem("hpRules", self.hpRules);
  973. }
  974. let css=self.curSiteRule.css;
  975. if(css){
  976. _GM_addStyle(css);
  977. }
  978. let code=self.curSiteRule.init;
  979. if(code){
  980. try{
  981. Function('"use strict";' + code)();
  982. }catch(e){
  983. debug(e);
  984. }
  985. }
  986. self.getNextLink(document);
  987. callback();
  988. });
  989. }
  990.  
  991. insertPage(doc, eles, url, callback, tried){
  992. this.pageDoc=doc;
  993. this.curUrl=url;
  994. let nextLink=this.getNextLink(doc);
  995. if(curPage==1 && !tried && !this.nextLinkHref && this.curSiteRule.singleUrl && this.curSiteRule.pageElement){
  996. this.curSiteRule.action=1;
  997. return false;
  998. }
  999. if(callback)callback(eles);
  1000. this.getInsert();
  1001. var self=this,newEles=[];
  1002. if(!eles || eles.length==0 || !self.insert || !self.insert.parentNode){
  1003. }else{
  1004. [].forEach.call(eles, ele=>{
  1005. let newEle=ele.cloneNode(true);
  1006. let oldCanvass=ele.querySelectorAll("canvas");
  1007. let newCanvass=newEle.querySelectorAll("canvas");
  1008. for(let i=0;i<oldCanvass.length;i++){
  1009. let oldCanvas=oldCanvass[i];
  1010. let newCanvas=newCanvass[i];
  1011. newCanvas.getContext('2d').drawImage(oldCanvas, 0, 0);
  1012. }
  1013. if(self.curSiteRule.insertPos==2){
  1014. self.insert.appendChild(newEle);
  1015. }else{
  1016. self.insert.parentNode.insertBefore(newEle, self.insert);
  1017. }
  1018. newEles.push(newEle);
  1019. });
  1020. }
  1021. this.pageAction(doc, newEles);
  1022. if(nextLink && nextLink.tagName){
  1023. let nextLinkCs=_unsafeWindow.getComputedStyle(nextLink);
  1024. if(nextLinkCs.cursor=="not-allowed" || !isVisible(nextLink, _unsafeWindow)){
  1025. self.nextLinkHref=false;
  1026. }
  1027. }
  1028. return true;
  1029. }
  1030. }
  1031. var ruleParser = new RuleParser();
  1032.  
  1033. function initConfig(){
  1034. _GM_registerMenuCommand(i18n(forceState==1?"enable":"disableSite"), ()=>{
  1035. storage.setItem("forceState_"+location.host, (forceState==1?0:1));
  1036. location.reload();
  1037. });
  1038.  
  1039. _GM_registerMenuCommand(i18n(forceState==2?"cancelForceIframe":"forceIframe"), ()=>{
  1040. storage.setItem("forceState_"+location.host, (forceState==2?"":2));
  1041. location.reload();
  1042. });
  1043. var configCon,insertPos;
  1044. if(location.href==configPage){
  1045. _GM_addStyle(`
  1046. p>span:nth-child(1),p>span:nth-child(2),p>span:nth-child(3){
  1047. cursor: pointer;
  1048. user-select: none;
  1049. }
  1050. p>span:nth-child(1):hover,p>span:nth-child(2):hover,p>span:nth-child(3):hover{
  1051. color:red;
  1052. }
  1053. .updateDate{
  1054. cursor: pointer;
  1055. user-select: none;
  1056. }
  1057. .updateDate:hover{
  1058. color:red;
  1059. }
  1060. `);
  1061. configCon=document.querySelector(".markdown-body");
  1062. insertPos=configCon.querySelector("hr");
  1063. }else if(location.href==configPage){
  1064. }else return false;
  1065. class Rulebar {
  1066. init(ruleUrl){
  1067. this.ruleUrl=ruleUrl;
  1068. this.item=document.createElement("p");
  1069. this.item.title=ruleUrl.type==0?"AutoPagerize Rules":"Pagetual Rules";
  1070. this.item.dataset.id=this.ruleUrl.id;
  1071. let url=document.createElement("span");
  1072. url.innerHTML=ruleUrl.url;
  1073. let up=document.createElement("span");
  1074. up.innerHTML="↑ ";
  1075. up.title=i18n("sortTitle");
  1076. let down=document.createElement("span");
  1077. down.innerHTML="↓ ";
  1078. down.title=i18n("sortTitle");
  1079. let del=document.createElement("span");
  1080. del.innerHTML="× ";
  1081. up.onclick=e=>{
  1082. this.moveUp();
  1083. };
  1084. down.onclick=e=>{
  1085. this.moveDown();
  1086. };
  1087. del.onclick=e=>{
  1088. this.del();
  1089. };
  1090. this.item.appendChild(up);
  1091. this.item.appendChild(down);
  1092. this.item.appendChild(del);
  1093. this.item.appendChild(url);
  1094. configCon.insertBefore(this.item, insertPos);
  1095. }
  1096. saveSort(){
  1097. let sort=[];
  1098. [].forEach.call(this.item.parentNode.querySelectorAll("p[data-id]"), i=>{
  1099. sort.push(i.dataset.id);
  1100. });
  1101. rulesData.sort=sort;
  1102. storage.setItem("rulesData", rulesData);
  1103. }
  1104. moveUp(){
  1105. let preE=this.item.previousElementSibling;
  1106. if(preE.tagName=="P" && preE.children.length>1){
  1107. this.item.parentNode.insertBefore(this.item,preE);
  1108. this.saveSort();
  1109. }
  1110. }
  1111. moveDown(){
  1112. let nextE=this.item.nextElementSibling;
  1113. if(nextE.tagName=="P" && nextE.children.length>1){
  1114. this.item.parentNode.insertBefore(nextE,this.item);
  1115. this.saveSort();
  1116. }
  1117. }
  1118. del(){
  1119. if(this.ruleUrl.id<2){
  1120. alert(i18n("cantDel"));
  1121. }else if(window.confirm(i18n("confirmDel"))){
  1122. for(let u=0;u<rulesData.urls.length;u++){
  1123. if(this.ruleUrl.id==rulesData.urls[u].id){
  1124. rulesData.urls.splice(u,1);
  1125. break;
  1126. }
  1127. }
  1128. for(let u=0;u<rulesData.sort.length;u++){
  1129. if(this.ruleUrl.id==rulesData.sort[u]){
  1130. rulesData.sort.splice(u,1);
  1131. break;
  1132. }
  1133. }
  1134. storage.setItem("rulesData", rulesData);
  1135. ruleParser.rules=ruleParser.rules.filter(item=>{return item.from!=this.ruleUrl.id});
  1136. storage.setItem("rules", ruleParser.rules);
  1137. this.item.parentNode.removeChild(this.item);
  1138. //location.reload();
  1139. }
  1140. }
  1141. }
  1142. let updateP=document.createElement("p"),i=0;
  1143. let now=new Date().getTime(),inUpdate=false;
  1144.  
  1145.  
  1146. let pastDate=(new Date(updateDate)).toString(),passStr;
  1147. let passTime=(now-updateDate)/1000;
  1148. if(passTime<60){
  1149. passStr=i18n("passSec", passTime);
  1150. }else if(passTime<60*60){
  1151. passStr=i18n("passMin", parseInt(passTime/60));
  1152. }else if(passTime<60*60*24){
  1153. passStr=i18n("passHour", parseInt(passTime/3600));
  1154. }else{
  1155. passStr=i18n("passDay", parseInt(passTime/86400));
  1156. }
  1157.  
  1158.  
  1159. updateP.className="updateDate";
  1160. updateP.innerHTML=passStr;
  1161. updateP.title=i18n("update")+" - "+pastDate;
  1162. updateP.onclick=e=>{
  1163. if(inUpdate)return;
  1164. inUpdate=true;
  1165. let ruleIndex=0;
  1166. storage.setItem("hpRules", []);
  1167. function addNextRule(){
  1168. if(ruleIndex>=ruleUrls.length){
  1169. storage.setItem("ruleLastUpdate", now);
  1170. alert(i18n("updateSucc"));
  1171. inUpdate=false;
  1172. updateP.innerHTML=i18n("passSec", 0);
  1173. updateP.title=i18n("update");
  1174. }else{
  1175. let rule=ruleUrls[ruleIndex++];
  1176. ruleParser.addRuleByUrl(rule.url, rule.type, rule.id, ()=>{
  1177. addNextRule();
  1178. })
  1179. }
  1180. }
  1181. addNextRule();
  1182. alert(i18n("beginUpdate"));
  1183. };
  1184. configCon.insertBefore(updateP, insertPos);
  1185. if(ruleUrls){
  1186. ruleUrls.forEach(ruleUrl=>{
  1187. var rulebar=new Rulebar();
  1188. rulebar.init(ruleUrl);
  1189. });
  1190. }
  1191. let customUrlsTitle=document.createElement("h2");
  1192. customUrlsTitle.innerHTML=i18n("customUrls");
  1193. configCon.insertBefore(customUrlsTitle, insertPos);
  1194. let customUrlsInput=document.createElement("textarea");
  1195. customUrlsInput.style.width="100%";
  1196. customUrlsInput.placeholder="0|http://wedata.net/databases/AutoPagerize/items_all.json";
  1197. configCon.insertBefore(customUrlsInput, insertPos);
  1198.  
  1199. let opacityTitle=document.createElement("h2");
  1200. opacityTitle.innerHTML=i18n("opacity");
  1201. let opacityInput=document.createElement("input");
  1202. opacityInput.value=rulesData.opacity*100;
  1203. opacityInput.type="number";
  1204. opacityInput.style.width="50px";
  1205. opacityInput.style.margin="0 0 0 10px";
  1206. opacityTitle.appendChild(opacityInput);
  1207. configCon.insertBefore(opacityTitle, insertPos);
  1208.  
  1209.  
  1210. let hideBarTitle=document.createElement("h2");
  1211. hideBarTitle.innerHTML=i18n("hideBar");
  1212. let hideBarInput=document.createElement("input");
  1213. hideBarInput.type="checkbox";
  1214. hideBarInput.style.width="50px";
  1215. hideBarInput.style.height="20px";
  1216. hideBarInput.checked=rulesData.hideBar;
  1217. hideBarTitle.appendChild(hideBarInput);
  1218. configCon.insertBefore(hideBarTitle, insertPos);
  1219.  
  1220. let dbClick2StopTitle=document.createElement("h2");
  1221. dbClick2StopTitle.innerHTML=i18n("dbClick2Stop");
  1222. let dbClick2StopInput=document.createElement("input");
  1223. dbClick2StopInput.type="checkbox";
  1224. dbClick2StopInput.style.width="50px";
  1225. dbClick2StopInput.style.height="20px";
  1226. dbClick2StopInput.checked=rulesData.dbClick2Stop;
  1227. dbClick2StopTitle.appendChild(dbClick2StopInput);
  1228. configCon.insertBefore(dbClick2StopTitle, insertPos);
  1229.  
  1230. let enableWhiteListTitle=document.createElement("h2");
  1231. enableWhiteListTitle.innerHTML=i18n("autoRun");
  1232. let enableWhiteListInput=document.createElement("input");
  1233. enableWhiteListInput.type="checkbox";
  1234. enableWhiteListInput.style.width="50px";
  1235. enableWhiteListInput.style.height="20px";
  1236. enableWhiteListInput.checked=rulesData.enableWhiteList!=true;
  1237. enableWhiteListTitle.appendChild(enableWhiteListInput);
  1238. configCon.insertBefore(enableWhiteListTitle, insertPos);
  1239.  
  1240. let customRulesTitle=document.createElement("h2");
  1241. customRulesTitle.innerHTML=i18n("customRules")
  1242. configCon.insertBefore(customRulesTitle, insertPos);
  1243. let customRulesInput=document.createElement("textarea");
  1244. customRulesInput.style.width="100%";
  1245. customRulesInput.style.height="500px";
  1246. 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]`;
  1247. customRulesInput.value=getFormatJSON(ruleParser.customRules);
  1248. configCon.insertBefore(customRulesInput, insertPos);
  1249. let saveBtn=document.createElement("button");
  1250. saveBtn.innerHTML=i18n("save");
  1251. saveBtn.style.width="100%";
  1252. configCon.insertBefore(saveBtn, insertPos);
  1253. saveBtn.onclick=e=>{
  1254. try{
  1255. storage.setItem("hpRules", []);
  1256. if(customRulesInput.value==""){
  1257. storage.setItem("customRules", "");
  1258. }else{
  1259. let customRules=JSON.parse(customRulesInput.value);
  1260. if(Array && Array.isArray && !Array.isArray(customRules)){
  1261. alert("Rules must be a Array!");
  1262. return;
  1263. }
  1264. debug(customRules);
  1265. storage.setItem("customRules", customRules);
  1266. }
  1267. }catch(e){
  1268. debug(e);
  1269. alert("JSON error, check again!");
  1270. return;
  1271. }
  1272. rulesData.opacity=opacityInput.value/100;
  1273. rulesData.hideBar=hideBarInput.checked;
  1274. rulesData.dbClick2Stop=dbClick2StopInput.checked;
  1275. rulesData.enableWhiteList=!enableWhiteListInput.checked;
  1276. storage.setItem("rulesData", rulesData);
  1277. let customUrls=customUrlsInput.value.trim();
  1278. if(customUrls){
  1279. customUrls=customUrls.split(/\n/);
  1280. for(let c=0;c<customUrls.length;c++){
  1281. let urlArr=customUrls[c].split("|"),url,type=1;
  1282. if(urlArr.length==1){
  1283. url=urlArr[0].trim();
  1284. if(!/^http/.test(url)){
  1285. alert("Wrong url, check again!");
  1286. return;
  1287. }
  1288. }else if(urlArr.length==2){
  1289. type=urlArr[0].trim();
  1290. url=urlArr[1].trim();
  1291. if(!/^http/.test(url)){
  1292. alert("Wrong url, check again!");
  1293. return;
  1294. }
  1295. }else{
  1296. break;
  1297. }
  1298. let maxId=0,hasUrl=false;;
  1299. if(!rulesData.urls){
  1300. rulesData.urls=[];
  1301. maxId=1;
  1302. }else{
  1303. rulesData.urls.forEach(u=>{
  1304. if(maxId<u.id){
  1305. maxId=u.id;
  1306. }
  1307. if(u.url==url){
  1308. hasUrl=true;
  1309. }
  1310. });
  1311. if(hasUrl)break;
  1312. }
  1313. rulesData.urls.push({id:maxId+1,url:url,type:type});
  1314. rulesData.sort.push(maxId+1);
  1315. storage.setItem("rulesData", rulesData);
  1316. }
  1317. }
  1318. alert("Modified successfully");
  1319. location.reload();
  1320. };
  1321. return true;
  1322. }
  1323.  
  1324. function objIsArr(obj) {
  1325. return obj &&
  1326. typeof obj === 'object' &&
  1327. typeof obj.length === 'number' &&
  1328. !(obj.propertyIsEnumerable('length'));
  1329. }
  1330.  
  1331. function isVisible(el, win) {
  1332. var loopable = true,
  1333. visible = win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  1334. while(loopable && visible) {
  1335. el = el.parentNode;
  1336.  
  1337. if(el && el.tagName!="BODY") {
  1338. visible = win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  1339. }else {
  1340. loopable = false;
  1341. }
  1342. }
  1343. return visible;
  1344. }
  1345.  
  1346. function getFormatJSON(obj){
  1347. if(!objIsArr(obj))return "";
  1348. let ret="[\n";
  1349. let len=obj.length,i=0,isLast;
  1350. obj.forEach(item=>{
  1351. ret+=" {\n";
  1352. let iLen=Object.keys(item).length,j=0;
  1353. for(let key in item){
  1354. isLast=(++j)==iLen;
  1355. let value=item[key];
  1356. if(objIsArr(value)){
  1357. let vstr="[",v=0,vIsLast=false;
  1358. value.forEach(vi=>{
  1359. vIsLast=(++v)==value.length;
  1360. vstr+="\""+vi.replace(/\\/g,"\\\\")+"\""+(vIsLast?"":",");
  1361. });
  1362. vstr+="]";
  1363. ret+=" \""+key+"\":"+vstr+""+(isLast?"":",")+"\n";
  1364. }else{
  1365. if(typeof value=="string"){
  1366. value=value.replace(/\\/g,"\\\\").replace(/"/g,"\\\"");
  1367. value="\""+value+"\"";
  1368. }
  1369. ret+=" \""+key+"\":"+value+""+(isLast?"":",")+"\n";
  1370. }
  1371. }
  1372. isLast=(++i)==len;
  1373. ret+=" }"+(isLast?"":",")+"\n";
  1374. });
  1375. ret+="]";
  1376. return ret;
  1377. }
  1378.  
  1379. function initRules(callback) {
  1380. /*0 wedata格式,1 pagetual格式*/
  1381. ruleUrls=[
  1382. {
  1383. id:0,
  1384. url:'https://raw.githubusercontent.com/hoothin/UserScripts/master/Pagetual/pagetualRules.json',
  1385. type:1
  1386. },
  1387. {
  1388. id:1,
  1389. url:'http://wedata.net/databases/AutoPagerize/items_all.json',
  1390. type:0,
  1391. }
  1392. ];var i=0,j=0;
  1393.  
  1394. ruleParser.initSavedRules(()=>{
  1395. storage.getItem("rulesData", data=>{
  1396. if(data){
  1397. rulesData=data;
  1398. if(data.urls)ruleUrls=ruleUrls.concat(data.urls);
  1399. if(data.sort){
  1400. let urls=[];
  1401. data.sort.forEach(id=>{
  1402. for(let s=0;s<ruleUrls.length;s++){
  1403. if(id==ruleUrls[s].id){
  1404. urls.push(ruleUrls[s]);
  1405. break;
  1406. }
  1407. }
  1408. });
  1409. ruleUrls=urls;
  1410. }
  1411. }
  1412. if(typeof(rulesData.opacity)=="undefined"){
  1413. rulesData.opacity=0.3;
  1414. }
  1415. if(typeof(rulesData.hideBar)=="undefined"){
  1416. rulesData.hideBar=true;
  1417. }
  1418. if(typeof(rulesData.dbClick2Stop)=="undefined"){
  1419. rulesData.dbClick2Stop=true;
  1420. }
  1421. if(typeof(rulesData.enableWhiteList)=="undefined"){
  1422. rulesData.enableWhiteList=false;
  1423. }
  1424. storage.getItem("forceState_"+location.host, v=>{
  1425. storage.getItem("ruleLastUpdate", date=>{
  1426. if(typeof(v)=="undefined"){
  1427. v=(rulesData.enableWhiteList?1:0);
  1428. }
  1429. forceState=v;
  1430. updateDate=date;
  1431. if(initConfig())return;
  1432. if(forceState==1)return;
  1433. let now=new Date().getTime();
  1434. if(!date || now-date>2*24*60*60*1000){
  1435. storage.setItem("ruleLastUpdate", now);
  1436. storage.setItem("hpRules", []);
  1437. let ruleIndex=0;
  1438. function addNextRule(){
  1439. if(ruleIndex>=ruleUrls.length){
  1440. callback();
  1441. }else{
  1442. let rule=ruleUrls[ruleIndex++];
  1443. ruleParser.addRuleByUrl(rule.url, rule.type, rule.id, ()=>{
  1444. addNextRule();
  1445. })
  1446. }
  1447. }
  1448. addNextRule();
  1449. }else{
  1450. callback();
  1451. }
  1452. });
  1453. });
  1454. });
  1455. });
  1456. }
  1457.  
  1458. function requestDoc(url, callback){
  1459. _GM_xmlhttpRequest({
  1460. url: url,
  1461. method: 'GET',
  1462. overrideMimeType: 'text/html;charset='+document.charset,
  1463. headers: {
  1464. 'Referer': location.href
  1465. },
  1466. timeout: 5000,
  1467. onload: function(res) {
  1468. var doc=null;
  1469. try {
  1470. doc=document.implementation.createHTMLDocument('');
  1471. doc.documentElement.innerHTML=res.response;
  1472. }
  1473. catch (e) {
  1474. debug('parse error'+e.toString());
  1475. }
  1476. let pageElement=ruleParser.getPageElement(doc);
  1477. //只有1的話怕不是圖片哦
  1478. if(pageElement && (pageElement.length>1 || (pageElement.length==1 && pageElement[0].tagName!="IMG") )){
  1479. let result=ruleParser.insertPage(doc, pageElement, url, callback, false);
  1480. if(!result){
  1481. requestFromIframe(url, (doc, eles)=>{
  1482. if(eles){
  1483. ruleParser.insertPage(doc, eles, url, callback, true);
  1484. }
  1485. });
  1486. }
  1487. }else if(ruleParser.curSiteRule.singleUrl){
  1488. requestFromIframe(url, (doc, eles)=>{
  1489. if(eles){
  1490. ruleParser.insertPage(doc, eles, url, callback, true);
  1491. }
  1492. });
  1493. }
  1494. },
  1495. onerror: function(e){
  1496. debug(e);
  1497. callback(false);
  1498. }
  1499. });
  1500. }
  1501.  
  1502. var failFromIframe=0;
  1503. function requestFromIframe(url, callback){
  1504. let orgPage,curPage;
  1505. let iframe = document.createElement('iframe');
  1506. iframe.name = 'pagetual-iframe';
  1507. iframe.width = '100%';
  1508. iframe.height = '0';
  1509. iframe.frameBorder = '0';
  1510. if(ruleParser.curSiteRule.sandbox){
  1511. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1512. }
  1513. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1514. iframe.addEventListener("load", e=>{
  1515. let waitTime=500,checkEval;
  1516. if(ruleParser.curSiteRule.wait){
  1517. if(isNaN(ruleParser.curSiteRule.wait)){
  1518. try{
  1519. checkEval=Function("doc",'"use strict";' + ruleParser.curSiteRule.wait);
  1520. }catch(e){
  1521. debug(e);
  1522. }
  1523. }else{
  1524. waitTime=ruleParser.curSiteRule.wait;
  1525. }
  1526. }
  1527. setTimeout(()=>{
  1528. let tryTimes=0;
  1529. function checkIframe(){
  1530. try{
  1531. let doc=iframe.contentDocument || iframe.contentWindow.document;
  1532. let eles=ruleParser.getPageElement(doc, iframe.contentWindow);
  1533. if(eles && eles.length>0 && (!checkEval || checkEval(doc))){
  1534. callback(doc, eles);
  1535. }else if(tryTimes++ < 10){
  1536. setTimeout(()=>{
  1537. checkIframe();
  1538. },waitTime);
  1539. return;
  1540. }else{
  1541. if(failFromIframe++ > 2){
  1542. failFromIframe=0;
  1543. debug("Stop as failFromIframe");
  1544. isPause=true;
  1545. callback(false, false);
  1546. }else{
  1547. callback(false, false);
  1548. }
  1549. }
  1550. }catch(e){
  1551. debug("Stop as cors");
  1552. isPause=true;
  1553. callback(false, false);
  1554. }
  1555. document.body.removeChild(iframe);
  1556. }
  1557. checkIframe();
  1558. },waitTime);
  1559. });
  1560. iframe.src=url;
  1561. document.body.appendChild(iframe);
  1562. }
  1563.  
  1564. function initPage(){
  1565. ruleParser.initPage(()=>{
  1566. if(ruleParser.nextLinkHref)initView();
  1567. initListener();
  1568. nextPage();
  1569. });
  1570. }
  1571.  
  1572. function initView(){
  1573. _GM_addStyle(`
  1574. .pagetual_pageBar.stop {
  1575. -webkit-filter: invert(100%);
  1576. filter: invert(100%);
  1577. opacity: 1!important;
  1578. }
  1579. .pagetual_pageBar.hide {
  1580. display: none!important;
  1581. }
  1582. .pagetual_pageBar:hover {
  1583. opacity: 1!important;
  1584. }
  1585. .pagetual_pageBar span {
  1586. vertical-align: super;
  1587. }
  1588.  
  1589. .pagetual_pageBar span>svg:hover {
  1590. animation: touhouAni 1s infinite;
  1591. }
  1592.  
  1593. @keyframes touhouAni{
  1594. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  1595. to {transform: rotate(360deg);}
  1596. }
  1597. @-webkit-keyframes touhouAni{
  1598. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  1599. to {transform: rotate(360deg);}
  1600. }
  1601. `);
  1602. 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: 5px auto; text-align: center;`;
  1603. }
  1604. var loading=document.createElement("div");
  1605. loading.className="pagetual_loading";
  1606. 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;";
  1607. 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>`;
  1608. document.body.appendChild(loading);
  1609.  
  1610. 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>`;
  1611. 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>`;
  1612. var pageBarStyle;
  1613. var initStyle=`display: initial;right: unset;left: unset;top: unset;bottom: unset;inset: unset;clear: both;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;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;`;
  1614. 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);`;
  1615.  
  1616. var isPause=false,isLoading=false,curPage=1,forceState=0,bottomGap=1000;
  1617.  
  1618. function changeStop(stop, hide){
  1619. isPause=stop;
  1620. [].forEach.call(document.querySelectorAll(".pagetual_pageBar"), bar=>{
  1621. if(isPause){
  1622. bar.classList.add("stop");
  1623. if(hide)bar.classList.add("hide");
  1624. }else{
  1625. bar.classList.remove("stop");
  1626. if(hide)bar.classList.remove("hide");
  1627. }
  1628. });
  1629. }
  1630.  
  1631. function isInViewPort(element) {
  1632. if(!element.parentNode)return false;
  1633. if(_unsafeWindow.getComputedStyle(element).display=="none")return false;
  1634. const viewWidth = window.innerWidth || document.documentElement.clientWidth;
  1635. const viewHeight = window.innerHeight || document.documentElement.clientHeight;
  1636. const {
  1637. top,
  1638. right,
  1639. bottom,
  1640. left,
  1641. } = element.getBoundingClientRect();
  1642.  
  1643. return (
  1644. top >= 0 &&
  1645. left >= 0 &&
  1646. right <= viewWidth &&
  1647. bottom <= viewHeight
  1648. );
  1649. }
  1650.  
  1651. var urlChanged=false;
  1652. var _wr = function(type) {
  1653. var orig = history[type];
  1654. return function() {
  1655. var rv = orig.apply(this, arguments);
  1656. var e = new Event(type);
  1657. e.arguments = arguments;
  1658. window.dispatchEvent(e);
  1659. return rv;
  1660. };
  1661. };
  1662. history.pushState = _wr('pushState');
  1663. window.addEventListener('pushState', function(e) {
  1664. urlChanged=true;
  1665. setTimeout(()=>{
  1666. if(location.href==configPage){
  1667. location.reload();
  1668. }
  1669. },1);
  1670. });
  1671.  
  1672. function initListener(){
  1673. let loadmoreBtn,loading=true;
  1674. setTimeout(()=>{
  1675. loadmoreBtn=getLoadMore(document);
  1676. if(loadmoreBtn){
  1677. loading=false;
  1678. }
  1679. },300);
  1680. document.addEventListener('scroll', e=>{
  1681. if(urlChanged){
  1682. ruleParser.initPage(()=>{
  1683. if(ruleParser.nextLinkHref)initView();
  1684. });
  1685. urlChanged=false;
  1686. isPause=false;
  1687. }
  1688. if(!loading && !isPause){
  1689. loading=true;
  1690. if(!loadmoreBtn || !loadmoreBtn.parentNode){
  1691. loadmoreBtn=getLoadMore(document);
  1692. }
  1693. if(loadmoreBtn){
  1694. loading=false;
  1695. if(isInViewPort(loadmoreBtn)){
  1696. emuClick(loadmoreBtn);
  1697. }
  1698. }else{
  1699. setTimeout(()=>{loading=false},500);
  1700. }
  1701. }
  1702. setTimeout(()=>{
  1703. if(!isPause && !isLoading){
  1704. let scrolly=window.scrollY;
  1705. let windowHeight=window.innerHeight;
  1706. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  1707. if(scrollH-scrolly-windowHeight<bottomGap){
  1708. nextPage();
  1709. }
  1710. }
  1711. },100);
  1712. }, true);
  1713. document.addEventListener('dblclick', e=>{
  1714. if(rulesData.dbClick2Stop){
  1715. setTimeout(()=>{
  1716. changeStop(!isPause, rulesData.hideBar);
  1717. if(!isPause){
  1718. let scrolly=window.scrollY;
  1719. let windowHeight=window.innerHeight;
  1720. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  1721. if(scrollH-scrolly-windowHeight<bottomGap){
  1722. nextPage();
  1723. }
  1724. }
  1725. },200);
  1726. }
  1727. });
  1728. }
  1729.  
  1730. function getLoadMore(doc){
  1731. let btnSel=ruleParser.curSiteRule.loadMore||".LoadMore,.load-more";
  1732. let loadmoreBtn=doc.querySelector(btnSel);
  1733. if(!loadmoreBtn){
  1734. let buttons=doc.querySelectorAll("input,button,a,div[onclick]"),loadmoreReg=/^\s*(加载更多|加載更多|load\s*more|もっと読み込む)\s*$/i;
  1735. for(let i=0;i<buttons.length;i++){
  1736. let button=buttons[i];
  1737. if(button && loadmoreReg.test(button.innerText)){
  1738. loadmoreBtn=button;
  1739. break;
  1740. }
  1741. }
  1742. }
  1743. return loadmoreBtn;
  1744. }
  1745.  
  1746. function createPageBar(url){
  1747. let insert=ruleParser.getInsert();
  1748. if(!insert || !insert.parentNode)return;
  1749. curPage++;
  1750. let inTable=insert.tagName=="TR" ||
  1751. (insert.previousElementSibling && insert.previousElementSibling.tagName=="TR") ||
  1752. insert.tagName=="TBODY" || (insert.previousElementSibling && insert.previousElementSibling.tagName=="TBODY");
  1753. let inLi=insert.tagName=="LI" || (insert.previousElementSibling && insert.previousElementSibling.tagName=="LI");
  1754. let pageBar=document.createElement(inTable?"tr":"div");
  1755. let upSpan=document.createElement("span");
  1756. let downSpan=document.createElement("span");
  1757. let pageText=document.createElement("a");
  1758. pageBar.className="pagetual_pageBar";
  1759. pageBar.id="pagetual_pageBar";
  1760. if(isPause){
  1761. pageBar.classList.add("stop");
  1762. }
  1763. pageBar.style.cssText=pageBarStyle;
  1764. pageBar.title=i18n(isPause?"enable":"disable");
  1765. upSpan.innerHTML=upSvg;
  1766. upSpan.title=i18n("toTop");
  1767. downSpan.innerHTML=downSvg;
  1768. downSpan.title=i18n("toBottom");
  1769. upSpan.style.cssText=initStyle;
  1770. downSpan.style.cssText=initStyle;
  1771. pageText.href=url;
  1772. pageText.style=pageTextStyle;
  1773. pageText.innerHTML="Page "+curPage;
  1774. pageText.title=i18n("current");
  1775. pageBar.appendChild(upSpan);
  1776. pageBar.appendChild(pageText);
  1777. pageBar.appendChild(downSpan);
  1778. if(inTable){
  1779. let example=(insert.tagName=="TR" || insert.tagName=="TBODY")?insert:insert.previousElementSibling;
  1780. let tdNum=0;
  1781. [].forEach.call(example.querySelectorAll("td,th"), td=>{
  1782. tdNum+=td.colSpan||1;
  1783. });
  1784. pageBar.style.display="table-row";
  1785. pageBar.style.backgroundColor="unset";
  1786. let td=document.createElement("td");
  1787. td.style.backgroundColor="rgb(240 240 240 / 80%)";
  1788. td.style.borderRadius="20px";
  1789. td.colSpan=tdNum||1;
  1790. td.style.padding="0 0";
  1791. td.style.textAlign="center";
  1792. td.appendChild(upSpan);
  1793. td.appendChild(pageText);
  1794. td.appendChild(downSpan);
  1795. pageBar.appendChild(td);
  1796. }
  1797.  
  1798. upSpan.addEventListener("click", e=>{
  1799. //changeStop(true);
  1800. //pageBar.title=i18n(isPause?"enable":"disable");
  1801. document.body.scrollTop=0;
  1802. document.documentElement.scrollTop=0;
  1803. e.preventDefault();
  1804. e.stopPropagation();
  1805. });
  1806. downSpan.addEventListener("click", e=>{
  1807. changeStop(true);
  1808. pageBar.title=i18n(isPause?"enable":"disable");
  1809. document.body.scrollTop=9999999;
  1810. document.documentElement.scrollTop=9999999;
  1811. e.preventDefault();
  1812. e.stopPropagation();
  1813. });
  1814. pageBar.addEventListener("click", e=>{
  1815. changeStop(!isPause);
  1816. pageBar.title=i18n(isPause?"enable":"disable");
  1817. });
  1818. pageText.addEventListener("click", e=>{
  1819. e.stopPropagation();
  1820. });
  1821. let parentStyle=_unsafeWindow.getComputedStyle(insert.parentNode);
  1822. pageBar.style.width=parseInt(parentStyle.width)*.99-parseInt(parentStyle.paddingLeft)-parseInt(parentStyle.paddingRight)+"px";
  1823. if(inLi){
  1824. pageBar.style.width="90%";
  1825. pageBar.style.minWidth="150px";
  1826. pageBar.style.display="inline-block";
  1827. let line=document.createElement("li");
  1828. line.style.textAlign="center";
  1829. line.appendChild(pageBar);
  1830. if(ruleParser.curSiteRule.insertPos==2){
  1831. insert.appendChild(line);
  1832. }else{
  1833. insert.parentNode.insertBefore(line, insert);
  1834. }
  1835. }else{
  1836. if(ruleParser.curSiteRule.insertPos==2){
  1837. insert.appendChild(pageBar);
  1838. }else{
  1839. insert.parentNode.insertBefore(pageBar, insert);
  1840. }
  1841. }
  1842.  
  1843. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  1844. let actualTop = pageBar.offsetTop;
  1845. let current = pageBar.parentNode.offsetParent;
  1846. while (current !== null){
  1847. actualTop += current.offsetTop;
  1848. current = current.offsetParent;
  1849. }
  1850. bottomGap=scrollH-actualTop+800;
  1851. return pageBar;
  1852. }
  1853.  
  1854. function emuClick(btn){
  1855. if(!PointerEvent)return btn.click();
  1856. let eventParam={
  1857. isTrusted: true,
  1858. altKey: false,
  1859. azimuthAngle: 0,
  1860. bubbles: true,
  1861. button: 0,
  1862. buttons: 0,
  1863. clientX: 1,
  1864. clientY: 1,
  1865. cancelBubble: false,
  1866. cancelable: true,
  1867. composed: true,
  1868. ctrlKey: false,
  1869. defaultPrevented: false,
  1870. detail: 1,
  1871. eventPhase: 2,
  1872. fromElement: null,
  1873. height: 1,
  1874. isPrimary: false,
  1875. metaKey: false,
  1876. pointerId: 1,
  1877. pointerType: "mouse",
  1878. pressure: 0,
  1879. relatedTarget: null,
  1880. returnValue: true,
  1881. shiftKey: false,
  1882. toElement: null,
  1883. twist: 0,
  1884. type: "click",
  1885. which: 1
  1886. };
  1887. var mouseclick = new PointerEvent("click",eventParam);
  1888. btn.dispatchEvent(mouseclick);
  1889. }
  1890.  
  1891. var emuIframe;
  1892. function emuPage(callback){
  1893. let orgPage,curPage,iframeDoc,times=0,loadmoreBtn,loadmoreEnd=false,waitTimes=10;
  1894. function checkPage(){
  1895. if(isPause)return;
  1896. try{
  1897. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  1898. }catch(e){
  1899. debug("Stop as cors");
  1900. isPause=true;
  1901. callback(false, false);
  1902. return;
  1903. }
  1904.  
  1905. let nextLink=ruleParser.getNextLink(iframeDoc);
  1906. let waitTime=500,checkEval;
  1907. if(ruleParser.curSiteRule.wait){
  1908. if(isNaN(ruleParser.curSiteRule.wait)){
  1909. try{
  1910. checkEval=Function("doc",'"use strict";' + ruleParser.curSiteRule.wait);
  1911. }catch(e){
  1912. debug(e);
  1913. }
  1914. }else{
  1915. waitTime=ruleParser.curSiteRule.wait;
  1916. }
  1917. }
  1918.  
  1919. if(!orgPage){
  1920. if(!loadmoreEnd){
  1921. loadmoreBtn=getLoadMore(iframeDoc);
  1922. if(loadmoreBtn){
  1923. emuClick(loadmoreBtn);
  1924. let intv=setInterval(()=>{
  1925. loadmoreBtn=getLoadMore(iframeDoc);
  1926. if(!loadmoreBtn || !loadmoreBtn.parentNode || !isVisible(loadmoreBtn, iframeDoc.defaultView)){
  1927. clearInterval(intv);
  1928. loadmoreEnd=true;
  1929. setTimeout(()=>{
  1930. checkPage();
  1931. },500);
  1932. }else{
  1933. emuClick(loadmoreBtn);
  1934. }
  1935. },200);
  1936. return;
  1937. }else{
  1938. loadmoreEnd=true;
  1939. }
  1940. }
  1941. let pageEle=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true);
  1942. if(!nextLink || !pageEle || (checkEval && !checkEval(iframeDoc))){
  1943. if(ruleParser.curSiteRule.wait && waitTimes-->0){
  1944. setTimeout(()=>{
  1945. checkPage();
  1946. },waitTime);
  1947. return;
  1948. }
  1949. }
  1950. orgPage=pageEle;
  1951. if(!orgPage || orgPage.length==0){
  1952. debug("Stop as no page when emu");
  1953. isPause=true;
  1954. callback(false, false);
  1955. return;
  1956. }
  1957. if(orgPage && orgPage[0].tagName=="UL")orgPage=orgPage[0].children;
  1958. if(orgPage && nextLink){
  1959. orgPage=orgPage[parseInt(orgPage.length/2)];
  1960. if(!isVisible(nextLink, iframeDoc.defaultView)){
  1961. debug("Stop as next hide when emu");
  1962. isPause=true;
  1963. callback(false, false);
  1964. }else{
  1965. emuClick(nextLink);
  1966. setTimeout(()=>{
  1967. checkPage();
  1968. },500);
  1969. }
  1970. }else{
  1971. debug("Stop as no next when emu");
  1972. isPause=true;
  1973. callback(false, false);
  1974. }
  1975. return;
  1976. }
  1977. if(times++ > 20){
  1978. //emuClick(nextLink);
  1979. debug("Stop as timeout when emu");
  1980. isPause=true;
  1981. callback(false, false);
  1982. return;
  1983. }
  1984. let eles=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true),checkItem=eles;
  1985. if(eles && eles[0].tagName=="UL")checkItem=eles[0].children;
  1986. if(!eles || eles.length==0 || orgPage == checkItem[parseInt(checkItem.length/2)] || (checkEval && !checkEval(iframeDoc))){
  1987. setTimeout(()=>{
  1988. checkPage();
  1989. },waitTime);
  1990. }else{
  1991. callback(iframeDoc, eles);
  1992. }
  1993. }
  1994. if(!emuIframe){
  1995. emuIframe = document.createElement('iframe');
  1996. emuIframe.name = 'pagetual-iframe';
  1997. if(ruleParser.curSiteRule.sandbox){
  1998. emuIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1999. }
  2000. emuIframe.width = '100%';
  2001. emuIframe.height = '0';
  2002. emuIframe.frameBorder = '0';
  2003. emuIframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  2004. emuIframe.addEventListener("load", e=>{
  2005. setTimeout(()=>{
  2006. checkPage();
  2007. },500);
  2008. });
  2009. emuIframe.src=location.href;
  2010. document.body.appendChild(emuIframe);
  2011. }else{
  2012. checkPage();
  2013. }
  2014. }
  2015.  
  2016. function forceIframe(url, callback){
  2017. let curIframe = document.createElement('iframe');
  2018. curIframe.name = 'pagetual-iframe';
  2019. curIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  2020. curIframe.frameBorder = '0';
  2021. curIframe.scrolling="no";
  2022. 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;';
  2023. curIframe.addEventListener("load", e=>{
  2024. let iframeDoc;
  2025. try{
  2026. iframeDoc=curIframe.contentDocument || curIframe.contentWindow.document;
  2027. }catch(e){
  2028. debug("Stop as cors");
  2029. isPause=true;
  2030. callback(false, false);
  2031. return;
  2032. }
  2033. ruleParser.insertPage(iframeDoc, [], url, null, true);
  2034. callback(curIframe, true);
  2035. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  2036. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  2037. setTimeout(()=>{
  2038. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  2039. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  2040. },300);
  2041. });
  2042. curIframe.src=url;
  2043. let insert=ruleParser.getInsert();
  2044. document.body.insertBefore(curIframe, loading);
  2045. return curIframe;
  2046. }
  2047.  
  2048. function nextPage(){
  2049. if(isPause || isLoading)return;
  2050. let nextLink=ruleParser.nextLinkHref;
  2051. if(!nextLink)return;
  2052. let insert=ruleParser.getInsert();
  2053. if(insert){
  2054. let isJs=/^(javascript|#)/.test(nextLink.replace(location.href,""));
  2055. if(location.protocol=="https:" && /^http:/.test(nextLink)){
  2056. nextLink=nextLink.replace(/^http/,"https");
  2057. }
  2058. isLoading=true;
  2059. loading.style.display="";
  2060. if(ruleParser.curSiteRule.pageElementByJs){
  2061. var over=ele=>{
  2062. isLoading=false;
  2063. loading.style.display="none";
  2064. if(ele){
  2065. createPageBar(nextLink);
  2066. ruleParser.insertPage(null, ele, nextLink, null, true);
  2067. }else{
  2068. debug("Stop as no page when get by js");
  2069. isPause=true;
  2070. }
  2071. };
  2072. try{
  2073. Function("over",'"use strict";' + ruleParser.curSiteRule.pageElementByJs)(over);
  2074. }catch(e){
  2075. debug(e);
  2076. }
  2077. }else if(ruleParser.curSiteRule.action==1 && !isJs){
  2078. requestFromIframe(nextLink, (doc, eles)=>{
  2079. isLoading=false;
  2080. loading.style.display="none";
  2081. if(eles){
  2082. createPageBar(nextLink);
  2083. ruleParser.insertPage(doc, eles, nextLink, null, true);
  2084. }
  2085. });
  2086. }else if(forceState==2 && !isJs){
  2087. forceIframe(nextLink, (iframe, eles)=>{
  2088. isLoading=false;
  2089. loading.style.display="none";
  2090. let pageBar=createPageBar(nextLink);
  2091. iframe.parentNode.insertBefore(pageBar, iframe);
  2092. });
  2093. }else{
  2094. if(!isJs){
  2095. requestDoc(nextLink, (eles)=>{
  2096. isLoading=false;
  2097. loading.style.display="none";
  2098. if(eles){
  2099. createPageBar(nextLink);
  2100. }
  2101. });
  2102. }else{
  2103. emuPage((doc, eles)=>{
  2104. isLoading=false;
  2105. loading.style.display="none";
  2106. if(eles){
  2107. createPageBar(nextLink);
  2108. ruleParser.insertPage(doc, eles, "", null, true);
  2109. }
  2110. });
  2111. }
  2112. }
  2113. }
  2114. }
  2115.  
  2116. function init(){
  2117. initRules(()=>{
  2118. initPage();
  2119. });
  2120. }
  2121. setTimeout(()=>{
  2122. init();
  2123. },300);
  2124. })();