东方永页机

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

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