东方永页机

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

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址