From 09a0be0bd5d119c177ee18b692e84fb4ba49a129 Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Sat, 24 Sep 2022 21:51:24 -0500 Subject: Add delete function and prettify now playing a bit --- index.js | 52 +++++++++++++++++++++++++++++----------------------- main.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 23 deletions(-) create mode 100644 main.js diff --git a/index.js b/index.js index a3bd2d8..521a28d 100644 --- a/index.js +++ b/index.js @@ -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; } - - + +

Now playling

      @@ -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") 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 = `

      ${song.title}

      + ${time} + +
      ` + li.innerHTML = my_html + el.appendChild(li) + }) + }) + } + var intervalId = setInterval(f, 5000); + f() +} +window.addEventListener('load', event => playlist()); -- cgit v1.2.3