东方永页机

⚔️最强自动翻页脚本,自动加载并拼接下一分页内容(例如论坛、漫画站、小说站、资讯站、博客等),无需规则支持所有网页!

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

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