diff --git a/static/music.js b/static/music.js index 414d1d4..32adf35 100644 --- a/static/music.js +++ b/static/music.js @@ -59,10 +59,17 @@ function addVolume(n) { setVol(Number(localStorage.getItem('volume') ?? Math.ceil(n / 2)))(); music.appendChild(vol); } -fetch('/static/songlist.json').then(e => e.json()).then(songs => { +let songs = []; +function playSong() { + fetch('/static/songlist.json').then(e => e.json()).then(e => { + songs = e; + shuffle(songs); + playSong = _playSong; + _playSong() + }); +} let n = 0; - shuffle(songs); - function playSong() { + function _playSong() { let song = songs[n] ?? songs[n = 0]; audio.src = song.href; if (song.src) popup(`\u266b - ${song.src} (${song.artist}) - ${song.name}`); @@ -96,4 +103,3 @@ fetch('/static/songlist.json').then(e => e.json()).then(songs => { playSong(++n); }); addVolume(5); -})