东方永页机

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

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

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

QingJ © 2025

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