// ==UserScript== // @name 麒麟听书 // @namespace czy // @version 1.0.0 // @description 麒麟听书爬取具体章节信息 // @author czy // @icon https://www.70ts.cc/favicon.ico // @match https://www.70ts.cc/tingshu/*.html // @grant GM_xmlhttpRequest // @grant unsafeWindow // @license MIT // @connect none // @require http://code.jquery.com/jquery-1.11.0.min.js // @downloadURL none // ==/UserScript== (function () { let newList=[]; let storyName; if(parseInt(window.location.href.substring(window.location.href.indexOf("tingshu/")).replace("tingshu/","")) && parseInt(window.location.href.substring(window.location.href.indexOf("tingshu/")).replace("tingshu/",""))!=NaN){ storyName = "tingshu"+parseInt(window.location.href.substring(window.location.href.indexOf("tingshu/")).replace("tingshu/","")); }else{ storyName = "tingshu"; } console.log("页面加载中") console.log("本地存储名:"+storyName) if(localStorage.getItem(storyName) != null){ newList = JSON.parse(localStorage.getItem(storyName)); }else{ localStorage.setItem(storyName,JSON.stringify(Array.from(new Set(newList)))); //window.location.href = $(".jump-list .pg-next")[0].href; } function unique(arr) { // 创建一个Map对象实例 const res = new Map() // 过滤条件:如果res中没有某个键,就设置这个键的值为1 return arr.filter((arr) => !res.has(arr.bookEpisode) && res.set(arr.bookEpisode, 1)) } window.onload=function(){ console.log("页面加载完成") setTimeout(()=>{ if(document.getElementById("play").contentWindow.document.getElementById("jp_audio_0").src !="" && document.getElementById("play").contentWindow.document.getElementById("jp_audio_0").src != undefined){ //console.log($(".list-book-dt a").text()); //console.log($(".content h1").text()); //console.log(document.getElementById("play").contentWindow.document.getElementById("jp_audio_0").src); //获取当前页有声书播放信息 let current = {bookName:$(".list-book-dt a").text(),bookEpisode:$(".content h1").text(),episodeUrl:document.getElementById("play").contentWindow.document.getElementById("jp_audio_0").src}; newList.push(current) localStorage.setItem(storyName,JSON.stringify(Array.from(unique(newList)))); console.log("爬取了:"+JSON.parse(localStorage.getItem(storyName)).length + "集"); if($("#nexturl")[0]){ setTimeout(()=>{ window.location=$("#nexturl")[0].href;//下一页 },10); }else{ alert("分析完毕,下载数据"); function sortData(a, b) { //str.substring(str.lastIndexOf("/")).replace(str.substring(str.lastIndexOf(".")),"").replace("/","") return ( (a.episodeUrl.substring(a.episodeUrl.lastIndexOf("/")).replace(a.episodeUrl.substring(a.episodeUrl.lastIndexOf(".")),"").replace("/","")) - (b.episodeUrl.substring(b.episodeUrl.lastIndexOf("/")).replace(b.episodeUrl.substring(b.episodeUrl.lastIndexOf(".")),"").replace("/","")) ) } let myList = JSON.parse(localStorage.getItem(storyName)); myList.sort(sortData); //将数据转为csv需要的格式 let csvString = [ ["bookName","bookEpisode","episodeUrl"], ...myList.map(item => [ item.bookName, item.bookEpisode.replace("正在播放:",""), item.episodeUrl ]) ].map(e => e.join(",")).join('\n') // 导出 let link = document.createElement("a") let exportContent = '\uFEFF' let blob = new Blob([exportContent+csvString],{ type:'text/plain;charset=utrf-8' }) link.id = "download-csv" link.setAttribute("href", URL.createObjectURL(blob)) link.setAttribute('download', storyName + ".csv") document.body.appendChild(link) link.click() } }else{ alert("失败"+ 'document.getElementById("play").contentWindow.document.getElementById("jp_audio_0").src'+"\n刷新该界面"); location.reload() } },100); } })();