东方永页机

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

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

  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.3.2
  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=(typeof unsafeWindow=='undefined')?window:unsafeWindow;//兼容 ios userscripts 的寫法
  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. if(cur){
  790. next=cur.nextSibling;
  791. }
  792. }else{
  793. cur=curPage.querySelector("div.article-paging>span");
  794. if(cur){
  795. next=cur.nextElementSibling;
  796. }
  797. }
  798. }
  799. if(!next){
  800. let pageDiv=curPage.querySelector("div.pages>ul");
  801. if(pageDiv){
  802. cur=pageDiv.querySelector("li>b");
  803. if(cur)next=cur.parentNode.nextElementSibling.querySelector("a");
  804. }
  805. }
  806. if(!next){
  807. let aTags=curPage.querySelectorAll("a");
  808. let next1,next2,next3,next4,nextJs1,nextJs2,nextJs3;
  809. for(i=aTags.length-1;i>=0;i--){
  810. let aTag=aTags[i];
  811. if(aTag.innerText=="§")continue;
  812. if(aTag.style.display=="none")continue;
  813. if(next1 && next2 && next3 && next4)break;
  814. if(!next1){
  815. if(/^\s*[下后後][一1]?[页頁张張]|^next( page)?\s*›?$|次のページ/i.test(aTag.innerText)){
  816. if(!aTag.href || /^javascript:/.test(aTag.href)){
  817. if(!nextJs1)nextJs1=aTag;
  818. }else{
  819. next1=aTag;
  820. }
  821. }
  822. }
  823. if(!next2){
  824. if(/^\s*[下后後][一1]?[章话話]/i.test(aTag.innerText)){
  825. if(!aTag.href || /^javascript:/.test(aTag.href)){
  826. if(!nextJs2)nextJs2=aTag;
  827. }else{
  828. next2=aTag;
  829. }
  830. }
  831. }
  832. if(!next3){
  833. if(aTag.innerText=="&gt;" || aTag.innerText=="▶" || aTag.innerText==">" || /nextpage/i.test(aTag.className)){
  834. if(!aTag.href || /^javascript:/.test(aTag.href)){
  835. if(!nextJs3)nextJs3=aTag;
  836. }else{
  837. next3=aTag;
  838. }
  839. }
  840. }
  841. if(!aTag.href || /^javascript:/.test(aTag.href))continue;
  842. if(!next4){
  843. if(aTag.href.replace("?&","?").replace("#!","").replace("index.php?","?").replace(preStr,"").replace(afterStr,"")==parseInt(pageNum)+1){
  844. next4=aTag;
  845. }else if(aTag.href.replace("?&","?").replace("index.php?","?").indexOf(url)!=-1 && /^[\/\?&]?[_-]?(p|page)?=?\/?2(\/|\?|&|$)/i.test(aTag.href.replace(url,"").replace(/\.s?html?$/i,""))){
  846. let pageOne=aTag.getAttribute("href").replace(/2(\/|\?|&|$)/,"1$1");
  847. pageOne=curPage.querySelector(`a[href='${pageOne}']`);
  848. if(!pageOne)next4=aTag;
  849. }
  850. }
  851. }
  852. next=next1||next3||next4||next2||nextJs1||nextJs3||nextJs2;
  853. }
  854. if(!next)next=jsNext;
  855. if(next && next.classList.contains("results-more"))next=null;
  856. return {next:next,canSave:canSave};
  857. }
  858.  
  859. canonicalUri(src, base_path) {
  860. if(src.charAt(0)=="#")return location.href+src;
  861. var root_page = /^[^?#]*\//.exec(location.href)[0],
  862. root_domain = /^\w+\:\/\/\/?[^\/]+/.exec(root_page)[0],
  863. absolute_regex = /^\w+\:\/\//;
  864. src=src.replace(/\.\//,"");
  865. if (/^\/\/\/?/.test(src)){
  866. src = location.protocol + src;
  867. }
  868. else if (!absolute_regex.test(src) && src.charAt(0) != "/"){
  869. src = (base_path || "") + src;
  870. }
  871. return (absolute_regex.test(src) ? src : ((src.charAt(0) == "/" ? root_domain : root_page) + src));
  872. }
  873.  
  874. getNextLink(doc) {
  875. let nextLink=null,page;
  876. if(this.curSiteRule.pageElementByJs){
  877. this.nextLinkHref="#";
  878. return true;
  879. }else if(this.curSiteRule.nextLinkByJs){
  880. try{
  881. let targetUrl=Function("doc",'"use strict";' + this.curSiteRule.nextLinkByJs)(doc);
  882. if(targetUrl)nextLink={href:targetUrl};
  883. }catch(e){
  884. debug(e);
  885. }
  886. }else if(this.curSiteRule.nextLinkByUrl){
  887. let targetUrl=this.curUrl.replace(new RegExp(this.curSiteRule.nextLinkByUrl[0]), this.curSiteRule.nextLinkByUrl[1]);
  888. if(targetUrl != this.curUrl){
  889. let reps=targetUrl.match(/{.*?}/g);
  890. if(reps){
  891. reps.forEach(rep=>{
  892. let code=rep.replace("{","").replace("}","");
  893. let result=code.match(/^(\d+)\+1$/);
  894. if(result){
  895. result=parseInt(result[1])+1;
  896. }else{
  897. try{
  898. result=Function('"use strict";return ' + code)();;
  899. }catch(e){
  900. debug(e);
  901. }
  902. }
  903. targetUrl=targetUrl.replace(rep, result);
  904. });
  905. }
  906. }
  907. nextLink={href:targetUrl};
  908. }else if(this.curSiteRule.nextLink){
  909. if(this.curSiteRule.nextLink!="0"){
  910. nextLink=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.nextLink,doc,doc):doc.querySelector(this.curSiteRule.nextLink);
  911. }
  912. }else{
  913. page=this.getPage(doc);
  914. nextLink=page.next;
  915. if(nextLink){
  916. if(nextLink.tagName=="INPUT" && nextLink.parentNode.tagName=="FORM"){
  917. let params=[];
  918. let form=nextLink.parentNode;
  919. [].forEach.call(form.querySelectorAll("input"), input=>{
  920. params.push(input.name+'='+input.value);
  921. });
  922. nextLink.href=form.action+'?'+params.join('&');
  923. }
  924. if(nextLink.classList.contains("noClick")){
  925. this.nextLinkHref=false;
  926. return null;
  927. }else if(doc==document){
  928. if((!nextLink.href || /^javascript:/.test(nextLink.href)) && !isVisible(nextLink, _unsafeWindow)){
  929. this.nextLinkHref=false;
  930. return null;
  931. }else{
  932. let nextLinkCs=_unsafeWindow.getComputedStyle(nextLink);
  933. if(nextLinkCs.cursor=="not-allowed"){
  934. this.nextLinkHref=false;
  935. return null;
  936. }
  937. }
  938. }
  939. }
  940. }
  941. if(nextLink){
  942. if(nextLink.href && nextLink.href==this.curUrl){
  943. nextLink=null;
  944. }else if(/^javascript:/.test(nextLink.href) && (this.curSiteRule.action==0 || this.curSiteRule.action==1)){
  945. nextLink=null;
  946. }
  947. /*if(!this.curSiteRule.nextLink && page && page.canSave){
  948. this.curSiteRule.nextLink=this.geneSelector(nextLink);
  949. this.curSiteRule.type=1;
  950. this.saveCurSiteRule();
  951. }*/
  952. }
  953. if(nextLink){
  954. this.nextLinkHref=nextLink.href?this.canonicalUri(nextLink.href):"#";
  955. debug(nextLink);
  956. }else{
  957. this.nextLinkHref=false;
  958. }
  959. return nextLink;
  960. }
  961.  
  962. getInsert(refresh) {
  963. if(refresh){
  964. this.insert=null;
  965. }
  966. if(this.insert && !refresh){
  967. let parent=this.insert;
  968. while(parent && parent.nodeName!="BODY"){
  969. parent=parent.parentNode;
  970. }
  971. if(parent && parent.nodeName=="BODY"){
  972. return this.insert;
  973. }
  974. }
  975. if(this.curSiteRule.insert){
  976. this.insert=this.curSiteRule.type==0?getElementByXpath(this.curSiteRule.insert,document):document.querySelector(this.curSiteRule.insert);
  977. }else{
  978. let pageElement=this.getPageElement(document, _unsafeWindow);
  979. if(pageElement && pageElement.length>0){
  980. var pELast = pageElement[pageElement.length - 1];
  981. this.insert = pELast.nextSibling ? pELast.nextSibling : pELast.parentNode.appendChild(document.createTextNode(' '));
  982. }
  983. }
  984. return this.insert;
  985. }
  986.  
  987. pageAction(doc,eles){
  988. let code=this.curSiteRule.pageAction;
  989. if(code){
  990. try{
  991. Function("doc","eles",'"use strict";' + code)(doc,eles);
  992. }catch(e){
  993. debug(e);
  994. }
  995. }
  996. let setLazyImg=img=>{
  997. let realSrc;
  998. if(img.getAttribute("_src") && !img.src){
  999. realSrc=img.getAttribute("_src");
  1000. }else if(img.dataset && img.dataset.original){
  1001. realSrc=img.dataset.original;
  1002. }else if(img.dataset && img.dataset.src){
  1003. realSrc=img.dataset.src;
  1004. }else if(img._lazyrias && img._lazyrias.srcset){
  1005. realSrc=img._lazyrias.srcset[img._lazyrias.srcset.length-1];
  1006. }else if(img.dataset && img.dataset.origFile){
  1007. realSrc=img.dataset.origFile;
  1008. }else if(img.srcset){
  1009. var srcs=img.srcset.split(","),largeSize=0;
  1010. srcs.forEach(srci=>{
  1011. let srcInfo=srci.trim().split(" "),curSize=parseInt(srcInfo[1]);
  1012. if(srcInfo[1] && curSize>largeSize){
  1013. largeSize=curSize;
  1014. realSrc=srcInfo[0];
  1015. }
  1016. });
  1017. }
  1018. if(realSrc){
  1019. img.src=realSrc;
  1020. img.style.display="block";
  1021. }
  1022. };
  1023. [].forEach.call(eles, ele=>{
  1024. if(ele.tagName=="IMG"){
  1025. setLazyImg(ele);
  1026. }else{
  1027. [].forEach.call(ele.querySelectorAll("img"), img=>{
  1028. setLazyImg(img);
  1029. });
  1030. }
  1031. if(ele.tagName=="A" && ele.classList.contains("lazyload")){
  1032. if(ele.dataset.original){
  1033. ele.style.backgroundImage='url("'+ele.dataset.original+'")';
  1034. }
  1035. }else{
  1036. [].forEach.call(ele.querySelectorAll("a.lazyload"), a=>{
  1037. if(a.dataset.original){
  1038. a.style.backgroundImage='url("'+a.dataset.original+'")';
  1039. }
  1040. });
  1041. }
  1042. });
  1043. let lazyImgSrc=this.curSiteRule.lazyImgSrc;
  1044. if(lazyImgSrc){
  1045. [].forEach.call(eles, ele=>{
  1046. [].forEach.call(ele.querySelectorAll("img"), img=>{
  1047. if(img.getAttribute(lazyImgSrc)){
  1048. img.src=img.getAttribute(lazyImgSrc);
  1049. }
  1050. });
  1051. });
  1052. }
  1053. }
  1054.  
  1055. initPage(callback){
  1056. let self=this;
  1057. curPage=1;
  1058. //if(this.curSiteRule.url && !this.curSiteRule.singleUrl)return;
  1059. this.curSiteRule={};
  1060. this.pageDoc=document;
  1061. this.nextLinkHref=null;
  1062. this.curUrl=location.href;
  1063. this.getRule(()=>{
  1064. if(self.curSiteRule.enable==0){
  1065. debug("Stop as rule disable");
  1066. isPause=true;
  1067. return;
  1068. }
  1069. if(self.curSiteRule && !self.curSiteRule.singleUrl){
  1070. self.hpRules=self.hpRules.filter(item=>{return item&&item.url!=self.curSiteRule.url});
  1071. self.hpRules.unshift(self.curSiteRule);
  1072. if(self.hpRules.length>30){
  1073. self.hpRules.pop();
  1074. }
  1075. storage.setItem("hpRules", self.hpRules);
  1076. }
  1077. let css=self.curSiteRule.css;
  1078. if(css){
  1079. _GM_addStyle(css);
  1080. }
  1081. let code=self.curSiteRule.init;
  1082. if(code){
  1083. try{
  1084. Function('doc','"use strict";' + code)(null);
  1085. }catch(e){
  1086. debug(e);
  1087. }
  1088. }
  1089. self.getNextLink(document);
  1090. callback();
  1091. });
  1092. }
  1093.  
  1094. insertPage(doc, eles, url, callback, tried){
  1095. this.pageDoc=doc;
  1096. this.curUrl=url;
  1097. let nextLink=this.getNextLink(doc);
  1098. if(curPage==1 && !tried && !this.nextLinkHref && this.curSiteRule.singleUrl && this.curSiteRule.pageElement && this.curSiteRule.pageElement!=allOfBody){
  1099. this.curSiteRule.action=1;
  1100. return false;
  1101. }
  1102. if(callback)callback(eles);
  1103. this.getInsert();
  1104. var self=this,newEles=[];
  1105. if(!eles || eles.length==0 || !self.insert || !self.insert.parentNode){
  1106. }else{
  1107. [].forEach.call(eles, ele=>{
  1108. let newEle=ele.cloneNode(true);
  1109. let oldCanvass=ele.querySelectorAll("canvas");
  1110. let newCanvass=newEle.querySelectorAll("canvas");
  1111. for(let i=0;i<oldCanvass.length;i++){
  1112. let oldCanvas=oldCanvass[i];
  1113. let newCanvas=newCanvass[i];
  1114. newCanvas.getContext('2d').drawImage(oldCanvas, 0, 0);
  1115. }
  1116. if(self.curSiteRule.insertPos==2){
  1117. self.insert.appendChild(newEle);
  1118. }else{
  1119. self.insert.parentNode.insertBefore(newEle, self.insert);
  1120. }
  1121. newEles.push(newEle);
  1122. });
  1123. }
  1124. this.pageAction(doc, newEles);
  1125. return true;
  1126. }
  1127. }
  1128. var ruleParser = new RuleParser();
  1129.  
  1130. function initConfig(){
  1131. _GM_registerMenuCommand(i18n(forceState==1?"enable":"disableSite"), ()=>{
  1132. storage.setItem("forceState_"+location.host, (forceState==1?0:1));
  1133. location.reload();
  1134. });
  1135. _GM_registerMenuCommand(i18n("update"), ()=>{
  1136. updateRules(()=>{
  1137. alert(i18n("updateSucc"));
  1138. location.reload();
  1139. },rule=>{
  1140. alert("Update "+rule.url+" rules fail!");
  1141. });
  1142. alert(i18n("beginUpdate"));
  1143. });
  1144.  
  1145. var configCon,insertPos;
  1146. if(location.href==configPage){
  1147. _GM_addStyle(`
  1148. p>span:nth-child(1),p>span:nth-child(2),p>span:nth-child(3){
  1149. cursor: pointer;
  1150. user-select: none;
  1151. }
  1152. p>span:nth-child(1):hover,p>span:nth-child(2):hover,p>span:nth-child(3):hover{
  1153. color:red;
  1154. }
  1155. .updateDate{
  1156. cursor: pointer;
  1157. user-select: none;
  1158. }
  1159. .updateDate:hover{
  1160. color:red;
  1161. }
  1162. `);
  1163. configCon=document.querySelector(".markdown-body");
  1164. insertPos=configCon.querySelector("hr");
  1165. }else if(location.href==configPage){
  1166. }else return false;
  1167. class Rulebar {
  1168. init(ruleUrl){
  1169. this.ruleUrl=ruleUrl;
  1170. this.item=document.createElement("p");
  1171. this.item.title=ruleUrl.type==0?"AutoPagerize Rules":"Pagetual Rules";
  1172. this.item.dataset.id=this.ruleUrl.id;
  1173. let url=document.createElement("span");
  1174. url.innerHTML=ruleUrl.url;
  1175. let up=document.createElement("span");
  1176. up.innerHTML="↑ ";
  1177. up.title=i18n("sortTitle");
  1178. let down=document.createElement("span");
  1179. down.innerHTML="↓ ";
  1180. down.title=i18n("sortTitle");
  1181. let del=document.createElement("span");
  1182. del.innerHTML="× ";
  1183. up.onclick=e=>{
  1184. this.moveUp();
  1185. };
  1186. down.onclick=e=>{
  1187. this.moveDown();
  1188. };
  1189. del.onclick=e=>{
  1190. this.del();
  1191. };
  1192. this.item.appendChild(up);
  1193. this.item.appendChild(down);
  1194. this.item.appendChild(del);
  1195. this.item.appendChild(url);
  1196. configCon.insertBefore(this.item, insertPos);
  1197. }
  1198. saveSort(){
  1199. let sort=[];
  1200. [].forEach.call(this.item.parentNode.querySelectorAll("p[data-id]"), i=>{
  1201. sort.push(i.dataset.id);
  1202. });
  1203. rulesData.sort=sort;
  1204. storage.setItem("rulesData", rulesData);
  1205. }
  1206. moveUp(){
  1207. let preE=this.item.previousElementSibling;
  1208. if(preE.tagName=="P" && preE.children.length>1){
  1209. this.item.parentNode.insertBefore(this.item,preE);
  1210. this.saveSort();
  1211. }
  1212. }
  1213. moveDown(){
  1214. let nextE=this.item.nextElementSibling;
  1215. if(nextE.tagName=="P" && nextE.children.length>1){
  1216. this.item.parentNode.insertBefore(nextE,this.item);
  1217. this.saveSort();
  1218. }
  1219. }
  1220. del(){
  1221. if(this.ruleUrl.id<2){
  1222. alert(i18n("cantDel"));
  1223. }else if(window.confirm(i18n("confirmDel"))){
  1224. for(let u=0;u<rulesData.urls.length;u++){
  1225. if(this.ruleUrl.id==rulesData.urls[u].id){
  1226. rulesData.urls.splice(u,1);
  1227. break;
  1228. }
  1229. }
  1230. for(let u=0;u<rulesData.sort.length;u++){
  1231. if(this.ruleUrl.id==rulesData.sort[u]){
  1232. rulesData.sort.splice(u,1);
  1233. break;
  1234. }
  1235. }
  1236. storage.setItem("rulesData", rulesData);
  1237. ruleParser.rules=ruleParser.rules.filter(item=>{return item.from!=this.ruleUrl.id});
  1238. storage.setItem("rules", ruleParser.rules);
  1239. this.item.parentNode.removeChild(this.item);
  1240. //location.reload();
  1241. }
  1242. }
  1243. }
  1244. let updateP=document.createElement("p"),i=0;
  1245. let now=new Date().getTime(),inUpdate=false;
  1246.  
  1247.  
  1248. let pastDate=(new Date(updateDate)).toString(),passStr;
  1249. let passTime=(now-updateDate)/1000;
  1250. if(isNaN(passTime)){
  1251. passStr=i18n("firstUpdate");
  1252. }else if(passTime<60){
  1253. passStr=i18n("passSec", parseInt(passTime))+" ← "+i18n("click2update");
  1254. }else if(passTime<60*60){
  1255. passStr=i18n("passMin", parseInt(passTime/60))+" ← "+i18n("click2update");
  1256. }else if(passTime<60*60*24){
  1257. passStr=i18n("passHour", parseInt(passTime/3600))+" ← "+i18n("click2update");
  1258. }else{
  1259. passStr=i18n("passDay", parseInt(passTime/86400))+" ← "+i18n("click2update");
  1260. }
  1261.  
  1262.  
  1263. updateP.className="updateDate";
  1264. updateP.innerHTML=passStr;
  1265. updateP.title=i18n("update")+" - "+pastDate;
  1266. updateP.onclick=e=>{
  1267. updateRules(()=>{
  1268. alert(i18n("updateSucc"));
  1269. updateP.innerHTML=i18n("passSec", 0);
  1270. updateP.title=i18n("update");
  1271. },rule=>{
  1272. alert("Update "+rule.url+" rules fail!");
  1273. });
  1274. alert(i18n("beginUpdate"));
  1275. };
  1276. configCon.insertBefore(updateP, insertPos);
  1277. if(ruleUrls){
  1278. ruleUrls.forEach(ruleUrl=>{
  1279. var rulebar=new Rulebar();
  1280. rulebar.init(ruleUrl);
  1281. });
  1282. }
  1283. let customUrlsTitle=document.createElement("h2");
  1284. customUrlsTitle.innerHTML=i18n("customUrls");
  1285. configCon.insertBefore(customUrlsTitle, insertPos);
  1286. let customUrlsInput=document.createElement("textarea");
  1287. customUrlsInput.style.width="100%";
  1288. customUrlsInput.placeholder="0|http://wedata.net/databases/AutoPagerize/items_all.json";
  1289. configCon.insertBefore(customUrlsInput, insertPos);
  1290.  
  1291. let opacityTitle=document.createElement("h2");
  1292. opacityTitle.innerHTML=i18n("opacity");
  1293. let opacityInput=document.createElement("input");
  1294. opacityInput.value=rulesData.opacity*100;
  1295. opacityInput.type="number";
  1296. opacityInput.style.width="50px";
  1297. opacityInput.style.margin="0 0 0 10px";
  1298. opacityTitle.appendChild(opacityInput);
  1299. configCon.insertBefore(opacityTitle, insertPos);
  1300.  
  1301.  
  1302. let hideBarTitle=document.createElement("h2");
  1303. hideBarTitle.innerHTML=i18n("hideBar");
  1304. let hideBarInput=document.createElement("input");
  1305. hideBarInput.type="checkbox";
  1306. hideBarInput.style.width="50px";
  1307. hideBarInput.style.height="20px";
  1308. hideBarInput.checked=rulesData.hideBar;
  1309. hideBarTitle.appendChild(hideBarInput);
  1310. configCon.insertBefore(hideBarTitle, insertPos);
  1311.  
  1312. let dbClick2StopTitle=document.createElement("h2");
  1313. dbClick2StopTitle.innerHTML=i18n("dbClick2Stop");
  1314. let dbClick2StopInput=document.createElement("input");
  1315. dbClick2StopInput.type="checkbox";
  1316. dbClick2StopInput.style.width="50px";
  1317. dbClick2StopInput.style.height="20px";
  1318. dbClick2StopInput.checked=rulesData.dbClick2Stop;
  1319. dbClick2StopTitle.appendChild(dbClick2StopInput);
  1320. configCon.insertBefore(dbClick2StopTitle, insertPos);
  1321.  
  1322. let enableWhiteListTitle=document.createElement("h2");
  1323. enableWhiteListTitle.innerHTML=i18n("autoRun");
  1324. let enableWhiteListInput=document.createElement("input");
  1325. enableWhiteListInput.type="checkbox";
  1326. enableWhiteListInput.style.width="50px";
  1327. enableWhiteListInput.style.height="20px";
  1328. enableWhiteListInput.checked=rulesData.enableWhiteList!=true;
  1329. enableWhiteListTitle.appendChild(enableWhiteListInput);
  1330. configCon.insertBefore(enableWhiteListTitle, insertPos);
  1331.  
  1332. let customRulesTitle=document.createElement("h2");
  1333. customRulesTitle.innerHTML=i18n("customRules")
  1334. configCon.insertBefore(customRulesTitle, insertPos);
  1335. let customRulesInput=document.createElement("textarea");
  1336. customRulesInput.style.width="100%";
  1337. customRulesInput.style.height="500px";
  1338. 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]`;
  1339. customRulesInput.value=getFormatJSON(ruleParser.customRules);
  1340. configCon.insertBefore(customRulesInput, insertPos);
  1341. let saveBtn=document.createElement("button");
  1342. saveBtn.innerHTML=i18n("save");
  1343. saveBtn.style.width="100%";
  1344. configCon.insertBefore(saveBtn, insertPos);
  1345. saveBtn.onclick=e=>{
  1346. try{
  1347. storage.setItem("hpRules", []);
  1348. if(customRulesInput.value==""){
  1349. storage.setItem("customRules", "");
  1350. }else{
  1351. let customRules=JSON.parse(customRulesInput.value);
  1352. if(Array && Array.isArray && !Array.isArray(customRules)){
  1353. alert("Rules must be a Array!");
  1354. return;
  1355. }
  1356. debug(customRules);
  1357. storage.setItem("customRules", customRules);
  1358. }
  1359. }catch(e){
  1360. debug(e);
  1361. alert("JSON error, check again!");
  1362. return;
  1363. }
  1364. rulesData.opacity=opacityInput.value/100;
  1365. rulesData.hideBar=hideBarInput.checked;
  1366. rulesData.dbClick2Stop=dbClick2StopInput.checked;
  1367. rulesData.enableWhiteList=!enableWhiteListInput.checked;
  1368. storage.setItem("rulesData", rulesData);
  1369. let customUrls=customUrlsInput.value.trim();
  1370. if(customUrls){
  1371. customUrls=customUrls.split(/\n/);
  1372. for(let c=0;c<customUrls.length;c++){
  1373. let urlArr=customUrls[c].split("|"),url,type=1;
  1374. if(urlArr.length==1){
  1375. url=urlArr[0].trim();
  1376. if(!/^http/.test(url)){
  1377. alert("Wrong url, check again!");
  1378. return;
  1379. }
  1380. }else if(urlArr.length==2){
  1381. type=urlArr[0].trim();
  1382. url=urlArr[1].trim();
  1383. if(!/^http/.test(url)){
  1384. alert("Wrong url, check again!");
  1385. return;
  1386. }
  1387. }else{
  1388. break;
  1389. }
  1390. let maxId=0,hasUrl=false;;
  1391. if(!rulesData.urls){
  1392. rulesData.urls=[];
  1393. maxId=1;
  1394. }else{
  1395. rulesData.urls.forEach(u=>{
  1396. if(maxId<u.id){
  1397. maxId=u.id;
  1398. }
  1399. if(u.url==url){
  1400. hasUrl=true;
  1401. }
  1402. });
  1403. if(hasUrl)break;
  1404. }
  1405. rulesData.urls.push({id:maxId+1,url:url,type:type});
  1406. rulesData.sort.push(maxId+1);
  1407. storage.setItem("rulesData", rulesData);
  1408. }
  1409. }
  1410. alert("Modified successfully");
  1411. location.reload();
  1412. };
  1413. return true;
  1414. }
  1415.  
  1416. var inUpdate=false;
  1417. function updateRules(success,fail){
  1418. if(inUpdate)return;
  1419. inUpdate=true;
  1420. let ruleIndex=0;
  1421. storage.setItem("hpRules", []);
  1422. function addNextRule(){
  1423. if(ruleIndex>=ruleUrls.length){
  1424. let now=new Date().getTime();
  1425. storage.setItem("ruleLastUpdate", now);
  1426. storage.setItem("rules", ruleParser.rules);
  1427. inUpdate=false;
  1428. success();
  1429. }else{
  1430. let rule=ruleUrls[ruleIndex++];
  1431. ruleParser.addRuleByUrl(rule.url, rule.type, rule.id, (json)=>{
  1432. if(!json){
  1433. fail(rule);
  1434. }
  1435. addNextRule();
  1436. })
  1437. }
  1438. }
  1439. addNextRule();
  1440. }
  1441.  
  1442. function objIsArr(obj) {
  1443. return obj &&
  1444. typeof obj === 'object' &&
  1445. typeof obj.length === 'number' &&
  1446. !(obj.propertyIsEnumerable('length'));
  1447. }
  1448.  
  1449. function isVisible(el, win) {
  1450. if(!el.offsetParent)return false;
  1451. var loopable = true,
  1452. visible = el.tagName && win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  1453. while(loopable && visible) {
  1454. el = el.parentNode;
  1455.  
  1456. if(el && el.tagName && el.tagName!="BODY") {
  1457. visible = win.getComputedStyle(el).display != 'none' && win.getComputedStyle(el).visibility != 'hidden';
  1458. }else {
  1459. loopable = false;
  1460. }
  1461. }
  1462. return visible;
  1463. }
  1464.  
  1465. function getFormatJSON(obj){
  1466. if(!objIsArr(obj))return "";
  1467. let ret="[\n";
  1468. let len=obj.length,i=0,isLast;
  1469. obj.forEach(item=>{
  1470. ret+=" {\n";
  1471. let iLen=Object.keys(item).length,j=0;
  1472. for(let key in item){
  1473. isLast=(++j)==iLen;
  1474. let value=item[key];
  1475. if(objIsArr(value)){
  1476. let vstr="[",v=0,vIsLast=false;
  1477. value.forEach(vi=>{
  1478. vIsLast=(++v)==value.length;
  1479. vstr+="\""+vi.replace(/\\/g,"\\\\")+"\""+(vIsLast?"":",");
  1480. });
  1481. vstr+="]";
  1482. ret+=" \""+key+"\":"+vstr+""+(isLast?"":",")+"\n";
  1483. }else{
  1484. if(typeof value=="string"){
  1485. value=value.replace(/\\/g,"\\\\").replace(/"/g,"\\\"");
  1486. value="\""+value+"\"";
  1487. }
  1488. ret+=" \""+key+"\":"+value+""+(isLast?"":",")+"\n";
  1489. }
  1490. }
  1491. isLast=(++i)==len;
  1492. ret+=" }"+(isLast?"":",")+"\n";
  1493. });
  1494. ret+="]";
  1495. return ret;
  1496. }
  1497.  
  1498. function initRules(callback) {
  1499. /*0 wedata格式,1 pagetual格式*/
  1500. ruleUrls=[
  1501. {
  1502. id:0,
  1503. url:'https://raw.githubusercontent.com/hoothin/UserScripts/master/Pagetual/pagetualRules.json',
  1504. type:1
  1505. },
  1506. {
  1507. id:1,
  1508. url:'http://wedata.net/databases/AutoPagerize/items_all.json',
  1509. type:0,
  1510. }
  1511. ];var i=0,j=0;
  1512.  
  1513. ruleParser.initSavedRules(()=>{
  1514. storage.getItem("rulesData", data=>{
  1515. if(data){
  1516. rulesData=data;
  1517. if(data.urls)ruleUrls=ruleUrls.concat(data.urls);
  1518. if(data.sort){
  1519. let urls=[];
  1520. data.sort.forEach(id=>{
  1521. for(let s=0;s<ruleUrls.length;s++){
  1522. if(id==ruleUrls[s].id){
  1523. urls.push(ruleUrls[s]);
  1524. break;
  1525. }
  1526. }
  1527. });
  1528. ruleUrls=urls;
  1529. }
  1530. }
  1531. if(typeof(rulesData.opacity)=="undefined"){
  1532. rulesData.opacity=0.3;
  1533. }
  1534. if(typeof(rulesData.hideBar)=="undefined"){
  1535. rulesData.hideBar=true;
  1536. }
  1537. if(typeof(rulesData.dbClick2Stop)=="undefined"){
  1538. rulesData.dbClick2Stop=true;
  1539. }
  1540. if(typeof(rulesData.enableWhiteList)=="undefined"){
  1541. rulesData.enableWhiteList=false;
  1542. }
  1543. storage.getItem("forceState_"+location.host, v=>{
  1544. storage.getItem("ruleLastUpdate", date=>{
  1545. if(typeof(v)=="undefined"){
  1546. v=(rulesData.enableWhiteList?1:0);
  1547. }
  1548. forceState=v;
  1549. updateDate=date;
  1550. if(initConfig())return;
  1551. if(forceState==1)return;
  1552. let now=new Date().getTime();
  1553. if(!date || now-date>2*24*60*60*1000){
  1554. storage.setItem("ruleLastUpdate", now);
  1555. updateRules(()=>{
  1556. callback();
  1557. },rule=>{});
  1558. }else{
  1559. callback();
  1560. }
  1561. });
  1562. });
  1563. });
  1564. });
  1565. }
  1566.  
  1567. function requestDoc(url, callback){
  1568. _GM_xmlhttpRequest({
  1569. url: url,
  1570. method: 'GET',
  1571. overrideMimeType: 'text/html;charset='+document.charset,
  1572. headers: {
  1573. 'Referer': location.href
  1574. },
  1575. timeout: 5000,
  1576. onload: function(res) {
  1577. var doc=null;
  1578. try {
  1579. doc=document.implementation.createHTMLDocument('');
  1580. doc.documentElement.innerHTML=res.response;
  1581. }
  1582. catch (e) {
  1583. debug('parse error'+e.toString());
  1584. }
  1585. let pageElement=ruleParser.getPageElement(doc);
  1586. //只有1的話怕不是圖片哦
  1587. if(pageElement && (pageElement.length>1 || (pageElement.length==1 && pageElement[0].tagName!="IMG") )){
  1588. let result=ruleParser.insertPage(doc, pageElement, url, callback, false);
  1589. if(!result){
  1590. requestFromIframe(url, (doc, eles)=>{
  1591. loadPageOver();
  1592. if(eles){
  1593. ruleParser.insertPage(doc, eles, url, callback, true);
  1594. }
  1595. });
  1596. }
  1597. }else if(ruleParser.curSiteRule.singleUrl){
  1598. requestFromIframe(url, (doc, eles)=>{
  1599. loadPageOver();
  1600. if(eles){
  1601. ruleParser.insertPage(doc, eles, url, callback, true);
  1602. }
  1603. });
  1604. }
  1605. },
  1606. onerror: function(e){
  1607. debug(e);
  1608. callback(false);
  1609. },
  1610. ontimeout: function(e){
  1611. debug(e);
  1612. callback(false);
  1613. }
  1614. });
  1615. }
  1616.  
  1617. var failFromIframe=0;
  1618. function requestFromIframe(url, callback){
  1619. let orgPage,curPage;
  1620. let iframe = document.createElement('iframe');
  1621. iframe.name = 'pagetual-iframe';
  1622. iframe.width = '100%';
  1623. iframe.height = '0';
  1624. iframe.frameBorder = '0';
  1625. if(ruleParser.curSiteRule.sandbox!=false){
  1626. iframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  1627. }
  1628. iframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  1629. iframe.addEventListener("load", e=>{
  1630. let waitTime=500,checkEval;
  1631. if(ruleParser.curSiteRule.wait){
  1632. if(isNaN(ruleParser.curSiteRule.wait)){
  1633. try{
  1634. checkEval=Function("doc",'"use strict";' + ruleParser.curSiteRule.wait);
  1635. }catch(e){
  1636. debug(e);
  1637. }
  1638. }else{
  1639. waitTime=ruleParser.curSiteRule.wait;
  1640. }
  1641. }
  1642. setTimeout(()=>{
  1643. let tryTimes=0;
  1644. function checkIframe(){
  1645. try{
  1646. let doc=iframe.contentDocument || iframe.contentWindow.document;
  1647. let eles=ruleParser.getPageElement(doc, iframe.contentWindow);
  1648. if(eles && eles.length>0 && (!checkEval || checkEval(doc))){
  1649. callback(doc, eles);
  1650. }else if(tryTimes++ < 10){
  1651. setTimeout(()=>{
  1652. checkIframe();
  1653. },waitTime);
  1654. return;
  1655. }else{
  1656. if(failFromIframe++ > 2){
  1657. failFromIframe=0;
  1658. debug("Stop as failFromIframe");
  1659. isPause=true;
  1660. callback(false, false);
  1661. }else{
  1662. callback(false, false);
  1663. }
  1664. }
  1665. }catch(e){
  1666. debug("Stop as cors");
  1667. //isPause=true;
  1668. ruleParser.curSiteRule.pageElement=allOfBody;
  1669. ruleParser.getInsert(true);
  1670. callback(false, false);
  1671. }
  1672. document.body.removeChild(iframe);
  1673. }
  1674. checkIframe();
  1675. },waitTime);
  1676. });
  1677. iframe.src=url;
  1678. document.body.appendChild(iframe);
  1679. }
  1680.  
  1681. function initPage(){
  1682. ruleParser.initPage(()=>{
  1683. if(ruleParser.nextLinkHref){
  1684. initView();
  1685. let isJs=/^(javascript|#)/.test(ruleParser.nextLinkHref.replace(location.href,""));
  1686. if(!isJs){
  1687. _GM_registerMenuCommand(i18n(forceState==2?"cancelForceIframe":"forceIframe"), ()=>{
  1688. storage.setItem("forceState_"+location.host, (forceState==2?"":2));
  1689. location.reload();
  1690. });
  1691. }
  1692. _GM_registerMenuCommand(i18n("loadNow"), ()=>{
  1693. let pageNum=window.prompt(i18n("loadConfirm"), "1");
  1694. if(pageNum==="" || pageNum===null)return;
  1695. pageNum=Math.abs(parseInt(pageNum));
  1696. autoLoadNum=pageNum;
  1697. nextPage();
  1698. });
  1699. }
  1700. initListener();
  1701. nextPage();
  1702. });
  1703. }
  1704.  
  1705. function initView(){
  1706. _GM_addStyle(`
  1707. .pagetual_pageBar.stop {
  1708. -webkit-filter: invert(100%);
  1709. filter: invert(100%);
  1710. opacity: 1!important;
  1711. }
  1712. .pagetual_pageBar.hide {
  1713. display: none!important;
  1714. }
  1715. .pagetual_pageBar:hover {
  1716. opacity: 1!important;
  1717. }
  1718. .pagetual_pageBar span {
  1719. vertical-align: super;
  1720. }
  1721.  
  1722. .pagetual_pageBar span>svg:hover {
  1723. animation: touhouAni 1s infinite;
  1724. }
  1725.  
  1726. @keyframes touhouAni{
  1727. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  1728. to {transform: rotate(360deg);}
  1729. }
  1730. @-webkit-keyframes touhouAni{
  1731. from {transform: rotate(0deg) scale3d(1.2, 1.2, 1.2);}
  1732. to {transform: rotate(360deg);}
  1733. }
  1734. `);
  1735. 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;`;
  1736. }
  1737. var loadingDiv=document.createElement("div");
  1738. loadingDiv.className="pagetual_loading";
  1739. 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;";
  1740. 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>`;
  1741.  
  1742. 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>`;
  1743. 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>`;
  1744. var pageBarStyle;
  1745. 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;`;
  1746. 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);`;
  1747.  
  1748. var isPause=false,isLoading=false,curPage=1,forceState=0,bottomGap=1000,autoLoadNum=-1;
  1749.  
  1750. function changeStop(stop, hide){
  1751. isPause=stop;
  1752. [].forEach.call(document.querySelectorAll(".pagetual_pageBar"), bar=>{
  1753. if(isPause){
  1754. bar.classList.add("stop");
  1755. if(hide)bar.classList.add("hide");
  1756. }else{
  1757. bar.classList.remove("stop");
  1758. if(hide)bar.classList.remove("hide");
  1759. }
  1760. });
  1761. }
  1762.  
  1763. function isInViewPort(element) {
  1764. if(!element.parentNode)return false;
  1765. if(_unsafeWindow.getComputedStyle(element).display=="none")return false;
  1766. const viewWidth = window.innerWidth || document.documentElement.clientWidth;
  1767. const viewHeight = window.innerHeight || document.documentElement.clientHeight;
  1768. const {
  1769. top,
  1770. right,
  1771. bottom,
  1772. left,
  1773. } = element.getBoundingClientRect();
  1774.  
  1775. return (
  1776. top >= 0 &&
  1777. left >= 0 &&
  1778. right <= viewWidth &&
  1779. bottom <= viewHeight
  1780. );
  1781. }
  1782.  
  1783. var urlChanged=false;
  1784. var _wr = function(type) {
  1785. var orig = history[type];
  1786. return function() {
  1787. var rv = orig.apply(this, arguments);
  1788. var e = new Event(type);
  1789. e.arguments = arguments;
  1790. window.dispatchEvent(e);
  1791. return rv;
  1792. };
  1793. };
  1794. history.pushState = _wr('pushState');
  1795. window.addEventListener('pushState', function(e) {
  1796. urlChanged=true;
  1797. setTimeout(()=>{
  1798. if(location.href==configPage){
  1799. location.reload();
  1800. }
  1801. },1);
  1802. });
  1803.  
  1804. function initListener(){
  1805. let loadmoreBtn,loading=true;
  1806. setTimeout(()=>{
  1807. loadmoreBtn=getLoadMore(document);
  1808. if(loadmoreBtn && isVisible(loadmoreBtn, _unsafeWindow)){
  1809. loading=false;
  1810. }
  1811. },500);
  1812. let checkScrollReach=()=>{
  1813. let scrolly=window.scrollY;
  1814. let windowHeight=window.innerHeight || document.documentElement.clientHeight;
  1815. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  1816. if(scrollH-scrolly-windowHeight<bottomGap){
  1817. nextPage();
  1818. }
  1819. };
  1820. document.addEventListener('scroll', e=>{
  1821. if(urlChanged){
  1822. ruleParser.initPage(()=>{
  1823. if(ruleParser.nextLinkHref)initView();
  1824. });
  1825. urlChanged=false;
  1826. isPause=false;
  1827. }
  1828. if(isPause)return;
  1829. if(!loading){
  1830. loading=true;
  1831. if(!loadmoreBtn || !loadmoreBtn.parentNode){
  1832. loadmoreBtn=getLoadMore(document);
  1833. }
  1834. if(loadmoreBtn){
  1835. loading=false;
  1836. if(isInViewPort(loadmoreBtn)){
  1837. emuClick(loadmoreBtn);
  1838. }
  1839. }else{
  1840. setTimeout(()=>{loading=false},500);
  1841. }
  1842. }
  1843. setTimeout(()=>{
  1844. if(!isLoading){
  1845. checkScrollReach();
  1846. }
  1847. },100);
  1848. }, true);
  1849. document.addEventListener('dblclick', e=>{
  1850. if(rulesData.dbClick2Stop){
  1851. setTimeout(()=>{
  1852. changeStop(!isPause, rulesData.hideBar);
  1853. if(!isPause){
  1854. checkScrollReach();
  1855. }
  1856. },200);
  1857. }
  1858. });
  1859. }
  1860.  
  1861. function getLoadMore(doc){
  1862. if(ruleParser.curSiteRule.loadMore==="")return null;
  1863. let btnSel=ruleParser.curSiteRule.loadMore||".LoadMore,.load-more";
  1864. let loadmoreBtn=doc.querySelector(btnSel);
  1865. if(!loadmoreBtn){
  1866. let buttons=doc.querySelectorAll("input,button,a,div[onclick]"),loadmoreReg=/^\s*(加载更多|加載更多|load\s*more|もっと読み込む)\s*$/i;
  1867. for(let i=0;i<buttons.length;i++){
  1868. let button=buttons[i];
  1869. if(button && loadmoreReg.test(button.innerText)){
  1870. loadmoreBtn=button;
  1871. break;
  1872. }
  1873. }
  1874. }
  1875. return loadmoreBtn;
  1876. }
  1877.  
  1878. function createPageBar(url){
  1879. let insert=ruleParser.getInsert();
  1880. if(!insert || !insert.parentNode)return;
  1881. curPage++;
  1882. let example=ruleParser.curSiteRule.insertPos==2?insert.children[0]:insert;
  1883. let inTable=example.parentNode.tagName=="TABLE" ||
  1884. example.tagName=="TR" ||
  1885. example.tagName=="TBODY" ||
  1886. (example.previousElementSibling && example.previousElementSibling.tagName=="TR") ||
  1887. (example.previousElementSibling && example.previousElementSibling.tagName=="TBODY");
  1888. let inLi=example.tagName=="LI" || (example.previousElementSibling && example.previousElementSibling.tagName=="LI");
  1889. let pageBar=document.createElement(inTable?"tr":"div");
  1890. let upSpan=document.createElement("span");
  1891. let downSpan=document.createElement("span");
  1892. let pageText=document.createElement("a");
  1893. pageBar.className="pagetual_pageBar";
  1894. pageBar.id="pagetual_pageBar";
  1895. if(isPause){
  1896. pageBar.classList.add("stop");
  1897. }
  1898. pageBar.style.cssText=pageBarStyle;
  1899. pageBar.title=i18n(isPause?"enable":"disable");
  1900. upSpan.innerHTML=upSvg;
  1901. upSpan.title=i18n("toTop");
  1902. downSpan.innerHTML=downSvg;
  1903. downSpan.title=i18n("toBottom");
  1904. upSpan.style.cssText=initStyle;
  1905. downSpan.style.cssText=initStyle;
  1906. pageText.href=url;
  1907. pageText.style=pageTextStyle;
  1908. pageText.innerHTML="Page "+curPage;
  1909. pageText.title=i18n("current");
  1910. pageBar.appendChild(upSpan);
  1911. pageBar.appendChild(pageText);
  1912. pageBar.appendChild(downSpan);
  1913. if(inTable){
  1914. example=(insert.tagName=="TR" || insert.tagName=="TBODY")?insert:insert.previousElementSibling;
  1915. if(example.previousElementSibling)example=example.previousElementSibling;
  1916. let tdNum=0;
  1917. [].forEach.call(example.querySelectorAll("td,th"), td=>{
  1918. tdNum+=td.colSpan||1;
  1919. });
  1920. pageBar.style.display="table-row";
  1921. pageBar.style.backgroundColor="unset";
  1922. let td=document.createElement("td");
  1923. td.style.backgroundColor="rgb(240 240 240 / 80%)";
  1924. td.style.borderRadius="20px";
  1925. td.colSpan=tdNum||1;
  1926. td.style.padding="0 0";
  1927. td.style.textAlign="center";
  1928. td.appendChild(upSpan);
  1929. td.appendChild(pageText);
  1930. td.appendChild(downSpan);
  1931. pageBar.appendChild(td);
  1932. }
  1933.  
  1934. upSpan.addEventListener("click", e=>{
  1935. //changeStop(true);
  1936. //pageBar.title=i18n(isPause?"enable":"disable");
  1937. document.body.scrollTop=0;
  1938. document.documentElement.scrollTop=0;
  1939. e.preventDefault();
  1940. e.stopPropagation();
  1941. });
  1942. downSpan.addEventListener("click", e=>{
  1943. changeStop(true);
  1944. pageBar.title=i18n(isPause?"enable":"disable");
  1945. document.body.scrollTop=9999999;
  1946. document.documentElement.scrollTop=9999999;
  1947. e.preventDefault();
  1948. e.stopPropagation();
  1949. });
  1950. pageBar.addEventListener("click", e=>{
  1951. changeStop(!isPause);
  1952. pageBar.title=i18n(isPause?"enable":"disable");
  1953. });
  1954. pageText.addEventListener("click", e=>{
  1955. e.stopPropagation();
  1956. });
  1957. let parentStyle=_unsafeWindow.getComputedStyle(insert.parentNode);
  1958. pageBar.style.width=parseInt(parentStyle.width)*.99-parseInt(parentStyle.paddingLeft)-parseInt(parentStyle.paddingRight)+"px";
  1959. if(inLi){
  1960. pageBar.style.width="90%";
  1961. pageBar.style.minWidth="150px";
  1962. pageBar.style.display="inline-block";
  1963. let line=document.createElement("li");
  1964. line.style.textAlign="center";
  1965. line.appendChild(pageBar);
  1966. if(ruleParser.curSiteRule.insertPos==2){
  1967. insert.appendChild(line);
  1968. }else{
  1969. insert.parentNode.insertBefore(line, insert);
  1970. }
  1971. }else{
  1972. if(ruleParser.curSiteRule.insertPos==2){
  1973. insert.appendChild(pageBar);
  1974. }else{
  1975. insert.parentNode.insertBefore(pageBar, insert);
  1976. }
  1977. }
  1978. if(ruleParser.curSiteRule.pageBar){
  1979. try{
  1980. Function("pageBar",'"use strict";' + ruleParser.curSiteRule.pageBar)(pageBar);
  1981. }catch(e){
  1982. debug(e);
  1983. }
  1984. }
  1985.  
  1986. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  1987. let actualTop = pageBar.offsetTop;
  1988. let current = pageBar.parentNode.offsetParent;
  1989. while (current !== null){
  1990. actualTop += current.offsetTop;
  1991. current = current.offsetParent;
  1992. }
  1993. bottomGap=scrollH-actualTop+(window.innerHeight||document.documentElement.clientHeight)*(ruleParser.curSiteRule.rate||1);
  1994. return pageBar;
  1995. }
  1996.  
  1997. function emuClick(btn){
  1998. if(!PointerEvent)return btn.click();
  1999. let eventParam={
  2000. isTrusted: true,
  2001. altKey: false,
  2002. azimuthAngle: 0,
  2003. bubbles: true,
  2004. button: 0,
  2005. buttons: 0,
  2006. clientX: 1,
  2007. clientY: 1,
  2008. cancelBubble: false,
  2009. cancelable: true,
  2010. composed: true,
  2011. ctrlKey: false,
  2012. defaultPrevented: false,
  2013. detail: 1,
  2014. eventPhase: 2,
  2015. fromElement: null,
  2016. height: 1,
  2017. isPrimary: false,
  2018. metaKey: false,
  2019. pointerId: 1,
  2020. pointerType: "mouse",
  2021. pressure: 0,
  2022. relatedTarget: null,
  2023. returnValue: true,
  2024. shiftKey: false,
  2025. toElement: null,
  2026. twist: 0,
  2027. type: "click",
  2028. which: 1
  2029. };
  2030. var mouseclick = new PointerEvent("click",eventParam);
  2031. btn.dispatchEvent(mouseclick);
  2032. }
  2033.  
  2034. var emuIframe;
  2035. function emuPage(callback){
  2036. let orgPage,curPage,iframeDoc,times=0,loadmoreBtn,loadmoreEnd=false,waitTimes=10;
  2037. function checkPage(){
  2038. if(isPause)return;
  2039. try{
  2040. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  2041. }catch(e){
  2042. debug("Stop as cors");
  2043. isPause=true;
  2044. callback(false, false);
  2045. return;
  2046. }
  2047.  
  2048. let nextLink=ruleParser.getNextLink(iframeDoc);
  2049. let waitTime=500,checkEval;
  2050. if(ruleParser.curSiteRule.wait){
  2051. if(isNaN(ruleParser.curSiteRule.wait)){
  2052. try{
  2053. checkEval=Function("doc",'"use strict";' + ruleParser.curSiteRule.wait);
  2054. }catch(e){
  2055. debug(e);
  2056. }
  2057. }else{
  2058. waitTime=ruleParser.curSiteRule.wait;
  2059. }
  2060. }
  2061.  
  2062. if(!orgPage){
  2063. if(!loadmoreEnd){
  2064. loadmoreBtn=getLoadMore(iframeDoc);
  2065. if(loadmoreBtn && isVisible(loadmoreBtn, iframeDoc.defaultView)){
  2066. emuClick(loadmoreBtn);
  2067. let intv=setInterval(()=>{
  2068. loadmoreBtn=getLoadMore(iframeDoc);
  2069. if(!loadmoreBtn || !loadmoreBtn.parentNode || !isVisible(loadmoreBtn, iframeDoc.defaultView)){
  2070. clearInterval(intv);
  2071. loadmoreEnd=true;
  2072. setTimeout(()=>{
  2073. checkPage();
  2074. },500);
  2075. }else{
  2076. emuClick(loadmoreBtn);
  2077. }
  2078. },200);
  2079. return;
  2080. }else{
  2081. loadmoreEnd=true;
  2082. }
  2083. }
  2084. let pageEle=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true);
  2085. if(!nextLink || !pageEle || (checkEval && !checkEval(iframeDoc))){
  2086. if(ruleParser.curSiteRule.wait && waitTimes-->0){
  2087. setTimeout(()=>{
  2088. checkPage();
  2089. },waitTime);
  2090. return;
  2091. }
  2092. }
  2093. orgPage=pageEle;
  2094. if(!orgPage || orgPage.length==0){
  2095. debug("Stop as no page when emu");
  2096. isPause=true;
  2097. callback(false, false);
  2098. return;
  2099. }
  2100. if(orgPage && orgPage[0].tagName=="UL")orgPage=orgPage[0].children;
  2101. if(orgPage && nextLink){
  2102. orgPage=orgPage[parseInt(orgPage.length/2)];
  2103. if(!isVisible(nextLink, iframeDoc.defaultView)){
  2104. debug("Stop as next hide when emu");
  2105. isPause=true;
  2106. callback(false, false);
  2107. }else{
  2108. emuClick(nextLink);
  2109. setTimeout(()=>{
  2110. checkPage();
  2111. },500);
  2112. }
  2113. }else{
  2114. debug("Stop as no next when emu");
  2115. isPause=true;
  2116. callback(false, false);
  2117. }
  2118. return;
  2119. }
  2120. if(times++ > 20){
  2121. //emuClick(nextLink);
  2122. debug("Stop as timeout when emu");
  2123. isPause=true;
  2124. callback(false, false);
  2125. return;
  2126. }
  2127. let eles=ruleParser.getPageElement(iframeDoc, iframeDoc.defaultView, true),checkItem=eles;
  2128. if(eles && eles.length>0 && eles[0].tagName=="UL")checkItem=eles[0].children;
  2129. if(!eles || eles.length==0 || orgPage == checkItem[parseInt(checkItem.length/2)] || (checkEval && !checkEval(iframeDoc))){
  2130. setTimeout(()=>{
  2131. checkPage();
  2132. },waitTime);
  2133. }else{
  2134. callback(iframeDoc, eles);
  2135. }
  2136. }
  2137. if(!emuIframe){
  2138. emuIframe = document.createElement('iframe');
  2139. emuIframe.name = 'pagetual-iframe';
  2140. if(ruleParser.curSiteRule.sandbox!=false){
  2141. emuIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  2142. }
  2143. emuIframe.width = '100%';
  2144. emuIframe.height = '0';
  2145. emuIframe.frameBorder = '0';
  2146. emuIframe.style.cssText = 'margin:0!important;padding:0!important;visibility:hidden!important;';
  2147. emuIframe.addEventListener("load", e=>{
  2148. setTimeout(()=>{
  2149. try{
  2150. iframeDoc=emuIframe.contentDocument || emuIframe.contentWindow.document;
  2151. }catch(e){
  2152. debug("Stop as cors");
  2153. isPause=true;
  2154. callback(false, false);
  2155. return;
  2156. }
  2157. let code=ruleParser.curSiteRule.init;
  2158. if(code){
  2159. try{
  2160. Function('doc','"use strict";' + code)(iframeDoc);
  2161. }catch(e){
  2162. debug(e);
  2163. }
  2164. }
  2165. checkPage();
  2166. },500);
  2167. });
  2168. emuIframe.src=location.href;
  2169. document.body.appendChild(emuIframe);
  2170. }else{
  2171. checkPage();
  2172. }
  2173. }
  2174.  
  2175. function forceIframe(url, callback){
  2176. let curIframe = document.createElement('iframe'),iframeDoc;
  2177. curIframe.name = 'pagetual-iframe';
  2178. curIframe.sandbox="allow-same-origin allow-scripts allow-popups allow-forms";
  2179. curIframe.frameBorder = '0';
  2180. curIframe.scrolling="no";
  2181. 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;';
  2182. curIframe.addEventListener("load", e=>{
  2183. try{
  2184. iframeDoc=curIframe.contentDocument || curIframe.contentWindow.document;
  2185. }catch(e){
  2186. debug("Stop as cors");
  2187. isPause=true;
  2188. callback(false, false);
  2189. return;
  2190. }
  2191. ruleParser.insertPage(iframeDoc, [], url, null, true);
  2192. callback(curIframe, true);
  2193. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  2194. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  2195. });
  2196. let inAction=false;
  2197. let forceRefresh=e=>{
  2198. if(inAction || !iframeDoc)return;
  2199. inAction=true;
  2200. setTimeout(()=>{
  2201. inAction=false;
  2202. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  2203. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  2204. if(!ruleParser.nextLinkHref){
  2205. ruleParser.getNextLink(iframeDoc);
  2206. if(ruleParser.nextLinkHref){
  2207. document.removeEventListener("scroll", forceRefresh);
  2208. }
  2209. }else{
  2210. document.removeEventListener("scroll", forceRefresh);
  2211. }
  2212. },500);
  2213. curIframe.style.height=iframeDoc.body.scrollHeight+"px";
  2214. curIframe.style.width=iframeDoc.body.scrollWidth+"px";
  2215. };
  2216. document.addEventListener("scroll", forceRefresh);
  2217. curIframe.src=url;
  2218. let insert=ruleParser.getInsert();
  2219. document.body.appendChild(curIframe);
  2220. return curIframe;
  2221. }
  2222.  
  2223. function loadPageOver(){
  2224. isLoading=false;
  2225. if(loadingDiv.parentNode){
  2226. loadingDiv.parentNode.removeChild(loadingDiv);
  2227. }
  2228. setTimeout(()=>{
  2229. let scrollH=Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
  2230. if(scrollH < (window.innerHeight || document.documentElement.clientHeight)){
  2231. nextPage();
  2232. }
  2233. },1);
  2234. }
  2235.  
  2236. function nextPage(){
  2237. if(isPause || isLoading)return;
  2238. let nextLink=ruleParser.nextLinkHref;
  2239. if(!nextLink)return;
  2240. let insert=ruleParser.getInsert();
  2241. if(insert){
  2242. let isJs=/^(javascript|#)/.test(nextLink.replace(location.href,""));
  2243. if(location.protocol=="https:" && /^http:/.test(nextLink)){
  2244. nextLink=nextLink.replace(/^http/,"https");
  2245. }
  2246. isLoading=true;
  2247. document.body.appendChild(loadingDiv);
  2248. let sleep=ruleParser.curSiteRule.sleep||0;
  2249. setTimeout(()=>{
  2250. if(ruleParser.curSiteRule.pageElementByJs){
  2251. var over=ele=>{
  2252. loadPageOver();
  2253. if(ele){
  2254. createPageBar(nextLink);
  2255. ruleParser.insertPage(null, ele, nextLink, null, true);
  2256. if(autoLoadNum>=0){
  2257. if(autoLoadNum!=0 && --autoLoadNum==0){
  2258. autoLoadNum=-1;
  2259. }else{
  2260. nextPage();
  2261. }
  2262. }
  2263. }else{
  2264. debug("Stop as no page when get by js");
  2265. isPause=true;
  2266. }
  2267. };
  2268. try{
  2269. Function("over",'"use strict";' + ruleParser.curSiteRule.pageElementByJs)(over);
  2270. }catch(e){
  2271. debug(e);
  2272. }
  2273. }else if(ruleParser.curSiteRule.action==1 && !isJs){
  2274. requestFromIframe(nextLink, (doc, eles)=>{
  2275. loadPageOver();
  2276. if(eles){
  2277. createPageBar(nextLink);
  2278. ruleParser.insertPage(doc, eles, nextLink, null, true);
  2279. if(autoLoadNum>=0){
  2280. if(autoLoadNum!=0 && --autoLoadNum==0){
  2281. autoLoadNum=-1;
  2282. }else{
  2283. nextPage();
  2284. }
  2285. }
  2286. }
  2287. });
  2288. }else if((forceState==2||ruleParser.curSiteRule.action==2) && !isJs){
  2289. forceIframe(nextLink, (iframe, eles)=>{
  2290. loadPageOver();
  2291. let pageBar=createPageBar(nextLink);
  2292. iframe.parentNode.insertBefore(pageBar, iframe);
  2293. if(autoLoadNum>=0){
  2294. if(autoLoadNum!=0 && --autoLoadNum==0){
  2295. autoLoadNum=-1;
  2296. }else{
  2297. nextPage();
  2298. }
  2299. }
  2300. });
  2301. }else{
  2302. if(!isJs){
  2303. requestDoc(nextLink, (eles)=>{
  2304. loadPageOver();
  2305. if(eles){
  2306. createPageBar(nextLink);
  2307. if(autoLoadNum>=0){
  2308. if(autoLoadNum!=0 && --autoLoadNum==0){
  2309. autoLoadNum=-1;
  2310. }else{
  2311. nextPage();
  2312. }
  2313. }
  2314. }
  2315. });
  2316. }else{
  2317. emuPage((doc, eles)=>{
  2318. loadPageOver();
  2319. if(eles){
  2320. createPageBar(nextLink);
  2321. ruleParser.insertPage(doc, eles, "", null, true);
  2322. if(autoLoadNum>=0){
  2323. if(autoLoadNum!=0 && --autoLoadNum==0){
  2324. autoLoadNum=-1;
  2325. }else{
  2326. nextPage();
  2327. }
  2328. }
  2329. }
  2330. });
  2331. }
  2332. }
  2333. },sleep);
  2334. }
  2335. }
  2336.  
  2337. function init(){
  2338. initRules(()=>{
  2339. initPage();
  2340. });
  2341. }
  2342. setTimeout(()=>{
  2343. init();
  2344. },300);
  2345. })();

QingJ © 2025

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