From 35437424398ac280d4a7a51583a9df4bb4ba4f63 Mon Sep 17 00:00:00 2001 From: caandt Date: Fri, 13 Sep 2024 19:25:36 -0500 Subject: [PATCH] delay songlist.json fetch until necessary --- static/music.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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); -})