summaryrefslogtreecommitdiff
path: root/main.js
blob: 818801bc372930c5203850628401dd5eaaad45ca (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
33
34
35
36
37
38
function enqueue(ids){
    ids.forEach(id => {
        fetch("/"+id)
    })
}
function delete_item(index){
    fetch(`/delete/${index}`)
}
function random(){
    fetch("/random")
}
function playlist(){
  let volume_slider = document.getElementById("volume")
  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)
        })
        volume_slider.value = res.volume * 100
    })
  }
  var intervalId = setInterval(f, 5000);
  f()

  volume_slider.onchange = function() {
    fetch(`/volume/${volume_slider.value/100}`)
  }
}
window.addEventListener('load', event => playlist());