东方永页机

自动翻页

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

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