diff options
Diffstat (limited to 'main.js')
-rw-r--r-- | main.js | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -0,0 +1,32 @@ +function enqueue(ids){ + ids.forEach(id => { + fetch("/"+id) + }) +} +function delete_item(index){ + fetch(`/delete/${index}`) +} +function random(){ + fetch("/random") +} +function playlist(){ + function f(){ + fetch("/playlist").then(res => res.json()).then(res => { + let el = document.getElementById("playlist") + el.innerHTML = '' + res.items.forEach((song, i) => { + var li = document.createElement("li"); + let time = "(" + (song.duration/60).toFixed(2) + " minutes)" + let my_html = `<div><h2>${song.title}</h2> + <span class="time">${time}</span> + <button onclick="delete_item(${i})">X</button> + </div>` + li.innerHTML = my_html + el.appendChild(li) + }) + }) + } + var intervalId = setInterval(f, 5000); + f() +} +window.addEventListener('load', event => playlist()); |