东方永页机

最强自动翻页脚本,无需规则自动支持所有网页!

当前为 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.innerText=="§")continue;
  763. if(aTag.style.display=="none")continue;
  764. if(next1 && next2 && next3 && next4)break;
  765. if(!next1){
  766. if(/^\s*[下后後][一1]?[页頁张張]|^next( page)?\s*$|次のページ/i.test(aTag.innerText)){
  767. if(!aTag.href || /^javascript:/.test(aTag.href)){
  768. if(!nextJs1)nextJs1=aTag;
  769. }else{
  770. next1=aTag;
  771. }
  772. }
  773. }
  774. if(!next2){
  775. if(/^\s*[下后後][一1]?[章话話]/i.test(aTag.innerText)){
  776. if(!aTag.href || /^javascript:/.test(aTag.href)){
  777. if(!nextJs2)nextJs2=aTag;
  778. }else{
  779. next2=aTag;
  780. }
  781. }
  782. }
  783. if(!next3){
  784. if(aTag.innerText=="&gt;" || aTag.innerText=="▶" || aTag.innerText=="»"){
  785. if(!aTag.href || /^javascript:/.test(aTag.href)){
  786. if(!nextJs3)nextJs3=aTag;
  787. }else{
  788. next3=aTag;
  789. }
  790. }
  791. }
  792. if(!aTag.href || /^javascript:/.test(aTag.href))continue;
  793. if(!next4){
  794. if(aTag.href.replace("?&","?").replace("#!","").replace(preStr,"").replace(afterStr,"")==parseInt(pageNum)+1){
  795. next4=aTag;
  796. }else if(aTag.href.replace("?&","?").indexOf(url)!=-1 && /^[\/\?&]?[_-]?(p|page)?=?\/?2(\/|\?|&|$)/i.test(aTag.href.replace(url,"").replace(/\.s?html?$/i,""))){
  797. next4=aTag;
  798. }
  799. }
  800. }
  801. next=next1||next3||next4||next2||nextJs1||nextJs3||nextJs2;
  802. }
  803. if(!next)next=jsNext;
  804. return {next:next,canSave:canSave};
  805. }
  806.  
  807. getNextLink(doc) {
  808. let nextLink=null,page;
  809. if(this.curSiteRule.pageElementByJs){
  810. this.nextLinkHref="#";
  811. return true;
  812. }else if(this.curSiteRule.nextLinkByJs){
  813. try{
  814. let targetUrl=Function("doc",'"use strict";' + this.curSiteRule.nextLinkByJs)(doc);
  815. if(targetUrl)nextLink={href:targetUrl};
  816. }catch(e){
  817. debug(e);
  818. }
  819. }else if(this.curSiteRule.nextLinkByUrl){
  820. let targetUrl=this.curUrl.replace(new RegExp(this.curSiteRule.nextLinkByUrl[0]), this.curSiteRule.nextLinkByUrl[1]);
  821. if(targetUrl != this.curUrl){
  822. let reps=targetUrl.match(/{.*?}/g);
  823. if(reps){
  824. reps.forEach(rep=>{
  825. let code=rep.replace("{","").replace("}","");
  826. let result=code.match(/^(\d+)\+1$/);
  827. if(result){
  828. result=parseInt(result[1])+1;
  829. }else{
  830. try{
  831. result=Function('"use strict";return ' + code)();;
  832. }catch(e){
  833. debug(e);
  834. }
  835. }
  836. targetUrl=targetUrl.replace(rep, result);
  837. });
  838. }
  839. }
  840. nextLink={href:targetUrl};
  841. }else if(this.curSiteRule.nextLink){
  842. nextLink=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.nextLink,doc,doc):doc.querySelector(this.curSiteRule.nextLink);
  843. }else{
  844. page=this.getPage(doc);
  845. nextLink=page.next;
  846. if(nextLink && nextLink.classList.contains("noClick")){
  847. self.nextLinkHref=false;
  848. return null;
  849. }else if(nextLink && doc==document){
  850. if((!nextLink.href || /^javascript:/.test(nextLink.href)) && !isVisible(nextLink, _unsafeWindow)){
  851. self.nextLinkHref=false;
  852. return null;
  853. }else{
  854. let nextLinkCs=_unsafeWindow.getComputedStyle(nextLink);
  855. if(nextLinkCs.cursor=="not-allowed"){
  856. self.nextLinkHref=false;
  857. return null;
  858. }
  859. }
  860. }
  861. }
  862. if(nextLink){
  863. if(nextLink.href=="javascript:;" && (this.curSiteRule.action==0 || this.curSiteRule.action==1)){
  864. nextLink=null;
  865. }
  866. /*if(!this.curSiteRule.nextLink && page && page.canSave){
  867. this.curSiteRule.nextLink=this.geneSelector(nextLink);
  868. this.curSiteRule.type=1;
  869. this.saveCurSiteRule();
  870. }*/
  871. }
  872. if(nextLink){
  873. this.nextLinkHref=nextLink.href?nextLink.href:"#";
  874. debug(nextLink);
  875. }else{
  876. this.nextLinkHref=false;
  877. }
  878. return nextLink;
  879. }
  880.  
  881. getInsert(refresh) {
  882. if(this.insert && !refresh){
  883. let parent=this.insert;
  884. while(parent && parent.nodeName!="BODY"){
  885. parent=parent.parentNode;
  886. }
  887. if(parent && parent.nodeName=="BODY"){
  888. return this.insert;
  889. }
  890. }
  891. if(this.curSiteRule.insert){
  892. this.insert=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.insert,document):document.querySelector(this.curSiteRule.insert);
  893. }else{
  894. let pageElement=this.getPageElement(document, _unsafeWindow);
  895. if(pageElement && pageElement.length>0){
  896. var pELast = pageElement[pageElement.length - 1];
  897. this.insert = pELast.nextSibling ? pELast.nextSibling : pELast.parentNode.appendChild(document.createTextNode(' '));
  898. }
  899. }
  900. return this.insert;
  901. }
  902.  
  903. pageAction(doc,eles){
  904. let code=this.curSiteRule.pageAction;
  905. if(code){
  906. try{
  907. Function("doc","eles",'"use strict";' + code)(doc,eles);
  908. }catch(e){
  909. debug(e);
  910. }
  911. }
  912. [].forEach.call(eles, ele=>{
  913. [].forEach.call(ele.querySelectorAll("img"), img=>{
  914. let realSrc;
  915. if(img.dataset && img.dataset.original){
  916. realSrc=img.dataset.original;
  917. }else if(img.dataset && img.dataset.src){
  918. realSrc=img.dataset.src;
  919. }else if(img._lazyrias && img._lazyrias.srcset){
  920. realSrc=img._lazyrias.srcset[img._lazyrias.srcset.length-1];
  921. }else if(img.dataset && img.dataset.origFile){
  922. realSrc=img.dataset.origFile;
  923. }else if(img.srcset){
  924. var srcs=img.srcset.split(","),largeSize=0;
  925. srcs.forEach(srci=>{
  926. let srcInfo=srci.trim().split(" "),curSize=parseInt(srcInfo[1]);
  927. if(srcInfo[1] && curSize>largeSize){
  928. largeSize=curSize;
  929. realSrc=srcInfo[0];
  930. }
  931. });
  932. }
  933. if(realSrc)img.src=realSrc;
  934. });
  935. [].forEach.call(ele.querySelectorAll("a.lazyload"), a=>{
  936. if(a.dataset.original){
  937. a.style.backgroundImage='url("'+a.dataset.original+'")';
  938. }
  939. });
  940. });
  941. let lazyImgSrc=this.curSiteRule.lazyImgSrc;
  942. if(lazyImgSrc){
  943. [].forEach.call(eles, ele=>{
  944. [].forEach.call(ele.querySelectorAll("img"), img=>{
  945. if(img[lazyImgSrc]){
  946. img.src=img[lazyImgSrc];
  947. }
  948. });
  949. });
  950. }
  951. }
  952.  
  953. initPage(callback){
  954. let self=this;
  955. curPage=1;
  956. //if(this.curSiteRule.url && !this.curSiteRule.singleUrl)return;
  957. this.curSiteRule={};
  958. this.pageDoc=document;
  959. this.nextLinkHref=null;
  960. this.curUrl=location.href;
  961. this.getRule(()=>{
  962. if(self.curSiteRule.enable==0){
  963. debug("Stop as rule disable");
  964. isPause=true;
  965. return;
  966. }
  967. if(self.curSiteRule && !self.curSiteRule.singleUrl){
  968. self.hpRules=self.hpRules.filter(item=>{return item&&item.url!=self.curSiteRule.url});
  969. self.hpRules.unshift(self.curSiteRule);
  970. if(self.hpRules.length>30){
  971. self.hpRules.pop();
  972. }
  973. storage.setItem("hpRules", self.hpRules);
  974. }
  975. let css=self.curSiteRule.css;
  976. if(css){
  977. _GM_addStyle(css);
  978. }
  979. let code=self.curSiteRule.init;
  980. if(code){
  981. try{
  982. Function('"use strict";' + code)();
  983. }catch(e){
  984. debug(e);
  985. }
  986. }
  987. self.getNextLink(document);
  988. callback();
  989. });
  990. }
  991.  
  992. insertPage(doc, eles, url, callback, tried){
  993. this.pageDoc=doc;
  994. this.curUrl=url;
  995. let nextLink=this.getNextLink(doc);
  996. if(curPage==1 && !tried && !this.nextLinkHref && this.curSiteRule.singleUrl && this.curSiteRule.pageElement){
  997. this.curSiteRule.action=1;
  998. return false;
  999. }
  1000. if(callback)callback(eles);
  1001. this.getInsert();
  1002. var self=this,newEles=[];
  1003. if(!eles || eles.length==0 || !self.insert || !self.insert.parentNode){
  1004. }else{
  1005. [].forEach.call(eles, ele=>{
  1006. let newEle=ele.cloneNode(true);
  1007. let oldCanvass=ele.querySelectorAll("canvas");
  1008. let newCanvass=newEle.querySelectorAll("canvas");
  1009. for(let i=0;i<oldCanvass.length;i++){
  1010. let oldCanvas=oldCanvass[i];
  1011. let newCanvas=newCanvass[i];
  1012. newCanvas.getContext('2d').drawImage(oldCanvas, 0, 0);
  1013. }
  1014. if(self.curSiteRule.insertPos==2){
  1015. self.insert.appendChild(newEle);
  1016. }else{
  1017. self.insert.parentNode.insertBefore(newEle, self.insert);
  1018. }
  1019. newEles.push(newEle);
  1020. });
  1021. }
  1022. this.pageAction(doc, newEles);
  1023. if(nextLink && nextLink.tagName){
  1024. let nextLinkCs=_unsafeWindow.getComputedStyle(nextLink);
  1025. if(nextLinkCs.cursor=="not-allowed" || !isVisible(nextLink, _unsafeWindow)){
  1026. self.nextLinkHref=false;
  1027. }
  1028. }
  1029. return true;
  1030. }
  1031. }
  1032. var ruleParser = new RuleParser();
  1033.  
  1034. function initConfig(){
  1035. _GM_registerMenuCommand(i18n(forceState==1?"enable":"disableSite"), ()=>{
  1036. storage.setItem("forceState_"+location.host, (forceState==1?0:1));
  1037. location.reload();
  1038. });
  1039.  
  1040. _GM_registerMenuCommand(i18n(forceState==2?"cancelForceIframe":"forceIframe"), ()=>{
  1041. storage.setItem("forceState_"+location.host, (forceState==2?"":2));
  1042. location.reload();
  1043. });
  1044. var configCon,insertPos;
  1045. if(location.href==configPage){
  1046. _GM_addStyle(`
  1047. p>span:nth-child(1),p>span:nth-child(2),p>span:nth-child(3){
  1048. cursor: pointer;
  1049. user-select: none;
  1050. }
  1051. p>span:nth-child(1):hover,p>span:nth-child(2):hover,p>span:nth-child(3):hover{
  1052. color:red;
  1053. }
  1054. .updateDate{
  1055. cursor: pointer;
  1056. user-select: none;
  1057. }
  1058. .updateDate:hover{
  1059. color:red;
  1060. }
  1061. `);
  1062. configCon=document.querySelector(".markdown-body");
  1063. insertPos=configCon.querySelector("hr");
  1064. }else if(location.href==configPage){
  1065. }else return false;
  1066. class Rulebar {
  1067. init(ruleUrl){
  1068. this.ruleUrl=ruleUrl;
  1069. this.item=document.createElement("p");
  1070. this.item.title=ruleUrl.type==0?"AutoPagerize Rules":"Pagetual Rules";
  1071. this.item.dataset.id=this.ruleUrl.id;
  1072. let url=document.createElement("span");
  1073. url.innerHTML=ruleUrl.url;
  1074. let up=document.createElement("span");
  1075. up.innerHTML="↑ ";
  1076. up.title=i18n("sortTitle");
  1077. let down=document.createElement("span");
  1078. down.innerHTML="↓ ";
  1079. down.title=i18n("sortTitle");
  1080. let del=document.createElement("span");
  1081. del.innerHTML="× ";
  1082. up.onclick=e=>{
  1083. this.moveUp();
  1084. };
  1085. down.onclick=e=>{
  1086. this.moveDown();
  1087. };
  1088. del.onclick=e=>{
  1089. this.del();
  1090. };
  1091. this.item.appendChild(up);
  1092. this.item.appendChild(down);
  1093. this.item.appendChild(del);
  1094. this.item.appendChild(url);
  1095. configCon.insertBefore(this.item, insertPos);
  1096. }
  1097. saveSort(){
  1098. let sort=[];
  1099. [].forEach.call(this.item.parentNode.querySelectorAll("p[data-id]"), i=>{
  1100. sort.push(i.dataset.id);
  1101. });
  1102. rulesData.sort=sort;
  1103. storage.setItem("rulesData", rulesData);
  1104. }
  1105. moveUp(){
  1106. let preE=this.item.previousElementSibling;
  1107. if(preE.tagName=="P" && preE.children.length>1){
  1108. this.item.parentNode.insertBefore(this.item,preE);
  1109. this.saveSort();
  1110. }
  1111. }
  1112. moveDown(){
  1113. let nextE=this.item.nextElementSibling;
  1114. if(nextE.tagName=="P" && nextE.children.length>1){
  1115. this.item.parentNode.insertBefore(nextE,this.item);
  1116. this.saveSort();
  1117. }
  1118. }
  1119. del(){
  1120. if(this.ruleUrl.id<2){
  1121. alert(i18n("cantDel"));
  1122. }else if(window.confirm(i18n("confirmDel"))){
  1123. for(let u=0;u<rulesData.urls.length;u++){
  1124. if(this.ruleUrl.id==rulesData.urls[u].id){
  1125. rulesData.urls.splice(u,1);
  1126. break;
  1127. }
  1128. }
  1129. for(let u=0;u<rulesData.sort.length;u++){
  1130. if(this.ruleUrl.id==rulesData.sort[u]){
  1131. rulesData.sort.splice(u,1);
  1132. break;
  1133. }
  1134. }
  1135. storage.setItem("rulesData", rulesData);
  1136. ruleParser.rules=ruleParser.rules.filter(item=>{return item.from!=this.ruleUrl.id});
  1137. storage.setItem("rules", ruleParser.rules);
  1138. this.item.parentNode.removeChild(this.item);
  1139. //location.reload();
  1140. }
  1141. }
  1142. }
  1143. let updateP=document.createElement("p"),i=0;
  1144. let now=new Date().getTime(),inUpdate=false;
  1145.  
  1146.  
  1147. let pastDate=(new Date(updateDate)).toString(),passStr;
  1148. let passTime=(now-updateDate)/1000;
  1149. if(passTime<60){
  1150. passStr=i18n("passSec", passTime);
  1151. }else if(passTime<60*60){
  1152. passStr=i18n("passMin", parseInt(passTime/60));
  1153. }else if(passTime<60*60*24){
  1154. passStr=i18n("passHour", parseInt(passTime/3600));
  1155. }else{
  1156. passStr=i18n("passDay", parseInt(passTime/86400));
  1157. }
  1158.  
  1159.  
  1160. updateP.className="updateDate";
  1161. updateP.innerHTML=passStr;
  1162. updateP.title=i18n("update")+" - "+pastDate;
  1163. updateP.onclick=e=>{
  1164. if(inUpdate)return;
  1165. inUpdate=true;
  1166. let ruleIndex=0;
  1167. storage.setItem("hpRules", []);
  1168. function addNextRule(){
  1169. if(ruleIndex>=ruleUrls.length){
  1170. storage.setItem("ruleLastUpdate", now);
  1171. alert(i18n("updateSucc"));
  1172. inUpdate=false;
  1173. updateP.innerHTML=i18n("passSec", 0);
  1174. updateP.title=i18n("update");
  1175. }else{
  1176. let rule=ruleUrls[ruleIndex++];
  1177. ruleParser.addRuleByUrl(rule.url, rule.type, rule.id, ()=>{
  1178. addNextRule();
  1179. })
  1180. }
  1181. }
  1182. addNextRule();
  1183. alert(i18n("beginUpdate"));
  1184. };
  1185. configCon.insertBefore(updateP, insertPos);
  1186. if(ruleUrls){
  1187. ruleUrls.forEach(ruleUrl=>{
  1188. var rulebar=new Rulebar();
  1189. rulebar.init(ruleUrl);
  1190. });
  1191. }
  1192. let customUrlsTitle=document.createElement("h2");
  1193. customUrlsTitle.innerHTML=i18n("customUrls");
  1194. configCon.insertBefore(customUrlsTitle, insertPos);
  1195. let customUrlsInput=document.createElement("textarea");
  1196. customUrlsInput.style.width="100%";
  1197. customUrlsInput.placeholder="0|http://wedata.net/databases/AutoPagerize/items_all.json";
  1198. configCon.insertBefore(customUrlsInput, insertPos);
  1199.  
  1200. let opacityTitle=document.createElement("h2");
  1201. opacityTitle.innerHTML=i18n("opacity");
  1202. let opacityInput=document.createElement("input");
  1203. opacityInput.value=rulesData.opacity*100;
  1204. opacityInput.type="number";
  1205. opacityInput.style.width="50px";
  1206. opacityInput.style.margin="0 0 0 10px";
  1207. opacityTitle.appendChild(opacityInput);
  1208. configCon.insertBefore(opacityTitle, insertPos);
  1209.  
  1210.  
  1211. let hideBarTitle=document.createElement("h2");
  1212. hideBarTitle.innerHTML=i18n("hideBar");
  1213. let hideBarInput=document.createElement("input");
  1214. hideBarInput.type="checkbox";
  1215. hideBarInput.style.width="50px";
  1216. hideBarInput.style.height="20px";
  1217. hideBarInput.checked=rulesData.hideBar;
  1218. hideBarTitle.appendChild(hideBarInput);
  1219. configCon.insertBefore(hideBarTitle, insertPos);
  1220.  
  1221. let dbClick2StopTitle=document.createElement("h2");
  1222. dbClick2StopTitle.innerHTML=i18n("dbClick2Stop");
  1223. let dbClick2StopInput=document.createElement("input");
  1224. dbClick2StopInput.type="checkbox";
  1225. dbClick2StopInput.style.width="50px";
  1226. dbClick2StopInput.style.height="20px";
  1227. dbClick2StopInput.checked=rulesData.dbClick2Stop;
  1228. dbClick2StopTitle.appendChild(dbClick2StopInput);
  1229. configCon.insertBefore(dbClick2StopTitle, insertPos);
  1230.  
  1231. let enableWhiteListTitle=document.createElement("h2");
  1232. enableWhiteListTitle.innerHTML=i18n("autoRun");
  1233. let enableWhiteListInput=document.createElement("input");
  1234. enableWhiteListInput.type="checkbox";
  1235. enableWhiteListInput.style.width="50px";
  1236. enableWhiteListInput.style.height="20px";
  1237. enableWhiteListInput.checked=rulesData.enableWhiteList!=true;
  1238. enableWhiteListTitle.appendChild(enableWhiteListInput);
  1239. configCon.insertBefore(enableWhiteListTitle, insertPos);
  1240.  
  1241. let customRulesTitle=document.createElement("h2");
  1242. customRulesTitle.innerHTML=i18n("customRules")
  1243. configCon.insertBefore(customRulesTitle, insertPos);
  1244. let customRulesInput=document.createElement("textarea");
  1245. customRulesInput.style.width="100%";
  1246. customRulesInput.style.height="500px";
  1247. 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]`;
  1248. customRulesInput.value=getFormatJSON(ruleParser.customRules);
  1249. configCon.insertBefore(customRulesInput, insertPos);
  1250. let saveBtn=document.createElement("button");
  1251. saveBtn.innerHTML=i18n("save");
  1252. saveBtn.style.width="100%";
  1253. configCon.insertBefore(saveBtn, insertPos);
  1254. saveBtn.onclick=e=>{
  1255. try{
  1256. storage.setItem("hpRules", []);
  1257. if(customRulesInput.value==""){
  1258. storage.setItem("customRules", "");
  1259. }else{
  1260. let customRules=JSON.parse(customRulesInput.value);
  1261. if(Array && Array.isArray && !Array.isArray(customRules)){
  1262. alert("Rules must be a Array!");
  1263. return;
  1264. }
  1265. debug(customRules);
  1266. storage.setItem("customRules", customRules);
  1267. }
  1268. }catch(e){
  1269. debug(e);
  1270. alert("JSON error, check again!");
  1271. return;
  1272. }
  1273. rulesData.opacity=opacityInput.value/100;
  1274. rulesData.hideBar=hideBarInput.checked;
  1275. rulesData.dbClick2Stop=dbClick2StopInput.checked;
  1276. rulesData.enableWhiteList=!enableWhiteListInput.checked;
  1277. storage.setItem("rulesData", rulesData);
  1278. let customUrls=customUrlsInput.value.trim();
  1279. if(customUrls){
  1280. customUrls=customUrls.split(/\n/);
  1281. for(let c=0;c<customUrls.length;c++){
  1282. let urlArr=customUrls[c].split("|"),url,type=1;
  1283. if(urlArr.length==1){
  1284. url=urlArr[0].trim();
  1285. if(!/^http/.test(url)){
  1286. alert("Wrong url, check again!");
  1287. return;
  1288. }
  1289. }else if(urlArr.length==2){
  1290. type=urlArr[0].trim();
  1291. url=urlArr[1].trim();
  1292. if(!/^http/.test(url)){
  1293. alert("Wrong url, check again!");
  1294. return;
  1295. }
  1296. }else{
  1297. break;
  1298. }
  1299. let maxId=0,hasUrl=false;;
  1300. if(!rulesData.urls){
  1301. rulesData.urls=[];
  1302. maxId=1;
  1303. }else{
  1304. rulesData.urls.forEach(u=>{
  1305. if(maxId<u.id){
  1306. maxId=u.id;
  1307. }
  1308. if(u.url==url){
  1309. hasUrl=true;
  1310. }
  1311. });
  1312. if(hasUrl)break;
  1313. }
  1314. rulesData.urls.push({id:maxId+1,url:url,type:type});
  1315. rulesData.sort.push(maxId+1);
  1316. storage.setItem("rulesData", rulesData);
  1317. }
  1318. }
  1319. alert("Modified successfully");
  1320. location.reload();
  1321. };
  1322. return true;
  1323. }
  1324.  
  1325. function objIsArr(obj) {
  1326. return obj &&
  1327. typeof obj === 'object' &&
  1328. typeof obj.length === 'number' &&
  1329. !(obj.propertyIsEnumerable('length'));
  1330. }
  1331.  
  1332. function isVisible(el, win) {
  1333. var loopable = true,
  1334. visible = win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  1335. while(loopable && visible) {
  1336. el = el.parentNode;
  1337.  
  1338. if(el && el.tagName!="BODY") {
  1339. visible = win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  1340. }else {
  1341. loopable = false;
  1342. }
  1343. }
  1344. return visible;
  1345. }
  1346.  
  1347. function getFormatJSON(obj){
  1348. if(!objIsArr(obj))return "";
  1349. let ret="[\n";
  1350. let len=obj.length,i=0,isLast;
  1351. obj.forEach(item=>{
  1352. ret+=" {\n";
  1353. let iLen=Object.keys(item).length,j=0;
  1354. for(let key in item){
  1355. isLast=(++j)==iLen;
  1356. let value=item[key];
  1357. if(objIsArr(value)){
  1358. let vstr="[",v=0,vIsLast=false;
  1359. value.forEach(vi=>{
  1360. vIsLast=(++v)==value.length;
  1361. vstr+="\""+vi.replace(/\\/g,"\\\\")+"\""+(vIsLast?"":",");
  1362. });
  1363. vstr+="]";
  1364. ret+=" \""+key+"\":"+vstr+""+(isLast?"":",")+"\n";
  1365. }else{
  1366. if(typeof value=="string"){
  1367. value=value.replace(/\\/g,"\\\\").replace(/"/g,"\\\"");
  1368. value="\""+value+"\"";
  1369. }
  1370. ret+=" \""+key+"\":"+value+""+(isLast?"":",")+"\n";
  1371. }
  1372. }
  1373. isLast=(++i)==len;
  1374. ret+=" }"+(isLast?"":",")+"\n";
  1375. });
  1376. ret+="]";
  1377. return ret;
  1378. }
  1379.  
  1380. function initRules(callback) {
  1381. /*0 wedata格式,1 pagetual格式*/
  1382. ruleUrls=[
  1383. {
  1384. id:0,
  1385. url:'https://raw.githubusercontent.com/hoothin/UserScripts/master/Pagetual/pagetualRules.json',
  1386. type:1
  1387. },
  1388. {
  1389. id:1,
  1390. url:'http://wedata.net/databases/AutoPagerize/items_all.json',
  1391. type:0,
  1392. }
  1393. ];var i=0,j=0;
  1394.  
  1395. ruleParser.initSavedRules(()=>{
  1396. storage.getItem("rulesData", data=>{
  1397. if(data){
  1398. rulesData=data;
  1399. if(data.urls)ruleUrls=ruleUrls.concat(data.urls);
  1400. if(data.sort){
  1401. let urls=[];
  1402. data.sort.forEach(id=>{
  1403. for(let s=0;s<ruleUrls.length;s++){
  1404. if(id==ruleUrls[s].id){
  1405. urls.push(ruleUrls[s]);
  1406. break;
  1407. }
  1408. }
  1409. });
  1410. ruleUrls=urls;
  1411. }
  1412. }
  1413. if(typeof(rulesData.opacity)=="undefined"){
  1414. rulesData.opacity=0.3;
  1415. }
  1416. if(typeof(rulesData.hideBar)=="undefined"){
  1417. rulesData.hideBar=true;
  1418. }
  1419. if(typeof(rulesData.dbClick2Stop)=="undefined"){
  1420. rulesData.dbClick2Stop=true;
  1421. }
  1422. if(typeof(rulesData.enableWhiteList)=="undefined"){
  1423. rulesData.enableWhiteList=false;
  1424. }
  1425. storage.getItem("forceState_"+location.host, v=>{
  1426. storage.getItem("ruleLastUpdate", date=>{
  1427. if(typeof(v)=="undefined"){
  1428. v=(rulesData.enableWhiteList?1:0);
  1429. }
  1430. forceState=v;
  1431. updateDate=date;
  1432. if(initConfig())return;
  1433. if(forceState==1)return;
  1434. let now=new Date().getTime();
  1435. if(!date || now-date>2*24*60*60*1000){
  1436. storage.setItem("ruleLastUpdate", now);
  1437. storage.setItem("hpRules", []);
  1438. let ruleIndex=0;
  1439. function addNextRule(){
  1440. if(ruleIndex>=ruleUrls.length){
  1441. callback();
  1442. }else{
  1443. let rule=ruleUrls[ruleIndex++];
  1444. ruleParser.addRuleByUrl(rule.url, rule.type, rule.id, ()=>{
  1445. addNextRule();
  1446. })
  1447. }
  1448. }
  1449. addNextRule();
  1450. }else{
  1451. callback();
  1452. }
  1453. });
  1454. });
  1455. });
  1456. });
  1457. }
  1458.  
  1459. function requestDoc(url, callback){
  1460. _GM_xmlhttpRequest({
  1461. url: url,
  1462. method: 'GET',
  1463. overrideMimeType: 'text/html;charset='+document.charset,
  1464. headers: {
  1465. 'Referer': location.href
  1466. },
  1467. timeout: 5000,
  1468. onload: function(res) {
  1469. var doc=null;
  1470. try {
  1471. doc=document.implementation.createHTMLDocument('');
  1472. doc.documentElement.innerHTML=res.response;
  1473. }
  1474. catch (e) {
  1475. debug('parse error'+e.toString());
  1476. }
  1477. let pageElement=ruleParser.getPageElement(doc);
  1478. //只有1的話怕不是圖片哦
  1479. if(pageElement && (pageElement.length>1 || (pageElement.length==1 && pageElement[0].tagName!="IMG") )){
  1480. let result=ruleParser.insertPage(doc, pageElement, url, callback, false);
  1481. if(!result){
  1482. requestFromIframe(url, (doc, eles)=>{
  1483. if(eles){
  1484. ruleParser.insertPage(doc, eles, url, callback, true);
  1485. }
  1486. });
  1487. }
  1488. }else if(ruleParser.curSiteRule.singleUrl){
  1489. requestFromIframe(url, (doc, eles)=>{
  1490. if(eles){
  1491. ruleParser.insertPage(doc, eles, url, callback, true);
  1492. }
  1493. });
  1494. }
  1495. },
  1496. onerror: function(e){
  1497. debug(e);
  1498. callback(false);
  1499. }
  1500. });
  1501. }
  1502.  
  1503. var failFromIframe=0;
  1504. function requestFromIframe(url, callback){
  1505. let orgPage,curPage;
  1506. let iframe = document.createElement('iframe');
  1507. iframe.name = 'pagetual-iframe';
  1508. iframe.width = '100%';
  1509. iframe.height = '0';
  1510. iframe.frameBorder = '0';
  1511. if(ruleParser.curSiteRule.sandbox){
  1512. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1513. }
  1514. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1515. iframe.addEventListener("load", e=>{
  1516. let waitTime=500,checkEval;
  1517. if(ruleParser.curSiteRule.wait){
  1518. if(isNaN(ruleParser.curSiteRule.wait)){
  1519. try{
  1520. checkEval=Function("doc",'"use strict";' + ruleParser.curSiteRule.wait);
  1521. }catch(e){
  1522. debug(e);
  1523. }
  1524. }else{
  1525. waitTime=ruleParser.curSiteRule.wait;
  1526. }
  1527. }
  1528. setTimeout(()=>{
  1529. let tryTimes=0;
  1530. function checkIframe(){
  1531. try{
  1532. let doc=iframe.contentDocument || iframe.contentWindow.document;
  1533. let eles=ruleParser.getPageElement(doc, iframe.contentWindow);
  1534. if(eles && eles.length>0 && (!checkEval || checkEval(doc))){
  1535. callback(doc, eles);
  1536. }else if(tryTimes++ < 10){
  1537. setTimeout(()=>{
  1538. checkIframe();
  1539. },waitTime);
  1540. return;
  1541. }else{
  1542. if(failFromIframe++ > 2){
  1543. failFromIframe=0;
  1544. debug("Stop as failFromIframe");
  1545. isPause=true;
  1546. callback(false, false);
  1547. }else{
  1548. callback(false, false);
  1549. }
  1550. }
  1551. }catch(e){
  1552. debug("Stop as cors");
  1553. isPause=true;
  1554. callback(false, false);
  1555. }
  1556. document.body.removeChild(iframe);
  1557. }
  1558. checkIframe();
  1559. },waitTime);
  1560. });
  1561. iframe.src=url;
  1562. document.body.appendChild(iframe);
  1563. }
  1564.  
  1565. function initPage(){
  1566. ruleParser.initPage(()=>{
  1567. if(ruleParser.nextLinkHref)initView();
  1568. initListener();
  1569. nextPage();
  1570. });
  1571. }
  1572.  
  1573. function initView(){
  1574. _GM_addStyle(`
  1575. .pagetual_pageBar.stop {
  1576. -webkit-filter: invert(100%);
  1577. filter: invert(100%);
  1578. opacity: 1!important;
  1579. }
  1580. .pagetual_pageBar.hide {
  1581. display: none!important;
  1582. }
  1583. .pagetual_pageBar:hover {
  1584. opacity: 1!important;
  1585. }
  1586. .pagetual_pageBar span {
  1587. vertical-align: super;
  1588. }
  1589.  
  1590. .pagetual_pageBar span>svg:hover {
  1591. animation: touhouAni 1s infinite;
  1592. }
  1593.  
  1594. @keyframes touhouAni{
  1595. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  1596. to {transform: rotate(360deg);}
  1597. }
  1598. @-webkit-keyframes touhouAni{
  1599. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  1600. to {transform: rotate(360deg);}
  1601. }
  1602. `);
  1603. 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;`;
  1604. }
  1605. var loading=document.createElement("div");
  1606. loading.className="pagetual_loading";
  1607. 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;";
  1608. 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>`;
  1609. document.body.appendChild(loading);
  1610.  
  1611. 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>`;
  1612. 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>`;
  1613. var pageBarStyle;
  1614. 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;`;
  1615. 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);`;
  1616.  
  1617. var isPause=false,isLoading=false,curPage=1,forceState=0,bottomGap=1000;
  1618.  
  1619. function changeStop(stop, hide){
  1620. isPause=stop;
  1621. [].forEach.call(document.querySelectorAll(".pagetual_pageBar"), bar=>{
  1622. if(isPause){
  1623. bar.classList.add("stop");
  1624. if(hide)bar.classList.add("hide");
  1625. }else{
  1626. bar.classList.remove("stop");
  1627. if(hide)bar.classList.remove("hide");
  1628. }
  1629. });
  1630. }
  1631.  
  1632. function isInViewPort(element) {
  1633. if(!element.parentNode)return false;
  1634. if(_unsafeWindow.getComputedStyle(element).display=="none")return false;
  1635. const viewWidth = window.innerWidth || document.documentElement.clientWidth;
  1636. const viewHeight = window.innerHeight || document.documentElement.clientHeight;
  1637. const {
  1638. top,
  1639. right,
  1640. bottom,
  1641. left,
  1642. } = element.getBoundingClientRect();
  1643.  
  1644. return (
  1645. top >= 0 &&
  1646. left >= 0 &&
  1647. right <= viewWidth &&
  1648. bottom <= viewHeight
  1649. );
  1650. }
  1651.  
  1652. var urlChanged=false;
  1653. var _wr = function(type) {
  1654. var orig = history[type];
  1655. return function() {
  1656. var rv = orig.apply(this, arguments);
  1657. var e = new Event(type);
  1658. e.arguments = arguments;
  1659. window.dispatchEvent(e);
  1660. return rv;
  1661. };
  1662. };
  1663. history.pushState = _wr('pushState');
  1664. window.addEventListener('pushState', function(e) {
  1665. urlChanged=true;
  1666. setTimeout(()=>{
  1667. if(location.href==configPage){
  1668. location.reload();
  1669. }
  1670. },1);
  1671. });
  1672.  
  1673. function initListener(){
  1674. let loadmoreBtn,loading=true;
  1675. setTimeout(()=>{
  1676. loadmoreBtn=getLoadMore(document);
  1677. if(loadmoreBtn){
  1678. loading=false;
  1679. }
  1680. },300);
  1681. document.addEventListener('scroll', e=>{
  1682. if(urlChanged){
  1683. ruleParser.initPage(()=>{
  1684. if(ruleParser.nextLinkHref)initView();
  1685. });
  1686. urlChanged=false;
  1687. isPause=false;
  1688. }
  1689. if(!loading && !isPause){
  1690. loading=true;
  1691. if(!loadmoreBtn || !loadmoreBtn.parentNode){
  1692. loadmoreBtn=getLoadMore(document);
  1693. }
  1694. if(loadmoreBtn){
  1695. loading=false;
  1696. if(isInViewPort(loadmoreBtn)){
  1697. emuClick(loadmoreBtn);
  1698. }
  1699. }else{
  1700. setTimeout(()=>{loading=false},500);
  1701. }
  1702. }
  1703. setTimeout(()=>{
  1704. if(!isPause && !isLoading){
  1705. let scrolly=window.scrollY;
  1706. let windowHeight=window.innerHeight;
  1707. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  1708. if(scrollH-scrolly-windowHeight<bottomGap){
  1709. nextPage();
  1710. }
  1711. }
  1712. },100);
  1713. }, true);
  1714. document.addEventListener('dblclick', e=>{
  1715. if(rulesData.dbClick2Stop){
  1716. setTimeout(()=>{
  1717. changeStop(!isPause, rulesData.hideBar);
  1718. if(!isPause){
  1719. let scrolly=window.scrollY;
  1720. let windowHeight=window.innerHeight;
  1721. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  1722. if(scrollH-scrolly-windowHeight<bottomGap){
  1723. nextPage();
  1724. }
  1725. }
  1726. },200);
  1727. }
  1728. });
  1729. }
  1730.  
  1731. function getLoadMore(doc){
  1732. let btnSel=ruleParser.curSiteRule.loadMore||".LoadMore,.load-more";
  1733. let loadmoreBtn=doc.querySelector(btnSel);
  1734. if(!loadmoreBtn){
  1735. let buttons=doc.querySelectorAll("input,button,a,div[onclick]"),loadmoreReg=/^\s*(加载更多|加載更多|load\s*more|もっと読み込む)\s*$/i;
  1736. for(let i=0;i<buttons.length;i++){
  1737. let button=buttons[i];
  1738. if(button && loadmoreReg.test(button.innerText)){
  1739. loadmoreBtn=button;
  1740. break;
  1741. }
  1742. }
  1743. }
  1744. return loadmoreBtn;
  1745. }
  1746.  
  1747. function createPageBar(url){
  1748. let insert=ruleParser.getInsert();
  1749. if(!insert || !insert.parentNode)return;
  1750. curPage++;
  1751. let inTable=insert.tagName=="TR" ||
  1752. (insert.previousElementSibling && insert.previousElementSibling.tagName=="TR") ||
  1753. insert.tagName=="TBODY" || (insert.previousElementSibling && insert.previousElementSibling.tagName=="TBODY");
  1754. let inLi=insert.tagName=="LI" || (insert.previousElementSibling && insert.previousElementSibling.tagName=="LI");
  1755. let pageBar=document.createElement(inTable?"tr":"div");
  1756. let upSpan=document.createElement("span");
  1757. let downSpan=document.createElement("span");
  1758. let pageText=document.createElement("a");
  1759. pageBar.className="pagetual_pageBar";
  1760. pageBar.id="pagetual_pageBar";
  1761. if(isPause){
  1762. pageBar.classList.add("stop");
  1763. }
  1764. pageBar.style.cssText=pageBarStyle;
  1765. pageBar.title=i18n(isPause?"enable":"disable");
  1766. upSpan.innerHTML=upSvg;
  1767. upSpan.title=i18n("toTop");
  1768. downSpan.innerHTML=downSvg;
  1769. downSpan.title=i18n("toBottom");
  1770. upSpan.style.cssText=initStyle;
  1771. downSpan.style.cssText=initStyle;
  1772. pageText.href=url;
  1773. pageText.style=pageTextStyle;
  1774. pageText.innerHTML="Page "+curPage;
  1775. pageText.title=i18n("current");
  1776. pageBar.appendChild(upSpan);
  1777. pageBar.appendChild(pageText);
  1778. pageBar.appendChild(downSpan);
  1779. if(inTable){
  1780. let example=(insert.tagName=="TR" || insert.tagName=="TBODY")?insert:insert.previousElementSibling;
  1781. let tdNum=0;
  1782. [].forEach.call(example.querySelectorAll("td,th"), td=>{
  1783. tdNum+=td.colSpan||1;
  1784. });
  1785. pageBar.style.display="table-row";
  1786. pageBar.style.backgroundColor="unset";
  1787. let td=document.createElement("td");
  1788. td.style.backgroundColor="rgb(240 240 240 / 80%)";
  1789. td.style.borderRadius="20px";
  1790. td.colSpan=tdNum||1;
  1791. td.style.padding="0 0";
  1792. td.style.textAlign="center";
  1793. td.appendChild(upSpan);
  1794. td.appendChild(pageText);
  1795. td.appendChild(downSpan);
  1796. pageBar.appendChild(td);
  1797. }
  1798.  
  1799. upSpan.addEventListener("click", e=>{
  1800. //changeStop(true);
  1801. //pageBar.title=i18n(isPause?"enable":"disable");
  1802. document.body.scrollTop=0;
  1803. document.documentElement.scrollTop=0;
  1804. e.preventDefault();
  1805. e.stopPropagation();
  1806. });
  1807. downSpan.addEventListener("click", e=>{
  1808. changeStop(true);
  1809. pageBar.title=i18n(isPause?"enable":"disable");
  1810. document.body.scrollTop=9999999;
  1811. document.documentElement.scrollTop=9999999;
  1812. e.preventDefault();
  1813. e.stopPropagation();
  1814. });
  1815. pageBar.addEventListener("click", e=>{
  1816. changeStop(!isPause);
  1817. pageBar.title=i18n(isPause?"enable":"disable");
  1818. });
  1819. pageText.addEventListener("click", e=>{
  1820. e.stopPropagation();
  1821. });
  1822. let parentStyle=_unsafeWindow.getComputedStyle(insert.parentNode);
  1823. pageBar.style.width=parseInt(parentStyle.width)*.99-parseInt(parentStyle.paddingLeft)-parseInt(parentStyle.paddingRight)+"px";
  1824. if(inLi){
  1825. pageBar.style.width="90%";
  1826. pageBar.style.minWidth="150px";
  1827. pageBar.style.display="inline-block";
  1828. let line=document.createElement("li");
  1829. line.style.textAlign="center";
  1830. line.appendChild(pageBar);
  1831. if(ruleParser.curSiteRule.insertPos==2){
  1832. insert.appendChild(line);
  1833. }else{
  1834. insert.parentNode.insertBefore(line, insert);
  1835. }
  1836. }else{
  1837. if(ruleParser.curSiteRule.insertPos==2){
  1838. insert.appendChild(pageBar);
  1839. }else{
  1840. insert.parentNode.insertBefore(pageBar, insert);
  1841. }
  1842. }
  1843.  
  1844. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  1845. let actualTop = pageBar.offsetTop;
  1846. let current = pageBar.parentNode.offsetParent;
  1847. while (current !== null){
  1848. actualTop += current.offsetTop;
  1849. current = current.offsetParent;
  1850. }
  1851. bottomGap=scrollH-actualTop+800;
  1852. return pageBar;
  1853. }
  1854.  
  1855. function emuClick(btn){
  1856. if(!PointerEvent)return btn.click();
  1857. let eventParam={
  1858. isTrusted: true,
  1859. altKey: false,
  1860. azimuthAngle: 0,
  1861. bubbles: true,
  1862. button: 0,
  1863. buttons: 0,
  1864. clientX: 1,
  1865. clientY: 1,
  1866. cancelBubble: false,
  1867. cancelable: true,
  1868. composed: true,
  1869. ctrlKey: false,
  1870. defaultPrevented: false,
  1871. detail: 1,
  1872. eventPhase: 2,
  1873. fromElement: null,
  1874. height: 1,
  1875. isPrimary: false,
  1876. metaKey: false,
  1877. pointerId: 1,
  1878. pointerType: "mouse",
  1879. pressure: 0,
  1880. relatedTarget: null,
  1881. returnValue: true,
  1882. shiftKey: false,
  1883. toElement: null,
  1884. twist: 0,
  1885. type: "click",
  1886. which: 1
  1887. };
  1888. var mouseclick = new PointerEvent("click",eventParam);
  1889. btn.dispatchEvent(mouseclick);
  1890. }
  1891.  
  1892. var emuIframe;
  1893. function emuPage(callback){
  1894. let orgPage,curPage,iframeDoc,times=0,loadmoreBtn,loadmoreEnd=false,waitTimes=10;
  1895. function checkPage(){
  1896. if(isPause)return;
  1897. try{
  1898. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  1899. }catch(e){
  1900. debug("Stop as cors");
  1901. isPause=true;
  1902. callback(false, false);
  1903. return;
  1904. }
  1905.  
  1906. let nextLink=ruleParser.getNextLink(iframeDoc);
  1907. let waitTime=500,checkEval;
  1908. if(ruleParser.curSiteRule.wait){
  1909. if(isNaN(ruleParser.curSiteRule.wait)){
  1910. try{
  1911. checkEval=Function("doc",'"use strict";' + ruleParser.curSiteRule.wait);
  1912. }catch(e){
  1913. debug(e);
  1914. }
  1915. }else{
  1916. waitTime=ruleParser.curSiteRule.wait;
  1917. }
  1918. }
  1919.  
  1920. if(!orgPage){
  1921. if(!loadmoreEnd){
  1922. loadmoreBtn=getLoadMore(iframeDoc);
  1923. if(loadmoreBtn){
  1924. emuClick(loadmoreBtn);
  1925. let intv=setInterval(()=>{
  1926. loadmoreBtn=getLoadMore(iframeDoc);
  1927. if(!loadmoreBtn || !loadmoreBtn.parentNode || !isVisible(loadmoreBtn, iframeDoc.defaultView)){
  1928. clearInterval(intv);
  1929. loadmoreEnd=true;
  1930. setTimeout(()=>{
  1931. checkPage();
  1932. },500);
  1933. }else{
  1934. emuClick(loadmoreBtn);
  1935. }
  1936. },200);
  1937. return;
  1938. }else{
  1939. loadmoreEnd=true;
  1940. }
  1941. }
  1942. let pageEle=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true);
  1943. if(!nextLink || !pageEle || (checkEval && !checkEval(iframeDoc))){
  1944. if(ruleParser.curSiteRule.wait && waitTimes-->0){
  1945. setTimeout(()=>{
  1946. checkPage();
  1947. },waitTime);
  1948. return;
  1949. }
  1950. }
  1951. orgPage=pageEle;
  1952. if(!orgPage || orgPage.length==0){
  1953. debug("Stop as no page when emu");
  1954. isPause=true;
  1955. callback(false, false);
  1956. return;
  1957. }
  1958. if(orgPage && orgPage[0].tagName=="UL")orgPage=orgPage[0].children;
  1959. if(orgPage && nextLink){
  1960. orgPage=orgPage[parseInt(orgPage.length/2)];
  1961. if(!isVisible(nextLink, iframeDoc.defaultView)){
  1962. debug("Stop as next hide when emu");
  1963. isPause=true;
  1964. callback(false, false);
  1965. }else{
  1966. emuClick(nextLink);
  1967. setTimeout(()=>{
  1968. checkPage();
  1969. },500);
  1970. }
  1971. }else{
  1972. debug("Stop as no next when emu");
  1973. isPause=true;
  1974. callback(false, false);
  1975. }
  1976. return;
  1977. }
  1978. if(times++ > 20){
  1979. //emuClick(nextLink);
  1980. debug("Stop as timeout when emu");
  1981. isPause=true;
  1982. callback(false, false);
  1983. return;
  1984. }
  1985. let eles=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true),checkItem=eles;
  1986. if(eles && eles[0].tagName=="UL")checkItem=eles[0].children;
  1987. if(!eles || eles.length==0 || orgPage == checkItem[parseInt(checkItem.length/2)] || (checkEval && !checkEval(iframeDoc))){
  1988. setTimeout(()=>{
  1989. checkPage();
  1990. },waitTime);
  1991. }else{
  1992. callback(iframeDoc, eles);
  1993. }
  1994. }
  1995. if(!emuIframe){
  1996. emuIframe = document.createElement('iframe');
  1997. emuIframe.name = 'pagetual-iframe';
  1998. if(ruleParser.curSiteRule.sandbox){
  1999. emuIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  2000. }
  2001. emuIframe.width = '100%';
  2002. emuIframe.height = '0';
  2003. emuIframe.frameBorder = '0';
  2004. emuIframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  2005. emuIframe.addEventListener("load", e=>{
  2006. setTimeout(()=>{
  2007. checkPage();
  2008. },500);
  2009. });
  2010. emuIframe.src=location.href;
  2011. document.body.appendChild(emuIframe);
  2012. }else{
  2013. checkPage();
  2014. }
  2015. }
  2016.  
  2017. function forceIframe(url, callback){
  2018. let curIframe = document.createElement('iframe');
  2019. curIframe.name = 'pagetual-iframe';
  2020. curIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  2021. curIframe.frameBorder = '0';
  2022. curIframe.scrolling="no";
  2023. 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;';
  2024. curIframe.addEventListener("load", e=>{
  2025. let iframeDoc;
  2026. try{
  2027. iframeDoc=curIframe.contentDocument || curIframe.contentWindow.document;
  2028. }catch(e){
  2029. debug("Stop as cors");
  2030. isPause=true;
  2031. callback(false, false);
  2032. return;
  2033. }
  2034. ruleParser.insertPage(iframeDoc, [], url, null, true);
  2035. callback(curIframe, true);
  2036. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  2037. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  2038. setTimeout(()=>{
  2039. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  2040. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  2041. },300);
  2042. });
  2043. curIframe.src=url;
  2044. let insert=ruleParser.getInsert();
  2045. document.body.insertBefore(curIframe, loading);
  2046. return curIframe;
  2047. }
  2048.  
  2049. function nextPage(){
  2050. if(isPause || isLoading)return;
  2051. let nextLink=ruleParser.nextLinkHref;
  2052. if(!nextLink)return;
  2053. let insert=ruleParser.getInsert();
  2054. if(insert){
  2055. let isJs=/^(javascript|#)/.test(nextLink.replace(location.href,""));
  2056. if(location.protocol=="https:" && /^http:/.test(nextLink)){
  2057. nextLink=nextLink.replace(/^http/,"https");
  2058. }
  2059. isLoading=true;
  2060. loading.style.display="";
  2061. if(ruleParser.curSiteRule.pageElementByJs){
  2062. var over=ele=>{
  2063. isLoading=false;
  2064. loading.style.display="none";
  2065. if(ele){
  2066. createPageBar(nextLink);
  2067. ruleParser.insertPage(null, ele, nextLink, null, true);
  2068. }else{
  2069. debug("Stop as no page when get by js");
  2070. isPause=true;
  2071. }
  2072. };
  2073. try{
  2074. Function("over",'"use strict";' + ruleParser.curSiteRule.pageElementByJs)(over);
  2075. }catch(e){
  2076. debug(e);
  2077. }
  2078. }else if(ruleParser.curSiteRule.action==1 && !isJs){
  2079. requestFromIframe(nextLink, (doc, eles)=>{
  2080. isLoading=false;
  2081. loading.style.display="none";
  2082. if(eles){
  2083. createPageBar(nextLink);
  2084. ruleParser.insertPage(doc, eles, nextLink, null, true);
  2085. }
  2086. });
  2087. }else if(forceState==2 && !isJs){
  2088. forceIframe(nextLink, (iframe, eles)=>{
  2089. isLoading=false;
  2090. loading.style.display="none";
  2091. let pageBar=createPageBar(nextLink);
  2092. iframe.parentNode.insertBefore(pageBar, iframe);
  2093. });
  2094. }else{
  2095. if(!isJs){
  2096. requestDoc(nextLink, (eles)=>{
  2097. isLoading=false;
  2098. loading.style.display="none";
  2099. if(eles){
  2100. createPageBar(nextLink);
  2101. }
  2102. });
  2103. }else{
  2104. emuPage((doc, eles)=>{
  2105. isLoading=false;
  2106. loading.style.display="none";
  2107. if(eles){
  2108. createPageBar(nextLink);
  2109. ruleParser.insertPage(doc, eles, "", null, true);
  2110. }
  2111. });
  2112. }
  2113. }
  2114. }
  2115. }
  2116.  
  2117. function init(){
  2118. initRules(()=>{
  2119. initPage();
  2120. });
  2121. }
  2122. setTimeout(()=>{
  2123. init();
  2124. },300);
  2125. })();