Perpetual pages - powerful auto-pager script. Auto fetching next paginated web pages and inserting into current page for infinite scroll. Support thousands of web sites without any rule.
{ "name": "漫画猫 - 閱讀 - 測試", "example": "https://www.maofly.com/manga/39027/515484.html", "url": "^https?://www\\.maofly\\.com/manga/", "pinUrl": true, "history": 2, "action": 1, "wait": 1000, "init": "function setNext(){let vgrdata=document.querySelector('.vg-r-data');let num=vgrdata.getAttribute('data-chapter_num');let type=vgrdata.getAttribute('data-chapter-type');let n=1;$.ajax({type:'get',url:'/chapter_num?chapter_id='+num+'&ctype='+n+'&type='+type,dataType:'json',success:function(json){let ne=document.querySelectorAll(\"a[href*='next']\");if(json.code!='0000'){ne.forEach(e=>{e.remove()})}else{ne.forEach(e=>{e.href=json.url})}}})}setNext();let vgrdata=document.querySelector('.vg-r-data');let code=Array.from(document.scripts).find(s=>s.innerHTML.search(/img_data/)>-1).innerHTML;let Base64=eval(code.match(/img_data = \".+\"/g)[0]);let imgData=LZString.decompressFromBase64(Base64).split(',');let imgPre='/uploads/';let assetDomain=vgrdata.getAttribute('data-chapter-domain');let assetKey=vgrdata.getAttribute('data-chapter-key');let _img='';for(let i=0;i`};document.querySelector('.img-content').innerHTML=_img;", "nextLink": "a[title=下集]", "pageElement": ".img-content", "replaceElement": "head>title,.breadcrumb-item.active,.h4.text-center", "pageInit": "function setNext(){let vgrdata=doc.querySelector('.vg-r-data');let num=vgrdata.getAttribute('data-chapter_num');let type=vgrdata.getAttribute('data-chapter-type');let n=1;$.ajax({type:'get',url:'/chapter_num?chapter_id='+num+'&ctype='+n+'&type='+type,dataType:'json',success:function(json){let ne=doc.querySelectorAll(\"a[href*='next']\");if(json.code!='0000'){ne.forEach(e=>{e.remove()})}else{ne.forEach(e=>{e.href=json.url})}}})}setNext();let vgrdata=doc.querySelector('.vg-r-data');let code=Array.from(doc.scripts).find(s=>s.innerHTML.search(/img_data/)>-1).innerHTML;let Base64=eval(code.match(/img_data = \".+\"/g)[0]);let imgData=LZString.decompressFromBase64(Base64).split(',');let imgPre='/uploads/';let assetDomain=vgrdata.getAttribute('data-chapter-domain');let assetKey=vgrdata.getAttribute('data-chapter-key');let _img='';for(let i=0;i`};doc.querySelector('.img-content').innerHTML=_img;", "pageAction": "function geAll(e){return document.querySelectorAll(e)};setTimeout(()=>{let c=geAll('.img-content');if(c.length>2){c[0].remove()}let p=geAll('.pagetual_pageBar');if(p.length>2){p[0].remove()}},200)", "pageBarText": 1, "css": "a[onclick],a[href*='false']{display:none!important}.img-content>img{width:auto!important;height:auto!important;max-width:100%!important;display:block!important;margin:0 auto !important}" }, { "name": "漫画DB - 閱讀 測試", "example": "https://www.manhuadb.com/manhua/1167/1315_13028.html", "url": "^https?://www\\.manhuadb\\.com/manhua/\\d+/\\w+\\.html", "pinUrl": true, "history": 2, "action": 1, "wait": 1000, "init": "function setNext(){let vgrdata=document.querySelector('.vg-r-data');let num=vgrdata.getAttribute('data-num');let nnum=parseInt(num)+1;let pccid=vgrdata.getAttribute('data-ccid');let pid=vgrdata.getAttribute('data-id');let pd=vgrdata.getAttribute('data-d');$.ajax({type:'post',url:'/book/goNumPage',data:{ccid:pccid,id:pid,num:nnum,d:pd,type:'next'},dataType:'json',success:function(json){let ne=document.querySelectorAll(\"a[href*='next']\");if(json.state==0){ne.forEach(e=>{e.remove()})}else{ne.forEach(e=>{e.href=json.url})}}})}setNext();let code=Array.from(document.scripts).find(s=>s.innerHTML.search(/img_data/)>-1).innerHTML;let Base64=eval(code.replace('var ',''));let imgData=eval(atob(Base64));let vgrdata=document.querySelector('.vg-r-data');let imgHost=vgrdata.getAttribute('data-host');let imgPre=vgrdata.getAttribute('data-img_pre');let _img='';for(let i=0;i`}else{_img+=``}};document.querySelector('#all').innerHTML=_img;", "nextLink": "a[title=下集]", "pageElement": "#all", "replaceElement": "head>title,h4.text-center,ol.breadcrumb", "pageInit": "function setNext(){let vgrdata=doc.querySelector('.vg-r-data');let num=vgrdata.getAttribute('data-num');let nnum=parseInt(num)+1;let pccid=vgrdata.getAttribute('data-ccid');let pid=vgrdata.getAttribute('data-id');let pd=vgrdata.getAttribute('data-d');$.ajax({type:'post',url:'/book/goNumPage',data:{ccid:pccid,id:pid,num:nnum,d:pd,type:'next'},dataType:'json',success:function(json){let ne=doc.querySelectorAll(\"a[href*='next']\");if(json.state==0){ne.forEach(e=>{e.remove()})}else{ne.forEach(e=>{e.href=json.url})}}})}setNext();let code=Array.from(doc.scripts).find(s=>s.innerHTML.search(/img_data/)>-1).innerHTML;let Base64=eval(code.replace('var ',''));let imgData=eval(atob(Base64));let vgrdata=doc.querySelector('.vg-r-data');let imgHost=vgrdata.getAttribute('data-host');let imgPre=vgrdata.getAttribute('data-img_pre');let _img='';for(let i=0;i`}else{_img+=`
`}};doc.querySelector('#all').innerHTML=_img;", "pageAction": "function geAll(e){return document.querySelectorAll(e)};setTimeout(()=>{let c=geAll('#all');if(c.length>2){c[0].remove()}let p=geAll('.pagetual_pageBar');if(p.length>2){p[0].remove()}},200)", "pageBarText": 1, "css": "nav.d-none+div.row,#left,#right,.pagination .form-inline>*:nth-child(n+2):nth-child(-n+4){display:none!important}.row>*{padding:0px!important}#all,img{width:auto!important;height:auto!important;max-width:100%!important;display:block!important;margin:0 auto !important}" }
總算是試出可行的方案了,先修改下一頁元素的href,然後延遲遍歷下一頁元素。
需要修改腳本
getNextLink(doc) { let nextLink = null, page, href; setTimeout(() => { 延遲執行的代碼 }, 1000) return nextLink; }
感謝反饋,已經把nextLinkByJs改成異步函數了,返回一個promise,監聽ajax返回執行resolve就行,或者用fetch取代原本的$.ajax
感謝反饋,已經把nextLinkByJs改成異步函數了,返回一個promise,監聽ajax返回執行resolve就行,或者用fetch取代原本的$.ajax
google搜索研究學習了一下promise、fetch,總算搞定這個問題了。
{ "name": "漫画猫 - 閱讀", "example": "https://www.maofly.com/manga/39027/515484.html", "url": "^https?://www\\.maofly\\.com/manga/", "pinUrl": true, "history": 2, "init": "let vgrdata=document.querySelector('.vg-r-data');let code=Array.from(document.scripts).find(s=>s.innerHTML.search(/img_data/)>-1).innerHTML;let Base64=eval(code.match(/img_data = \".+\"/g)[0]);let imgData=LZString.decompressFromBase64(Base64).split(',');let imgPre='/uploads/';let assetDomain=vgrdata.getAttribute('data-chapter-domain');let assetKey=vgrdata.getAttribute('data-chapter-key');let _img='';for(let i=0;i`};document.querySelector('.img-content').innerHTML=_img;", "nextLinkByJs": "let vgrdata=doc.querySelector('.vg-r-data');let num=vgrdata.getAttribute('data-chapter_num');let type=vgrdata.getAttribute('data-chapter-type');let n=1;let json='/chapter_num?chapter_id='+num+'&ctype='+n+'&type='+type;return fetch(json).then((response)=>{return response.json()}).then((json)=>{if(json.code!='0000'){return null}else{return json.url}}).then((res)=>{return res});", "pageElement": ".img-content", "replaceElement": "head>title,.breadcrumb-item.active,.h4.text-center", "pageInit": "let vgrdata=doc.querySelector('.vg-r-data');let code=Array.from(doc.scripts).find(s=>s.innerHTML.search(/img_data/)>-1).innerHTML;let Base64=eval(code.match(/img_data = \".+\"/g)[0]);let imgData=LZString.decompressFromBase64(Base64).split(',');let imgPre='/uploads/';let assetDomain=vgrdata.getAttribute('data-chapter-domain');let assetKey=vgrdata.getAttribute('data-chapter-key');let _img='';for(let i=0;i`};doc.querySelector('.img-content').innerHTML=_img;", "pageAction": "function geAll(e){return document.querySelectorAll(e)};setTimeout(()=>{let c=geAll('.img-content');if(c.length>2){c[0].remove()}let p=geAll('.pagetual_pageBar');if(p.length>2){p[0].remove()}},200)", "pageBarText": 1, "css": "a[onclick],a[href*='false']{display:none!important}.img-content>img{width:auto!important;height:auto!important;max-width:100%!important;display:block!important;margin:0 auto !important}" }, { "name": "漫画DB - 閱讀", "example": "https://www.manhuadb.com/manhua/1167/1315_13028.html", "url": "^https?://www\\.manhuadb\\.com/manhua/\\d+/\\w+\\.html", "pinUrl": true, "history": 2, "init": "let code=Array.from(document.scripts).find(s=>s.innerHTML.search(/img_data/)>-1).innerHTML;let Base64=eval(code.replace('var ',''));let imgData=eval(atob(Base64));let vgrdata=document.querySelector('.vg-r-data');let imgHost=vgrdata.getAttribute('data-host');let imgPre=vgrdata.getAttribute('data-img_pre');let _img='';for(let i=0;i`}else{_img+=``}};document.querySelector('#all').innerHTML=_img;", "nextLinkByJs": "return new Promise((resolve)=>{let vgrdata=doc.querySelector('.vg-r-data');let num=vgrdata.getAttribute('data-num');let nnum=parseInt(num)+1;let pccid=vgrdata.getAttribute('data-ccid');let pid=vgrdata.getAttribute('data-id');let pd=vgrdata.getAttribute('data-d');$.ajax({type:'post',url:'/book/goNumPage',data:{ccid:pccid,id:pid,num:nnum,d:pd,type:'next'},dataType:'json',success:function(json){if(json.state==0){resolve(null)}else{let url=json.url;resolve(location.origin+url)}}})}).then((res)=>{return res});", "pageElement": "#all", "replaceElement": "head>title,.h4.text-center,ol.breadcrumb", "pageInit": "let code=Array.from(doc.scripts).find(s=>s.innerHTML.search(/img_data/)>-1).innerHTML;let Base64=eval(code.replace('var ',''));let imgData=eval(atob(Base64));let vgrdata=doc.querySelector('.vg-r-data');let imgHost=vgrdata.getAttribute('data-host');let imgPre=vgrdata.getAttribute('data-img_pre');let _img='';for(let i=0;i`}else{_img+=`
`}};doc.querySelector('#all').innerHTML=_img;", "pageAction": "function geAll(e){return document.querySelectorAll(e)};setTimeout(()=>{let c=geAll('#all');if(c.length>2){c[0].remove()}let p=geAll('.pagetual_pageBar');if(p.length>2){p[0].remove()}},200)", "pageBarText": 1, "css": "nav.d-none+div.row,#left,#right,.pagination .form-inline>*:nth-child(n+2):nth-child(-n+4){display:none!important}.row>*{padding:0px!important}#all,img{width:auto!important;height:auto!important;max-width:100%!important;display:block!important;margin:0 auto !important}" }
求助 這種類型的怎麼寫nextLinkByJs才能正確返回下一頁連結
上面兩個規則直接用"nextLink": "a[title=下集]"就能取得下一頁,可是有缺點沒有元素或變數可以用來判斷已達最後一頁,"history": 2插入後也不能紀錄history。
所以提取出了取得下一話的代碼如下
放到主控台運行是能輸出下一話連結的
但是用nextLinkByJs卻不能返回下一話連結