东方永页机

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

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

  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.2.0
  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. var allOfBody="body>*";
  355. _GM_registerMenuCommand(i18n("configure"), ()=>{
  356. _GM_openInTab(configPage,{active:true});
  357. });
  358.  
  359. function getElementByXpath(xpath, contextNode, doc){
  360. doc = doc || document;
  361. contextNode = contextNode || doc;
  362. try {
  363. var result = doc.evaluate(xpath, contextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
  364. return result.singleNodeValue && result.singleNodeValue.nodeType === 1 && result.singleNodeValue;
  365. } catch (err) {
  366. throw new Error(`Invalid xpath: ${xpath}`);
  367. }
  368. }
  369.  
  370. function getAllElementsByXpath(xpath, contextNode, doc){
  371. doc = doc || document;
  372. contextNode = contextNode || doc;
  373. var result = [];
  374. try {
  375. var query = doc.evaluate(xpath, contextNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  376. for (var i = 0; i < query.snapshotLength; i++) {
  377. var node = query.snapshotItem(i);
  378. if (node.nodeType === 1) result.push(node);
  379. }
  380. } catch (err) {
  381. throw new Error(`Invalid xpath: ${xpath}`);
  382. }
  383. return result;
  384. }
  385.  
  386. class RuleParser {
  387. constructor() {
  388. this.hpRules=[];
  389. this.customRules=[];
  390. this.rules=[];
  391. this.pageDoc=document;
  392. this.nextLinkHref=null;
  393. this.curUrl=location.href;
  394. this.curSiteRule={};
  395. }
  396.  
  397. initSavedRules(callback){
  398. var self=this;
  399. storage.getItem("hpRules", hpRules=>{
  400. if(hpRules)self.hpRules=hpRules;
  401. storage.getItem("customRules", customRules=>{
  402. if(customRules)self.customRules=customRules;
  403. storage.getItem("rules", rules=>{
  404. if(rules)this.rules=rules;
  405. callback();
  406. });
  407. });
  408. });
  409. }
  410.  
  411. saveCurSiteRule(){
  412. if(!this.curSiteRule || !this.curSiteRule.url || this.curSiteRule.singleUrl)return;
  413. this.hpRules=this.hpRules.filter(item=>{return item&&item.url!=this.curSiteRule.url});
  414. this.hpRules.unshift(this.curSiteRule);
  415. if(this.hpRules.length>30){
  416. this.hpRules.pop();
  417. }
  418. storage.setItem("hpRules", this.hpRules);
  419. }
  420.  
  421. requestJSON(url, callback){
  422. _GM_xmlhttpRequest({
  423. url: url,
  424. method: 'GET',
  425. timeout: 10000,
  426. onload: function(res) {
  427. let json=null;
  428. try{
  429. json=JSON.parse(res.response);
  430. }catch(e){
  431. debug(e);
  432. }
  433. callback(json);
  434. },
  435. onerror: function() {
  436. callback(null);
  437. }
  438. });
  439. }
  440.  
  441. formatRule(item, type, from){
  442. switch(type){
  443. case 0:
  444. return {
  445. from:from,
  446. type:type,
  447. name:item.name,
  448. action:item.data.forceIframe=="true"?1:0,
  449. url:item.data.url,
  450. pageElement:item.data.pageElement,
  451. nextLink:item.data.nextLink,
  452. insert:item.data.insertBefore,
  453. insertPos:1,
  454. updatedAt:item.data.updated_at,
  455. css:item.data.Stylus+item.data.CSS,
  456. pageAction:item.data.bookmarklet
  457. };
  458. break;
  459. case 1:
  460. default:
  461. item.from=from;
  462. if(typeof(item.type) == "undefined")item.type=type;
  463. return item;
  464. break;
  465. }
  466. return null;
  467. }
  468.  
  469. addRuleByUrl(url, type, from, callback) {
  470. this.requestJSON(url, json=>{
  471. this.addRules(json, type, from);
  472. callback();
  473. });
  474. }
  475.  
  476. addRules(rules, type, from) {
  477. if(rules && rules.length>0){
  478. this.rules=this.rules.filter(item=>{return item.from!=from});
  479. rules.forEach(item=>{
  480. let rule=this.formatRule(item, type, from);
  481. if(rule){
  482. this.rules.push(rule);
  483. }
  484. });
  485. }
  486. }
  487.  
  488. getRule(callback) {
  489. if(this.curSiteRule && this.curSiteRule.url){
  490. return this.curSiteRule;
  491. }
  492. var self=this;
  493.  
  494. function setRule(r){
  495. self.curSiteRule=r;
  496. debug(r);
  497. callback();
  498. }
  499.  
  500. function ruleMatch(r){
  501. let pageElement,nextLink,insert;
  502. if(r.pageElement)pageElement=r.type==0?getElementByXpath(r.pageElement):document.querySelector(r.pageElement);
  503. if(r.nextLink)nextLink=r.type==0?getElementByXpath(r.nextLink):document.querySelector(r.nextLink);
  504. if(r.insert)insert=r.type==0?getElementByXpath(r.insert):document.querySelector(r.insert);
  505. return !((r.pageElement && !pageElement) ||
  506. (r.nextLink && !nextLink) ||
  507. (r.insert && !insert));
  508. }
  509.  
  510. function checkRule(r){
  511. let urlReg=new RegExp(r.url, "i");
  512. if(urlReg.test(location.href)){
  513. if(r.wait){
  514. let waitTime=500,checkEval;
  515. if(isNaN(r.wait)){
  516. try{
  517. checkEval=Function("doc",'"use strict";' + r.wait);
  518. }catch(e){
  519. debug(e);
  520. }
  521. }else{
  522. waitTime=r.wait;
  523. }
  524. let checkReady=()=>{
  525. setTimeout(()=>{
  526. if(!ruleMatch(r) || (checkEval && !checkEval(document))){
  527. checkReady();
  528. }else{
  529. setRule(r);
  530. }
  531. },parseInt(waitTime));
  532. };
  533. checkReady();
  534. return true;
  535. }
  536. if(r.pinUrl){
  537. setRule(r);
  538. return true;
  539. }
  540. if(!ruleMatch(r)){
  541. return false;
  542. }
  543. setRule(r);
  544. return true;
  545. }
  546. return false;
  547. }
  548.  
  549. for(let i in this.hpRules){
  550. let rule=this.hpRules[i];
  551. if(!rule || !rule.url)continue;
  552. if(rule.singleUrl){
  553. if(location.origin+location.pathname==rule.url){
  554. setRule(rule);
  555. return;
  556. }
  557. continue;
  558. }
  559. if(checkRule(rule))return;
  560. }
  561. for(let i in this.customRules){
  562. let rule=this.customRules[i];
  563. if(!rule || !rule.url)continue;
  564. if(checkRule(rule))return;
  565. }
  566. let r=0;
  567. function searchByTime(){
  568. setTimeout(()=>{
  569. let end=r+80;
  570. end=end>self.rules.length?self.rules.length:end;
  571. for(;r<end;r++){
  572. let rule=self.rules[r];
  573. if(checkRule(rule))return;
  574. }
  575. if(end>=self.rules.length){
  576. self.curSiteRule={};
  577. self.curSiteRule.url=location.origin+location.pathname;
  578. self.curSiteRule.singleUrl=true;
  579. callback();
  580. return;
  581. }else{
  582. searchByTime();
  583. }
  584. },20);
  585. }
  586. searchByTime();
  587. }
  588.  
  589. geneSelector(ele){
  590. let selector=ele.tagName;
  591. //Google id class都是隨機。百度更過分,style script順序都是隨機的
  592. //if(ele.id) selector += '#' + ele.id;
  593. //if(ele.classList) selector += [].map.call(ele.classList,d=>'.'+d).join('');
  594. let parent = ele.parentElement;
  595. if(parent){
  596. let i,j=0;
  597. for(i=0;i<parent.children.length;i++){
  598. if(parent.children[i].tagName==selector){
  599. j++;
  600. if(parent.children[i]==ele){
  601. break;
  602. }
  603. }
  604. }
  605. selector = this.geneSelector(parent) + ' > ' + selector + (parent.tagName=="HTML"?"":`:nth-of-type(${j})`);
  606. }
  607. return selector;
  608. }
  609.  
  610. getPageElement(doc, curWin, dontFind) {
  611. let pageElement=null;
  612. let self=this;
  613. if(this.curSiteRule.pageElement){
  614. pageElement=this.curSiteRule.type==0?getAllElementsByXpath(this.curSiteRule.pageElement,doc,doc):doc.querySelectorAll(this.curSiteRule.pageElement);
  615. }
  616. if((!pageElement || pageElement.length==0) && curWin && !dontFind){
  617. let body=doc.body;
  618. if(!body)return null;
  619. let bodyHeight=parseInt(body.scrollHeight);
  620. let curHeight=bodyHeight;
  621. function checkElement(ele){
  622. if(curHeight/bodyHeight<=0.30)return null;
  623. if(ele.children.length==0 && !self.curSiteRule.pageElement){
  624. if(ele.parentNode.tagName=="P")ele=ele.parentNode;
  625. self.curSiteRule.pageElement=self.geneSelector(ele.parentNode)+">"+ele.tagName;
  626. debug(self.curSiteRule.pageElement);
  627. return [ele];
  628. }
  629. let i,maxHeight=curHeight*0.6,curMaxEle=null,curMaxArea=0,maxWidth=0;
  630. let isHori=true;
  631. let offsetTop=ele.children[0].offsetTop;
  632. for(i=0;i<ele.children.length;i++){
  633. if(ele.children[i].offsetTop!=offsetTop){
  634. isHori=false;
  635. break;
  636. }
  637. }
  638. for(i=0;i<ele.children.length;i++){
  639. let curNode=ele.children[i];
  640. let comStyle=curWin.getComputedStyle(curNode);
  641. let h=parseInt(curNode.scrollHeight);
  642. let w=parseInt(curNode.scrollWidth);
  643. if(isNaN(h) || isNaN(w))continue;
  644. if(isHori && h==0)continue;
  645. let a=h*w+h,moreChild=curNode.children[0];
  646. while(moreChild){
  647. comStyle=curWin.getComputedStyle(moreChild);
  648. let ch=parseInt(moreChild.scrollHeight);
  649. let cw=parseInt(moreChild.scrollWidth);
  650. if(h<ch)h=ch;
  651. if(moreChild.innerText!="" && !isNaN(ch) && !isNaN(cw)){
  652. a+=ch*cw;
  653. }
  654. moreChild=moreChild.nextElementSibling;
  655. }
  656. let isMax=false;
  657. if(isHori){
  658. if(maxWidth<w){
  659. isMax=true;
  660. }
  661. if(maxWidth==w && curMaxArea<a){
  662. isMax=true;
  663. }
  664. }else{
  665. isMax=curMaxArea<a;
  666. }
  667. if(curMaxEle==null || isMax){
  668. if(h>0)curHeight=h;
  669. curMaxArea=a;
  670. maxWidth=w;
  671. curMaxEle=curNode;
  672. }
  673. }
  674. if(curMaxEle && (isHori || curHeight>maxHeight)){
  675. return checkElement(curMaxEle);
  676. }
  677. if(!self.curSiteRule.pageElement){
  678. if(ele.tagName=="P")ele=ele.parentNode;
  679. self.curSiteRule.pageElement=self.geneSelector(ele);
  680. if(ele.children.length>1 && ele.tagName!="UL")self.curSiteRule.pageElement+=">*";
  681. debug(self.curSiteRule.pageElement);
  682. }
  683. return (ele.tagName=="UL"||ele.children.length==1)?[ele]:ele.children;
  684. }
  685. pageElement=checkElement(body);
  686. if(pageElement)this.saveCurSiteRule();
  687. }
  688. if(this.insert && pageElement && pageElement[0]){
  689. let example=this.insertPos==2?this.insert.children[0]:this.insert;
  690. let inTable=example.parentNode.tagName=="TABLE" ||
  691. example.tagName=="TR" ||
  692. example.tagName=="TBODY" ||
  693. (example.previousElementSibling && example.previousElementSibling.tagName=="TR") ||
  694. (example.previousElementSibling && example.previousElementSibling.tagName=="TBODY");
  695. if(inTable && pageElement[0].tagName!="TR" && pageElement[0].tagName!="TBODY"){
  696. pageElement=null;
  697. }
  698. }
  699. return pageElement;
  700. }
  701.  
  702. getPage(doc){
  703. if(_unsafeWindow.Discourse)return {};
  704. let canSave=false;//發現頁碼選擇器在其他頁對不上,還是別保存了
  705. let url=this.curUrl.replace("#!","");
  706. let pageNum=1,preStr="",afterStr="";
  707. let pageMatch1=url.match(/(.*[a-z\/\-_](?:p|page)?\/?)(\d+)(\.s?html?$|\/?$)/i);
  708. let pageMatch2=url.match(/(.*[\?&]p(?:age)?=)(\d+)($|[#&].*)/i);
  709. if(pageMatch1){
  710. preStr=pageMatch1[1];
  711. pageNum=pageMatch1[2];
  712. afterStr=pageMatch1[3];
  713. }else if(pageMatch2){
  714. preStr=pageMatch2[1];
  715. pageNum=pageMatch2[2];
  716. afterStr=pageMatch2[3];
  717. }
  718. let curPage=doc,i,cur,jsNext;
  719. let next=curPage.querySelector("a.next");
  720. if(!next)next=curPage.querySelector("a#next");
  721. if(!next)next=curPage.querySelector("a#rightFix");
  722. if(!next)next=curPage.querySelector("a.next_page");
  723. if(!next)next=curPage.querySelector(".next>a");
  724. if(!next)next=curPage.querySelector("#next_page");
  725. if(!next)next=curPage.querySelector(".next>button");
  726. if(!next)next=curPage.querySelector("a[alt=next]");
  727. if(!next)next=curPage.querySelector("[title=next]");
  728. if(!next){
  729. next=curPage.querySelectorAll("[aria-label='Next']");
  730. if(next && next.length==1){
  731. next=next[0];
  732. }else{
  733. next=null;
  734. }
  735. }
  736. if(!next){
  737. next=curPage.querySelectorAll("[aria-label='Next page']");
  738. if(next && next.length==1){
  739. next=next[0];
  740. }else{
  741. next=null;
  742. }
  743. }
  744. if(!next)next=curPage.querySelector(".nextPage");
  745. if(next && (!next.href || /^javascript:/.test(next.href))){
  746. jsNext=next;
  747. next=null;
  748. }
  749. if(!next){
  750. let pageDiv=curPage.querySelector("div.wp-pagenavi");
  751. if(pageDiv){
  752. cur=pageDiv.querySelector("span.current");
  753. next=cur.nextSibling;
  754. }else{
  755. cur=curPage.querySelector("div.article-paging>span");
  756. if(cur){
  757. next=cur.nextElementSibling;
  758. }
  759. }
  760. }
  761. if(!next){
  762. let pageDiv=curPage.querySelector("div.pages>ul");
  763. if(pageDiv){
  764. cur=pageDiv.querySelector("li>b");
  765. if(cur)next=cur.parentNode.nextElementSibling.querySelector("a");
  766. }
  767. }
  768. if(!next){
  769. let aTags=curPage.querySelectorAll("a");
  770. let next1,next2,next3,next4,nextJs1,nextJs2,nextJs3;
  771. for(i=aTags.length-1;i>=0;i--){
  772. let aTag=aTags[i];
  773. if(aTag.innerText=="§")continue;
  774. if(aTag.style.display=="none")continue;
  775. if(next1 && next2 && next3 && next4)break;
  776. if(!next1){
  777. if(/^\s*[下后後][一1]?[页頁张張]|^next( page)?\s*›?$|次のページ/i.test(aTag.innerText)){
  778. if(!aTag.href || /^javascript:/.test(aTag.href)){
  779. if(!nextJs1)nextJs1=aTag;
  780. }else{
  781. next1=aTag;
  782. }
  783. }
  784. }
  785. if(!next2){
  786. if(/^\s*[下后後][一1]?[章话話]/i.test(aTag.innerText)){
  787. if(!aTag.href || /^javascript:/.test(aTag.href)){
  788. if(!nextJs2)nextJs2=aTag;
  789. }else{
  790. next2=aTag;
  791. }
  792. }
  793. }
  794. if(!next3){
  795. if(aTag.innerText=="&gt;" || aTag.innerText=="▶" || aTag.innerText=="»"){
  796. if(!aTag.href || /^javascript:/.test(aTag.href)){
  797. if(!nextJs3)nextJs3=aTag;
  798. }else{
  799. next3=aTag;
  800. }
  801. }
  802. }
  803. if(!aTag.href || /^javascript:/.test(aTag.href))continue;
  804. if(!next4){
  805. if(aTag.href.replace("?&","?").replace("#!","").replace(preStr,"").replace(afterStr,"")==parseInt(pageNum)+1){
  806. next4=aTag;
  807. }else if(aTag.href.replace("?&","?").indexOf(url)!=-1 && /^[\/\?&]?[_-]?(p|page)?=?\/?2(\/|\?|&|$)/i.test(aTag.href.replace(url,"").replace(/\.s?html?$/i,""))){
  808. next4=aTag;
  809. }
  810. }
  811. }
  812. next=next1||next3||next4||next2||nextJs1||nextJs3||nextJs2;
  813. }
  814. if(!next)next=jsNext;
  815. return {next:next,canSave:canSave};
  816. }
  817.  
  818. getNextLink(doc) {
  819. let nextLink=null,page;
  820. if(this.curSiteRule.pageElementByJs){
  821. this.nextLinkHref="#";
  822. return true;
  823. }else if(this.curSiteRule.nextLinkByJs){
  824. try{
  825. let targetUrl=Function("doc",'"use strict";' + this.curSiteRule.nextLinkByJs)(doc);
  826. if(targetUrl)nextLink={href:targetUrl};
  827. }catch(e){
  828. debug(e);
  829. }
  830. }else if(this.curSiteRule.nextLinkByUrl){
  831. let targetUrl=this.curUrl.replace(new RegExp(this.curSiteRule.nextLinkByUrl[0]), this.curSiteRule.nextLinkByUrl[1]);
  832. if(targetUrl != this.curUrl){
  833. let reps=targetUrl.match(/{.*?}/g);
  834. if(reps){
  835. reps.forEach(rep=>{
  836. let code=rep.replace("{","").replace("}","");
  837. let result=code.match(/^(\d+)\+1$/);
  838. if(result){
  839. result=parseInt(result[1])+1;
  840. }else{
  841. try{
  842. result=Function('"use strict";return ' + code)();;
  843. }catch(e){
  844. debug(e);
  845. }
  846. }
  847. targetUrl=targetUrl.replace(rep, result);
  848. });
  849. }
  850. }
  851. nextLink={href:targetUrl};
  852. }else if(this.curSiteRule.nextLink){
  853. nextLink=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.nextLink,doc,doc):doc.querySelector(this.curSiteRule.nextLink);
  854. }else{
  855. page=this.getPage(doc);
  856. nextLink=page.next;
  857. if(nextLink){
  858. if(nextLink.classList.contains("noClick")){
  859. this.nextLinkHref=false;
  860. return null;
  861. }else if(doc==document){
  862. if((!nextLink.href || /^javascript:/.test(nextLink.href)) && !isVisible(nextLink, _unsafeWindow)){
  863. this.nextLinkHref=false;
  864. return null;
  865. }else{
  866. let nextLinkCs=_unsafeWindow.getComputedStyle(nextLink);
  867. if(nextLinkCs.cursor=="not-allowed"){
  868. this.nextLinkHref=false;
  869. return null;
  870. }
  871. }
  872. }
  873. }
  874. }
  875. if(nextLink){
  876. if(nextLink.href && nextLink.href==this.curUrl){
  877. nextLink=null;
  878. }else if(/^javascript:/.test(nextLink.href) && (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.getAttribute("_src") && !img.src){
  934. realSrc=img.getAttribute("_src");
  935. }else if(img.dataset && img.dataset.original){
  936. realSrc=img.dataset.original;
  937. }else if(img.dataset && img.dataset.src){
  938. realSrc=img.dataset.src;
  939. }else if(img._lazyrias && img._lazyrias.srcset){
  940. realSrc=img._lazyrias.srcset[img._lazyrias.srcset.length-1];
  941. }else if(img.dataset && img.dataset.origFile){
  942. realSrc=img.dataset.origFile;
  943. }else if(img.srcset){
  944. var srcs=img.srcset.split(","),largeSize=0;
  945. srcs.forEach(srci=>{
  946. let srcInfo=srci.trim().split(" "),curSize=parseInt(srcInfo[1]);
  947. if(srcInfo[1] && curSize>largeSize){
  948. largeSize=curSize;
  949. realSrc=srcInfo[0];
  950. }
  951. });
  952. }
  953. if(realSrc)img.src=realSrc;
  954. });
  955. [].forEach.call(ele.querySelectorAll("a.lazyload"), a=>{
  956. if(a.dataset.original){
  957. a.style.backgroundImage='url("'+a.dataset.original+'")';
  958. }
  959. });
  960. });
  961. let lazyImgSrc=this.curSiteRule.lazyImgSrc;
  962. if(lazyImgSrc){
  963. [].forEach.call(eles, ele=>{
  964. [].forEach.call(ele.querySelectorAll("img"), img=>{
  965. if(img.getAttribute(lazyImgSrc)){
  966. img.src=img.getAttribute(lazyImgSrc);
  967. }
  968. });
  969. });
  970. }
  971. }
  972.  
  973. initPage(callback){
  974. let self=this;
  975. curPage=1;
  976. //if(this.curSiteRule.url && !this.curSiteRule.singleUrl)return;
  977. this.curSiteRule={};
  978. this.pageDoc=document;
  979. this.nextLinkHref=null;
  980. this.curUrl=location.href;
  981. this.getRule(()=>{
  982. if(self.curSiteRule.enable==0){
  983. debug("Stop as rule disable");
  984. isPause=true;
  985. return;
  986. }
  987. if(self.curSiteRule && !self.curSiteRule.singleUrl){
  988. self.hpRules=self.hpRules.filter(item=>{return item&&item.url!=self.curSiteRule.url});
  989. self.hpRules.unshift(self.curSiteRule);
  990. if(self.hpRules.length>30){
  991. self.hpRules.pop();
  992. }
  993. storage.setItem("hpRules", self.hpRules);
  994. }
  995. let css=self.curSiteRule.css;
  996. if(css){
  997. _GM_addStyle(css);
  998. }
  999. let code=self.curSiteRule.init;
  1000. if(code){
  1001. try{
  1002. Function('"use strict";' + code)();
  1003. }catch(e){
  1004. debug(e);
  1005. }
  1006. }
  1007. self.getNextLink(document);
  1008. callback();
  1009. });
  1010. }
  1011.  
  1012. insertPage(doc, eles, url, callback, tried){
  1013. this.pageDoc=doc;
  1014. this.curUrl=url;
  1015. let nextLink=this.getNextLink(doc);
  1016. if(curPage==1 && !tried && !this.nextLinkHref && this.curSiteRule.singleUrl && this.curSiteRule.pageElement && this.curSiteRule.pageElement!=allOfBody){
  1017. this.curSiteRule.action=1;
  1018. return false;
  1019. }
  1020. if(callback)callback(eles);
  1021. this.getInsert();
  1022. var self=this,newEles=[];
  1023. if(!eles || eles.length==0 || !self.insert || !self.insert.parentNode){
  1024. }else{
  1025. [].forEach.call(eles, ele=>{
  1026. let newEle=ele.cloneNode(true);
  1027. let oldCanvass=ele.querySelectorAll("canvas");
  1028. let newCanvass=newEle.querySelectorAll("canvas");
  1029. for(let i=0;i<oldCanvass.length;i++){
  1030. let oldCanvas=oldCanvass[i];
  1031. let newCanvas=newCanvass[i];
  1032. newCanvas.getContext('2d').drawImage(oldCanvas, 0, 0);
  1033. }
  1034. if(self.curSiteRule.insertPos==2){
  1035. self.insert.appendChild(newEle);
  1036. }else{
  1037. self.insert.parentNode.insertBefore(newEle, self.insert);
  1038. }
  1039. newEles.push(newEle);
  1040. });
  1041. }
  1042. this.pageAction(doc, newEles);
  1043. return true;
  1044. }
  1045. }
  1046. var ruleParser = new RuleParser();
  1047.  
  1048. function initConfig(){
  1049. _GM_registerMenuCommand(i18n(forceState==1?"enable":"disableSite"), ()=>{
  1050. storage.setItem("forceState_"+location.host, (forceState==1?0:1));
  1051. location.reload();
  1052. });
  1053.  
  1054. _GM_registerMenuCommand(i18n(forceState==2?"cancelForceIframe":"forceIframe"), ()=>{
  1055. storage.setItem("forceState_"+location.host, (forceState==2?"":2));
  1056. location.reload();
  1057. });
  1058. var configCon,insertPos;
  1059. if(location.href==configPage){
  1060. _GM_addStyle(`
  1061. p>span:nth-child(1),p>span:nth-child(2),p>span:nth-child(3){
  1062. cursor: pointer;
  1063. user-select: none;
  1064. }
  1065. p>span:nth-child(1):hover,p>span:nth-child(2):hover,p>span:nth-child(3):hover{
  1066. color:red;
  1067. }
  1068. .updateDate{
  1069. cursor: pointer;
  1070. user-select: none;
  1071. }
  1072. .updateDate:hover{
  1073. color:red;
  1074. }
  1075. `);
  1076. configCon=document.querySelector(".markdown-body");
  1077. insertPos=configCon.querySelector("hr");
  1078. }else if(location.href==configPage){
  1079. }else return false;
  1080. class Rulebar {
  1081. init(ruleUrl){
  1082. this.ruleUrl=ruleUrl;
  1083. this.item=document.createElement("p");
  1084. this.item.title=ruleUrl.type==0?"AutoPagerize Rules":"Pagetual Rules";
  1085. this.item.dataset.id=this.ruleUrl.id;
  1086. let url=document.createElement("span");
  1087. url.innerHTML=ruleUrl.url;
  1088. let up=document.createElement("span");
  1089. up.innerHTML="↑ ";
  1090. up.title=i18n("sortTitle");
  1091. let down=document.createElement("span");
  1092. down.innerHTML="↓ ";
  1093. down.title=i18n("sortTitle");
  1094. let del=document.createElement("span");
  1095. del.innerHTML="× ";
  1096. up.onclick=e=>{
  1097. this.moveUp();
  1098. };
  1099. down.onclick=e=>{
  1100. this.moveDown();
  1101. };
  1102. del.onclick=e=>{
  1103. this.del();
  1104. };
  1105. this.item.appendChild(up);
  1106. this.item.appendChild(down);
  1107. this.item.appendChild(del);
  1108. this.item.appendChild(url);
  1109. configCon.insertBefore(this.item, insertPos);
  1110. }
  1111. saveSort(){
  1112. let sort=[];
  1113. [].forEach.call(this.item.parentNode.querySelectorAll("p[data-id]"), i=>{
  1114. sort.push(i.dataset.id);
  1115. });
  1116. rulesData.sort=sort;
  1117. storage.setItem("rulesData", rulesData);
  1118. }
  1119. moveUp(){
  1120. let preE=this.item.previousElementSibling;
  1121. if(preE.tagName=="P" && preE.children.length>1){
  1122. this.item.parentNode.insertBefore(this.item,preE);
  1123. this.saveSort();
  1124. }
  1125. }
  1126. moveDown(){
  1127. let nextE=this.item.nextElementSibling;
  1128. if(nextE.tagName=="P" && nextE.children.length>1){
  1129. this.item.parentNode.insertBefore(nextE,this.item);
  1130. this.saveSort();
  1131. }
  1132. }
  1133. del(){
  1134. if(this.ruleUrl.id<2){
  1135. alert(i18n("cantDel"));
  1136. }else if(window.confirm(i18n("confirmDel"))){
  1137. for(let u=0;u<rulesData.urls.length;u++){
  1138. if(this.ruleUrl.id==rulesData.urls[u].id){
  1139. rulesData.urls.splice(u,1);
  1140. break;
  1141. }
  1142. }
  1143. for(let u=0;u<rulesData.sort.length;u++){
  1144. if(this.ruleUrl.id==rulesData.sort[u]){
  1145. rulesData.sort.splice(u,1);
  1146. break;
  1147. }
  1148. }
  1149. storage.setItem("rulesData", rulesData);
  1150. ruleParser.rules=ruleParser.rules.filter(item=>{return item.from!=this.ruleUrl.id});
  1151. storage.setItem("rules", ruleParser.rules);
  1152. this.item.parentNode.removeChild(this.item);
  1153. //location.reload();
  1154. }
  1155. }
  1156. }
  1157. let updateP=document.createElement("p"),i=0;
  1158. let now=new Date().getTime(),inUpdate=false;
  1159.  
  1160.  
  1161. let pastDate=(new Date(updateDate)).toString(),passStr;
  1162. let passTime=(now-updateDate)/1000;
  1163. if(isNaN(passTime)){
  1164. passStr=i18n("firstUpdate");
  1165. }else if(passTime<60){
  1166. passStr=i18n("passSec", parseInt(passTime));
  1167. }else if(passTime<60*60){
  1168. passStr=i18n("passMin", parseInt(passTime/60));
  1169. }else if(passTime<60*60*24){
  1170. passStr=i18n("passHour", parseInt(passTime/3600));
  1171. }else{
  1172. passStr=i18n("passDay", parseInt(passTime/86400));
  1173. }
  1174.  
  1175.  
  1176. updateP.className="updateDate";
  1177. updateP.innerHTML=passStr;
  1178. updateP.title=i18n("update")+" - "+pastDate;
  1179. updateP.onclick=e=>{
  1180. if(inUpdate)return;
  1181. inUpdate=true;
  1182. let ruleIndex=0;
  1183. storage.setItem("hpRules", []);
  1184. function addNextRule(){
  1185. if(ruleIndex>=ruleUrls.length){
  1186. storage.setItem("ruleLastUpdate", now);
  1187. storage.setItem("rules", ruleParser.rules);
  1188. alert(i18n("updateSucc"));
  1189. inUpdate=false;
  1190. updateP.innerHTML=i18n("passSec", 0);
  1191. updateP.title=i18n("update");
  1192. }else{
  1193. let rule=ruleUrls[ruleIndex++];
  1194. ruleParser.addRuleByUrl(rule.url, rule.type, rule.id, ()=>{
  1195. addNextRule();
  1196. })
  1197. }
  1198. }
  1199. addNextRule();
  1200. alert(i18n("beginUpdate"));
  1201. };
  1202. configCon.insertBefore(updateP, insertPos);
  1203. if(ruleUrls){
  1204. ruleUrls.forEach(ruleUrl=>{
  1205. var rulebar=new Rulebar();
  1206. rulebar.init(ruleUrl);
  1207. });
  1208. }
  1209. let customUrlsTitle=document.createElement("h2");
  1210. customUrlsTitle.innerHTML=i18n("customUrls");
  1211. configCon.insertBefore(customUrlsTitle, insertPos);
  1212. let customUrlsInput=document.createElement("textarea");
  1213. customUrlsInput.style.width="100%";
  1214. customUrlsInput.placeholder="0|http://wedata.net/databases/AutoPagerize/items_all.json";
  1215. configCon.insertBefore(customUrlsInput, insertPos);
  1216.  
  1217. let opacityTitle=document.createElement("h2");
  1218. opacityTitle.innerHTML=i18n("opacity");
  1219. let opacityInput=document.createElement("input");
  1220. opacityInput.value=rulesData.opacity*100;
  1221. opacityInput.type="number";
  1222. opacityInput.style.width="50px";
  1223. opacityInput.style.margin="0 0 0 10px";
  1224. opacityTitle.appendChild(opacityInput);
  1225. configCon.insertBefore(opacityTitle, insertPos);
  1226.  
  1227.  
  1228. let hideBarTitle=document.createElement("h2");
  1229. hideBarTitle.innerHTML=i18n("hideBar");
  1230. let hideBarInput=document.createElement("input");
  1231. hideBarInput.type="checkbox";
  1232. hideBarInput.style.width="50px";
  1233. hideBarInput.style.height="20px";
  1234. hideBarInput.checked=rulesData.hideBar;
  1235. hideBarTitle.appendChild(hideBarInput);
  1236. configCon.insertBefore(hideBarTitle, insertPos);
  1237.  
  1238. let dbClick2StopTitle=document.createElement("h2");
  1239. dbClick2StopTitle.innerHTML=i18n("dbClick2Stop");
  1240. let dbClick2StopInput=document.createElement("input");
  1241. dbClick2StopInput.type="checkbox";
  1242. dbClick2StopInput.style.width="50px";
  1243. dbClick2StopInput.style.height="20px";
  1244. dbClick2StopInput.checked=rulesData.dbClick2Stop;
  1245. dbClick2StopTitle.appendChild(dbClick2StopInput);
  1246. configCon.insertBefore(dbClick2StopTitle, insertPos);
  1247.  
  1248. let enableWhiteListTitle=document.createElement("h2");
  1249. enableWhiteListTitle.innerHTML=i18n("autoRun");
  1250. let enableWhiteListInput=document.createElement("input");
  1251. enableWhiteListInput.type="checkbox";
  1252. enableWhiteListInput.style.width="50px";
  1253. enableWhiteListInput.style.height="20px";
  1254. enableWhiteListInput.checked=rulesData.enableWhiteList!=true;
  1255. enableWhiteListTitle.appendChild(enableWhiteListInput);
  1256. configCon.insertBefore(enableWhiteListTitle, insertPos);
  1257.  
  1258. let customRulesTitle=document.createElement("h2");
  1259. customRulesTitle.innerHTML=i18n("customRules")
  1260. configCon.insertBefore(customRulesTitle, insertPos);
  1261. let customRulesInput=document.createElement("textarea");
  1262. customRulesInput.style.width="100%";
  1263. customRulesInput.style.height="500px";
  1264. customRulesInput.placeholder=`[\n {\n "name":"yande",\n "action":"0",\n "url":"^https:\/\/yande\\.re\/",\n "pageElement":"ul#post-list-posts>li",\n "nextLink":"a.next_page",\n "css":".javascript-hide {display: inline-block !important;}"\n },\n {\n "name":"tieba",\n "action":"1",\n "url":"^https:\/\/tieba\\.baidu.com\/f\\?kw=",\n "pageElement":"ul#thread_list>li",\n "nextLink":".next.pagination-item "\n }\n]`;
  1265. customRulesInput.value=getFormatJSON(ruleParser.customRules);
  1266. configCon.insertBefore(customRulesInput, insertPos);
  1267. let saveBtn=document.createElement("button");
  1268. saveBtn.innerHTML=i18n("save");
  1269. saveBtn.style.width="100%";
  1270. configCon.insertBefore(saveBtn, insertPos);
  1271. saveBtn.onclick=e=>{
  1272. try{
  1273. storage.setItem("hpRules", []);
  1274. if(customRulesInput.value==""){
  1275. storage.setItem("customRules", "");
  1276. }else{
  1277. let customRules=JSON.parse(customRulesInput.value);
  1278. if(Array && Array.isArray && !Array.isArray(customRules)){
  1279. alert("Rules must be a Array!");
  1280. return;
  1281. }
  1282. debug(customRules);
  1283. storage.setItem("customRules", customRules);
  1284. }
  1285. }catch(e){
  1286. debug(e);
  1287. alert("JSON error, check again!");
  1288. return;
  1289. }
  1290. rulesData.opacity=opacityInput.value/100;
  1291. rulesData.hideBar=hideBarInput.checked;
  1292. rulesData.dbClick2Stop=dbClick2StopInput.checked;
  1293. rulesData.enableWhiteList=!enableWhiteListInput.checked;
  1294. storage.setItem("rulesData", rulesData);
  1295. let customUrls=customUrlsInput.value.trim();
  1296. if(customUrls){
  1297. customUrls=customUrls.split(/\n/);
  1298. for(let c=0;c<customUrls.length;c++){
  1299. let urlArr=customUrls[c].split("|"),url,type=1;
  1300. if(urlArr.length==1){
  1301. url=urlArr[0].trim();
  1302. if(!/^http/.test(url)){
  1303. alert("Wrong url, check again!");
  1304. return;
  1305. }
  1306. }else if(urlArr.length==2){
  1307. type=urlArr[0].trim();
  1308. url=urlArr[1].trim();
  1309. if(!/^http/.test(url)){
  1310. alert("Wrong url, check again!");
  1311. return;
  1312. }
  1313. }else{
  1314. break;
  1315. }
  1316. let maxId=0,hasUrl=false;;
  1317. if(!rulesData.urls){
  1318. rulesData.urls=[];
  1319. maxId=1;
  1320. }else{
  1321. rulesData.urls.forEach(u=>{
  1322. if(maxId<u.id){
  1323. maxId=u.id;
  1324. }
  1325. if(u.url==url){
  1326. hasUrl=true;
  1327. }
  1328. });
  1329. if(hasUrl)break;
  1330. }
  1331. rulesData.urls.push({id:maxId+1,url:url,type:type});
  1332. rulesData.sort.push(maxId+1);
  1333. storage.setItem("rulesData", rulesData);
  1334. }
  1335. }
  1336. alert("Modified successfully");
  1337. location.reload();
  1338. };
  1339. return true;
  1340. }
  1341.  
  1342. function objIsArr(obj) {
  1343. return obj &&
  1344. typeof obj === 'object' &&
  1345. typeof obj.length === 'number' &&
  1346. !(obj.propertyIsEnumerable('length'));
  1347. }
  1348.  
  1349. function isVisible(el, win) {
  1350. var loopable = true,
  1351. visible = el.tagName && win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  1352. while(loopable && visible) {
  1353. el = el.parentNode;
  1354.  
  1355. if(el && el.tagName && el.tagName!="BODY") {
  1356. visible = win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  1357. }else {
  1358. loopable = false;
  1359. }
  1360. }
  1361. return visible;
  1362. }
  1363.  
  1364. function getFormatJSON(obj){
  1365. if(!objIsArr(obj))return "";
  1366. let ret="[\n";
  1367. let len=obj.length,i=0,isLast;
  1368. obj.forEach(item=>{
  1369. ret+=" {\n";
  1370. let iLen=Object.keys(item).length,j=0;
  1371. for(let key in item){
  1372. isLast=(++j)==iLen;
  1373. let value=item[key];
  1374. if(objIsArr(value)){
  1375. let vstr="[",v=0,vIsLast=false;
  1376. value.forEach(vi=>{
  1377. vIsLast=(++v)==value.length;
  1378. vstr+="\""+vi.replace(/\\/g,"\\\\")+"\""+(vIsLast?"":",");
  1379. });
  1380. vstr+="]";
  1381. ret+=" \""+key+"\":"+vstr+""+(isLast?"":",")+"\n";
  1382. }else{
  1383. if(typeof value=="string"){
  1384. value=value.replace(/\\/g,"\\\\").replace(/"/g,"\\\"");
  1385. value="\""+value+"\"";
  1386. }
  1387. ret+=" \""+key+"\":"+value+""+(isLast?"":",")+"\n";
  1388. }
  1389. }
  1390. isLast=(++i)==len;
  1391. ret+=" }"+(isLast?"":",")+"\n";
  1392. });
  1393. ret+="]";
  1394. return ret;
  1395. }
  1396.  
  1397. function initRules(callback) {
  1398. /*0 wedata格式,1 pagetual格式*/
  1399. ruleUrls=[
  1400. {
  1401. id:0,
  1402. url:'https://raw.githubusercontent.com/hoothin/UserScripts/master/Pagetual/pagetualRules.json',
  1403. type:1
  1404. },
  1405. {
  1406. id:1,
  1407. url:'http://wedata.net/databases/AutoPagerize/items_all.json',
  1408. type:0,
  1409. }
  1410. ];var i=0,j=0;
  1411.  
  1412. ruleParser.initSavedRules(()=>{
  1413. storage.getItem("rulesData", data=>{
  1414. if(data){
  1415. rulesData=data;
  1416. if(data.urls)ruleUrls=ruleUrls.concat(data.urls);
  1417. if(data.sort){
  1418. let urls=[];
  1419. data.sort.forEach(id=>{
  1420. for(let s=0;s<ruleUrls.length;s++){
  1421. if(id==ruleUrls[s].id){
  1422. urls.push(ruleUrls[s]);
  1423. break;
  1424. }
  1425. }
  1426. });
  1427. ruleUrls=urls;
  1428. }
  1429. }
  1430. if(typeof(rulesData.opacity)=="undefined"){
  1431. rulesData.opacity=0.3;
  1432. }
  1433. if(typeof(rulesData.hideBar)=="undefined"){
  1434. rulesData.hideBar=true;
  1435. }
  1436. if(typeof(rulesData.dbClick2Stop)=="undefined"){
  1437. rulesData.dbClick2Stop=true;
  1438. }
  1439. if(typeof(rulesData.enableWhiteList)=="undefined"){
  1440. rulesData.enableWhiteList=false;
  1441. }
  1442. storage.getItem("forceState_"+location.host, v=>{
  1443. storage.getItem("ruleLastUpdate", date=>{
  1444. if(typeof(v)=="undefined"){
  1445. v=(rulesData.enableWhiteList?1:0);
  1446. }
  1447. forceState=v;
  1448. updateDate=date;
  1449. if(initConfig())return;
  1450. if(forceState==1)return;
  1451. let now=new Date().getTime();
  1452. if(!date || now-date>2*24*60*60*1000){
  1453. storage.setItem("ruleLastUpdate", now);
  1454. storage.setItem("hpRules", []);
  1455. let ruleIndex=0;
  1456. function addNextRule(){
  1457. if(ruleIndex>=ruleUrls.length){
  1458. storage.setItem("rules", ruleParser.rules);
  1459. callback();
  1460. }else{
  1461. let rule=ruleUrls[ruleIndex++];
  1462. ruleParser.addRuleByUrl(rule.url, rule.type, rule.id, ()=>{
  1463. addNextRule();
  1464. })
  1465. }
  1466. }
  1467. addNextRule();
  1468. }else{
  1469. callback();
  1470. }
  1471. });
  1472. });
  1473. });
  1474. });
  1475. }
  1476.  
  1477. function requestDoc(url, callback){
  1478. _GM_xmlhttpRequest({
  1479. url: url,
  1480. method: 'GET',
  1481. overrideMimeType: 'text/html;charset='+document.charset,
  1482. headers: {
  1483. 'Referer': location.href
  1484. },
  1485. timeout: 5000,
  1486. onload: function(res) {
  1487. var doc=null;
  1488. try {
  1489. doc=document.implementation.createHTMLDocument('');
  1490. doc.documentElement.innerHTML=res.response;
  1491. }
  1492. catch (e) {
  1493. debug('parse error'+e.toString());
  1494. }
  1495. let pageElement=ruleParser.getPageElement(doc);
  1496. //只有1的話怕不是圖片哦
  1497. if(pageElement && (pageElement.length>1 || (pageElement.length==1 && pageElement[0].tagName!="IMG") )){
  1498. let result=ruleParser.insertPage(doc, pageElement, url, callback, false);
  1499. if(!result){
  1500. requestFromIframe(url, (doc, eles)=>{
  1501. isLoading=false;
  1502. loading.style.display="none";
  1503. if(eles){
  1504. ruleParser.insertPage(doc, eles, url, callback, true);
  1505. }
  1506. });
  1507. }
  1508. }else if(ruleParser.curSiteRule.singleUrl){
  1509. requestFromIframe(url, (doc, eles)=>{
  1510. isLoading=false;
  1511. loading.style.display="none";
  1512. if(eles){
  1513. ruleParser.insertPage(doc, eles, url, callback, true);
  1514. }
  1515. });
  1516. }
  1517. },
  1518. onerror: function(e){
  1519. debug(e);
  1520. callback(false);
  1521. },
  1522. ontimeout: function(e){
  1523. debug(e);
  1524. callback(false);
  1525. }
  1526. });
  1527. }
  1528.  
  1529. var failFromIframe=0;
  1530. function requestFromIframe(url, callback){
  1531. let orgPage,curPage;
  1532. let iframe = document.createElement('iframe');
  1533. iframe.name = 'pagetual-iframe';
  1534. iframe.width = '100%';
  1535. iframe.height = '0';
  1536. iframe.frameBorder = '0';
  1537. if(ruleParser.curSiteRule.sandbox){
  1538. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1539. }
  1540. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1541. iframe.addEventListener("load", e=>{
  1542. let waitTime=500,checkEval;
  1543. if(ruleParser.curSiteRule.wait){
  1544. if(isNaN(ruleParser.curSiteRule.wait)){
  1545. try{
  1546. checkEval=Function("doc",'"use strict";' + ruleParser.curSiteRule.wait);
  1547. }catch(e){
  1548. debug(e);
  1549. }
  1550. }else{
  1551. waitTime=ruleParser.curSiteRule.wait;
  1552. }
  1553. }
  1554. setTimeout(()=>{
  1555. let tryTimes=0;
  1556. function checkIframe(){
  1557. try{
  1558. let doc=iframe.contentDocument || iframe.contentWindow.document;
  1559. let eles=ruleParser.getPageElement(doc, iframe.contentWindow);
  1560. if(eles && eles.length>0 && (!checkEval || checkEval(doc))){
  1561. callback(doc, eles);
  1562. }else if(tryTimes++ < 10){
  1563. setTimeout(()=>{
  1564. checkIframe();
  1565. },waitTime);
  1566. return;
  1567. }else{
  1568. if(failFromIframe++ > 2){
  1569. failFromIframe=0;
  1570. debug("Stop as failFromIframe");
  1571. isPause=true;
  1572. callback(false, false);
  1573. }else{
  1574. callback(false, false);
  1575. }
  1576. }
  1577. }catch(e){
  1578. debug("Stop as cors");
  1579. //isPause=true;
  1580. ruleParser.curSiteRule.pageElement=allOfBody;
  1581. ruleParser.getInsert(true);
  1582. callback(false, false);
  1583. }
  1584. document.body.removeChild(iframe);
  1585. }
  1586. checkIframe();
  1587. },waitTime);
  1588. });
  1589. iframe.src=url;
  1590. document.body.appendChild(iframe);
  1591. }
  1592.  
  1593. function initPage(){
  1594. ruleParser.initPage(()=>{
  1595. if(ruleParser.nextLinkHref)initView();
  1596. initListener();
  1597. nextPage();
  1598. });
  1599. }
  1600.  
  1601. function initView(){
  1602. _GM_addStyle(`
  1603. .pagetual_pageBar.stop {
  1604. -webkit-filter: invert(100%);
  1605. filter: invert(100%);
  1606. opacity: 1!important;
  1607. }
  1608. .pagetual_pageBar.hide {
  1609. display: none!important;
  1610. }
  1611. .pagetual_pageBar:hover {
  1612. opacity: 1!important;
  1613. }
  1614. .pagetual_pageBar span {
  1615. vertical-align: super;
  1616. }
  1617.  
  1618. .pagetual_pageBar span>svg:hover {
  1619. animation: touhouAni 1s infinite;
  1620. }
  1621.  
  1622. @keyframes touhouAni{
  1623. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  1624. to {transform: rotate(360deg);}
  1625. }
  1626. @-webkit-keyframes touhouAni{
  1627. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  1628. to {transform: rotate(360deg);}
  1629. }
  1630. `);
  1631. 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;`;
  1632. }
  1633. var loading=document.createElement("div");
  1634. loading.className="pagetual_loading";
  1635. 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;";
  1636. 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>`;
  1637. document.body.appendChild(loading);
  1638.  
  1639. 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>`;
  1640. 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>`;
  1641. var pageBarStyle;
  1642. 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;`;
  1643. 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);`;
  1644.  
  1645. var isPause=false,isLoading=false,curPage=1,forceState=0,bottomGap=1000;
  1646.  
  1647. function changeStop(stop, hide){
  1648. isPause=stop;
  1649. [].forEach.call(document.querySelectorAll(".pagetual_pageBar"), bar=>{
  1650. if(isPause){
  1651. bar.classList.add("stop");
  1652. if(hide)bar.classList.add("hide");
  1653. }else{
  1654. bar.classList.remove("stop");
  1655. if(hide)bar.classList.remove("hide");
  1656. }
  1657. });
  1658. }
  1659.  
  1660. function isInViewPort(element) {
  1661. if(!element.parentNode)return false;
  1662. if(_unsafeWindow.getComputedStyle(element).display=="none")return false;
  1663. const viewWidth = window.innerWidth || document.documentElement.clientWidth;
  1664. const viewHeight = window.innerHeight || document.documentElement.clientHeight;
  1665. const {
  1666. top,
  1667. right,
  1668. bottom,
  1669. left,
  1670. } = element.getBoundingClientRect();
  1671.  
  1672. return (
  1673. top >= 0 &&
  1674. left >= 0 &&
  1675. right <= viewWidth &&
  1676. bottom <= viewHeight
  1677. );
  1678. }
  1679.  
  1680. var urlChanged=false;
  1681. var _wr = function(type) {
  1682. var orig = history[type];
  1683. return function() {
  1684. var rv = orig.apply(this, arguments);
  1685. var e = new Event(type);
  1686. e.arguments = arguments;
  1687. window.dispatchEvent(e);
  1688. return rv;
  1689. };
  1690. };
  1691. history.pushState = _wr('pushState');
  1692. window.addEventListener('pushState', function(e) {
  1693. urlChanged=true;
  1694. setTimeout(()=>{
  1695. if(location.href==configPage){
  1696. location.reload();
  1697. }
  1698. },1);
  1699. });
  1700.  
  1701. function initListener(){
  1702. let loadmoreBtn,loading=true;
  1703. setTimeout(()=>{
  1704. loadmoreBtn=getLoadMore(document);
  1705. if(loadmoreBtn){
  1706. loading=false;
  1707. }
  1708. },300);
  1709. document.addEventListener('scroll', e=>{
  1710. if(urlChanged){
  1711. ruleParser.initPage(()=>{
  1712. if(ruleParser.nextLinkHref)initView();
  1713. });
  1714. urlChanged=false;
  1715. isPause=false;
  1716. }
  1717. if(isPause)return;
  1718. if(!loading){
  1719. loading=true;
  1720. if(!loadmoreBtn || !loadmoreBtn.parentNode){
  1721. loadmoreBtn=getLoadMore(document);
  1722. }
  1723. if(loadmoreBtn){
  1724. loading=false;
  1725. if(isInViewPort(loadmoreBtn)){
  1726. emuClick(loadmoreBtn);
  1727. }
  1728. }else{
  1729. setTimeout(()=>{loading=false},500);
  1730. }
  1731. }
  1732. setTimeout(()=>{
  1733. if(!isLoading){
  1734. let scrolly=window.scrollY;
  1735. let windowHeight=window.innerHeight;
  1736. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  1737. if(scrollH-scrolly-windowHeight<bottomGap){
  1738. nextPage();
  1739. }
  1740. }
  1741. },100);
  1742. }, true);
  1743. document.addEventListener('dblclick', e=>{
  1744. if(rulesData.dbClick2Stop){
  1745. setTimeout(()=>{
  1746. changeStop(!isPause, rulesData.hideBar);
  1747. if(!isPause){
  1748. let scrolly=window.scrollY;
  1749. let windowHeight=window.innerHeight;
  1750. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  1751. if(scrollH-scrolly-windowHeight<bottomGap){
  1752. nextPage();
  1753. }
  1754. }
  1755. },200);
  1756. }
  1757. });
  1758. }
  1759.  
  1760. function getLoadMore(doc){
  1761. let btnSel=ruleParser.curSiteRule.loadMore||".LoadMore,.load-more";
  1762. let loadmoreBtn=doc.querySelector(btnSel);
  1763. if(!loadmoreBtn){
  1764. let buttons=doc.querySelectorAll("input,button,a,div[onclick]"),loadmoreReg=/^\s*(加载更多|加載更多|load\s*more|もっと読み込む)\s*$/i;
  1765. for(let i=0;i<buttons.length;i++){
  1766. let button=buttons[i];
  1767. if(button && loadmoreReg.test(button.innerText)){
  1768. loadmoreBtn=button;
  1769. break;
  1770. }
  1771. }
  1772. }
  1773. return loadmoreBtn;
  1774. }
  1775.  
  1776. function createPageBar(url){
  1777. let insert=ruleParser.getInsert();
  1778. if(!insert || !insert.parentNode)return;
  1779. curPage++;
  1780. let example=ruleParser.curSiteRule.insertPos==2?insert.children[0]:insert;
  1781. let inTable=example.parentNode.tagName=="TABLE" ||
  1782. example.tagName=="TR" ||
  1783. example.tagName=="TBODY" ||
  1784. (example.previousElementSibling && example.previousElementSibling.tagName=="TR") ||
  1785. (example.previousElementSibling && example.previousElementSibling.tagName=="TBODY");
  1786. let inLi=example.tagName=="LI" || (example.previousElementSibling && example.previousElementSibling.tagName=="LI");
  1787. let pageBar=document.createElement(inTable?"tr":"div");
  1788. let upSpan=document.createElement("span");
  1789. let downSpan=document.createElement("span");
  1790. let pageText=document.createElement("a");
  1791. pageBar.className="pagetual_pageBar";
  1792. pageBar.id="pagetual_pageBar";
  1793. if(isPause){
  1794. pageBar.classList.add("stop");
  1795. }
  1796. pageBar.style.cssText=pageBarStyle;
  1797. pageBar.title=i18n(isPause?"enable":"disable");
  1798. upSpan.innerHTML=upSvg;
  1799. upSpan.title=i18n("toTop");
  1800. downSpan.innerHTML=downSvg;
  1801. downSpan.title=i18n("toBottom");
  1802. upSpan.style.cssText=initStyle;
  1803. downSpan.style.cssText=initStyle;
  1804. pageText.href=url;
  1805. pageText.style=pageTextStyle;
  1806. pageText.innerHTML="Page "+curPage;
  1807. pageText.title=i18n("current");
  1808. pageBar.appendChild(upSpan);
  1809. pageBar.appendChild(pageText);
  1810. pageBar.appendChild(downSpan);
  1811. if(inTable){
  1812. example=(insert.tagName=="TR" || insert.tagName=="TBODY")?insert:insert.previousElementSibling;
  1813. if(example.previousElementSibling)example=example.previousElementSibling;
  1814. let tdNum=0;
  1815. [].forEach.call(example.querySelectorAll("td,th"), td=>{
  1816. tdNum+=td.colSpan||1;
  1817. });
  1818. pageBar.style.display="table-row";
  1819. pageBar.style.backgroundColor="unset";
  1820. let td=document.createElement("td");
  1821. td.style.backgroundColor="rgb(240 240 240 / 80%)";
  1822. td.style.borderRadius="20px";
  1823. td.colSpan=tdNum||1;
  1824. td.style.padding="0 0";
  1825. td.style.textAlign="center";
  1826. td.appendChild(upSpan);
  1827. td.appendChild(pageText);
  1828. td.appendChild(downSpan);
  1829. pageBar.appendChild(td);
  1830. }
  1831.  
  1832. upSpan.addEventListener("click", e=>{
  1833. //changeStop(true);
  1834. //pageBar.title=i18n(isPause?"enable":"disable");
  1835. document.body.scrollTop=0;
  1836. document.documentElement.scrollTop=0;
  1837. e.preventDefault();
  1838. e.stopPropagation();
  1839. });
  1840. downSpan.addEventListener("click", e=>{
  1841. changeStop(true);
  1842. pageBar.title=i18n(isPause?"enable":"disable");
  1843. document.body.scrollTop=9999999;
  1844. document.documentElement.scrollTop=9999999;
  1845. e.preventDefault();
  1846. e.stopPropagation();
  1847. });
  1848. pageBar.addEventListener("click", e=>{
  1849. changeStop(!isPause);
  1850. pageBar.title=i18n(isPause?"enable":"disable");
  1851. });
  1852. pageText.addEventListener("click", e=>{
  1853. e.stopPropagation();
  1854. });
  1855. let parentStyle=_unsafeWindow.getComputedStyle(insert.parentNode);
  1856. pageBar.style.width=parseInt(parentStyle.width)*.99-parseInt(parentStyle.paddingLeft)-parseInt(parentStyle.paddingRight)+"px";
  1857. if(inLi){
  1858. pageBar.style.width="90%";
  1859. pageBar.style.minWidth="150px";
  1860. pageBar.style.display="inline-block";
  1861. let line=document.createElement("li");
  1862. line.style.textAlign="center";
  1863. line.appendChild(pageBar);
  1864. if(ruleParser.curSiteRule.insertPos==2){
  1865. insert.appendChild(line);
  1866. }else{
  1867. insert.parentNode.insertBefore(line, insert);
  1868. }
  1869. }else{
  1870. if(ruleParser.curSiteRule.insertPos==2){
  1871. insert.appendChild(pageBar);
  1872. }else{
  1873. insert.parentNode.insertBefore(pageBar, insert);
  1874. }
  1875. }
  1876. if(ruleParser.curSiteRule.pageBar){
  1877. try{
  1878. Function("pageBar",'"use strict";' + ruleParser.curSiteRule.pageBar)(pageBar);
  1879. }catch(e){
  1880. debug(e);
  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'),iframeDoc;
  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. try{
  2066. iframeDoc=curIframe.contentDocument || curIframe.contentWindow.document;
  2067. }catch(e){
  2068. debug("Stop as cors");
  2069. isPause=true;
  2070. callback(false, false);
  2071. return;
  2072. }
  2073. ruleParser.insertPage(iframeDoc, [], url, null, true);
  2074. callback(curIframe, true);
  2075. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  2076. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  2077. });
  2078. let inAction=false;
  2079. let forceRefresh=e=>{
  2080. if(inAction || !iframeDoc)return;
  2081. inAction=true;
  2082. setTimeout(()=>{
  2083. inAction=false;
  2084. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  2085. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  2086. if(!ruleParser.nextLinkHref){
  2087. ruleParser.getNextLink(iframeDoc);
  2088. if(ruleParser.nextLinkHref){
  2089. document.removeEventListener("scroll", forceRefresh);
  2090. }
  2091. }else{
  2092. document.removeEventListener("scroll", forceRefresh);
  2093. }
  2094. },500);
  2095. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  2096. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  2097. };
  2098. document.addEventListener("scroll", forceRefresh);
  2099. curIframe.src=url;
  2100. let insert=ruleParser.getInsert();
  2101. document.body.insertBefore(curIframe, loading);
  2102. return curIframe;
  2103. }
  2104.  
  2105. function nextPage(){
  2106. if(isPause || isLoading)return;
  2107. let nextLink=ruleParser.nextLinkHref;
  2108. if(!nextLink)return;
  2109. let insert=ruleParser.getInsert();
  2110. if(insert){
  2111. let isJs=/^(javascript|#)/.test(nextLink.replace(location.href,""));
  2112. if(location.protocol=="https:" && /^http:/.test(nextLink)){
  2113. nextLink=nextLink.replace(/^http/,"https");
  2114. }
  2115. isLoading=true;
  2116. loading.style.display="";
  2117. let sleep=ruleParser.curSiteRule.sleep||0;
  2118. setTimeout(()=>{
  2119. if(ruleParser.curSiteRule.pageElementByJs){
  2120. var over=ele=>{
  2121. isLoading=false;
  2122. loading.style.display="none";
  2123. if(ele){
  2124. createPageBar(nextLink);
  2125. ruleParser.insertPage(null, ele, nextLink, null, true);
  2126. }else{
  2127. debug("Stop as no page when get by js");
  2128. isPause=true;
  2129. }
  2130. };
  2131. try{
  2132. Function("over",'"use strict";' + ruleParser.curSiteRule.pageElementByJs)(over);
  2133. }catch(e){
  2134. debug(e);
  2135. }
  2136. }else if(ruleParser.curSiteRule.action==1 && !isJs){
  2137. requestFromIframe(nextLink, (doc, eles)=>{
  2138. isLoading=false;
  2139. loading.style.display="none";
  2140. if(eles){
  2141. createPageBar(nextLink);
  2142. ruleParser.insertPage(doc, eles, nextLink, null, true);
  2143. }
  2144. });
  2145. }else if((forceState==2||ruleParser.curSiteRule.action==2) && !isJs){
  2146. forceIframe(nextLink, (iframe, eles)=>{
  2147. isLoading=false;
  2148. loading.style.display="none";
  2149. let pageBar=createPageBar(nextLink);
  2150. iframe.parentNode.insertBefore(pageBar, iframe);
  2151. });
  2152. }else{
  2153. if(!isJs){
  2154. requestDoc(nextLink, (eles)=>{
  2155. isLoading=false;
  2156. loading.style.display="none";
  2157. if(eles){
  2158. createPageBar(nextLink);
  2159. }
  2160. });
  2161. }else{
  2162. emuPage((doc, eles)=>{
  2163. isLoading=false;
  2164. loading.style.display="none";
  2165. if(eles){
  2166. createPageBar(nextLink);
  2167. ruleParser.insertPage(doc, eles, "", null, true);
  2168. }
  2169. });
  2170. }
  2171. }
  2172. },sleep);
  2173. }
  2174. }
  2175.  
  2176. function init(){
  2177. initRules(()=>{
  2178. initPage();
  2179. });
  2180. }
  2181. setTimeout(()=>{
  2182. init();
  2183. },300);
  2184. })();

QingJ © 2025

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