东方永页机

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

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

QingJ © 2025

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