Last active
September 25, 2020 09:12
-
-
Save lljxx1/399d5b5ae300f53d9c40022b35f30da2 to your computer and use it in GitHub Desktop.
虾米音乐收藏歌单导出
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var uid = _xiamiuser.split('"')[0]; | |
if(!uid) alert('uid'); | |
localStorage.clear(); | |
var iframe = document.createElement('iframe'); | |
iframe.src="https://emumo.xiami.com/space/lib-song/u/"+uid; | |
document.body.appendChild(iframe); | |
iframe.onload = function(){ | |
console.log("loaded") | |
getSongs(); | |
var nextLink = iframe.contentWindow.document.getElementsByClassName('p_redirect_l'); | |
if(nextLink.length){ | |
var nextPage = nextLink[0].href; | |
if(nextPage != iframe.src) { | |
iframe.src = nextPage; | |
console.log(nextPage) | |
console.log("done") | |
} | |
}else{ | |
console.log("done") | |
} | |
} | |
function getSongs(){ | |
var songs = []; | |
if(localStorage.getItem('songs')){ | |
songs = JSON.parse(localStorage.getItem('songs')); | |
} | |
var tds = iframe.contentWindow.document.getElementsByClassName('song_name'); | |
for (var i = 0; i < tds.length; i++) { | |
var td = tds[i]; | |
var tdas = td.getElementsByTagName('a'); | |
var titleA = tdas[0]; | |
var artistA = tdas[1]; | |
songs.push([titleA['title'], artistA.innerText].join(" - ")); | |
} | |
localStorage.setItem('songs', JSON.stringify(songs)); | |
} | |
setInterval(function(){ | |
try{ | |
var songs = JSON.parse(localStorage.getItem('songs')); | |
console.log("已完成", songs.length, songs[songs.length -1]); | |
}catch(e){} | |
}, 3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment