东方永页机

自动翻页

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

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