summaryrefslogtreecommitdiff
path: root/main.js
diff options
context:
space:
mode:
Diffstat (limited to 'main.js')
-rw-r--r--main.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/main.js b/main.js
new file mode 100644
index 0000000..2fc0098
--- /dev/null
+++ b/main.js
@@ -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());