东方永页机

自动加载并拼接下一分页内容(适用于论坛、漫画站、小说站、资讯站、博客等),无需规则支持所有网页

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

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

QingJ © 2025

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