东方永页机

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

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