delay songlist.json fetch until necessary
This commit is contained in:
parent
95423a7e4d
commit
3543742439
|
|
@ -59,10 +59,17 @@ function addVolume(n) {
|
||||||
setVol(Number(localStorage.getItem('volume') ?? Math.ceil(n / 2)))();
|
setVol(Number(localStorage.getItem('volume') ?? Math.ceil(n / 2)))();
|
||||||
music.appendChild(vol);
|
music.appendChild(vol);
|
||||||
}
|
}
|
||||||
fetch('/static/songlist.json').then(e => e.json()).then(songs => {
|
let songs = [];
|
||||||
let n = 0;
|
|
||||||
shuffle(songs);
|
|
||||||
function playSong() {
|
function playSong() {
|
||||||
|
fetch('/static/songlist.json').then(e => e.json()).then(e => {
|
||||||
|
songs = e;
|
||||||
|
shuffle(songs);
|
||||||
|
playSong = _playSong;
|
||||||
|
_playSong()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
let n = 0;
|
||||||
|
function _playSong() {
|
||||||
let song = songs[n] ?? songs[n = 0];
|
let song = songs[n] ?? songs[n = 0];
|
||||||
audio.src = song.href;
|
audio.src = song.href;
|
||||||
if (song.src) popup(`\u266b - ${song.src} (${song.artist}) - ${song.name}`);
|
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);
|
playSong(++n);
|
||||||
});
|
});
|
||||||
addVolume(5);
|
addVolume(5);
|
||||||
})
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue