东方永页机

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

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

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