blob: 2fc009851d8f94e54000999cd8fb3badf83614d1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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());
|