东方永页机

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

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

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

QingJ © 2025

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