diff options
author | Mark Powers <mark@marks.kitchen> | 2022-09-24 21:51:24 -0500 |
---|---|---|
committer | Mark Powers <mark@marks.kitchen> | 2022-09-24 21:51:24 -0500 |
commit | 09a0be0bd5d119c177ee18b692e84fb4ba49a129 (patch) | |
tree | e58e9f86ef452056f21a9a4999f5a6d862a77857 | |
parent | 1e04f311e6f84c19af2cf8795fc892d8f0242f5d (diff) |
Add delete function and prettify now playing a bit
-rw-r--r-- | index.js | 52 | ||||
-rw-r--r-- | main.js | 32 |
2 files changed, 61 insertions, 23 deletions
@@ -166,36 +166,28 @@ server.get('/', async (req, res) => { margin-left: 2em; font-style: italic; } + span.time { + font-style: italic; + } div.container { display: flex; flex-wrap: wrap; } - </style> - <script> - function enqueue(ids){ - ids.forEach(id => { - fetch("/"+id) - }) + h2 { + margin: 0; + font-size: 16px; + display: inline; + margin-right: 1em; } - function random(){ - fetch("/random") + li { + border: 1px solid gray; + margin: 0.5em; } - function playlist(){ - var intervalId = setInterval(function() { - fetch("/playlist").then(res => res.json()).then(res => { - let el = document.getElementById("playlist") - el.innerHTML = '' - res.items.forEach(song => { - var li = document.createElement("li"); - let text = song.title + " (" + (song.duration/60).toFixed(2) + " minutes)" - li.appendChild(document.createTextNode(text)) - el.appendChild(li) - }) - }) - }, 5000); + li button { + float: right; } - window.addEventListener('load', event => playlist()); - </script> + </style> + <script src="/main.js"></script> <div> <h1>Now playling</h1> <ol id="playlist"><ol> @@ -251,6 +243,20 @@ server.get('/playlist', async (req, res, next) => { res.send(playlist_items) }) +server.get('/main.js', async (req, res, next) => { + res.sendFile(__dirname + "/main.js") +}) + +server.get('/delete/:id', async (req, res, next) => { + fetch(`${config.baseURL}/post`, { + "credentials": "include", + "headers": headers(), + "body": `delete_music=${req.params.id}`, + "method": "POST", + }) + res.send("ok") +}) + server.get('/:id', async (req, res, next) => { enqueue(req.params.id) res.send("ok") @@ -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()); |