From a88afe40ec5068b849141dee274543aed049a0bc Mon Sep 17 00:00:00 2001 From: Krateng Date: Sun, 16 Aug 2020 20:08:17 +0200 Subject: [PATCH] Added ability to quickly prefill manual scrobble form with last scrobble --- maloja/proccontrol/control.py | 2 +- maloja/static/js/manualscrobble.js | 66 ++++++++++++++++++++--------- maloja/web/jinja/admin_manual.jinja | 1 + 3 files changed, 48 insertions(+), 21 deletions(-) diff --git a/maloja/proccontrol/control.py b/maloja/proccontrol/control.py index d0cf53e..12c4342 100644 --- a/maloja/proccontrol/control.py +++ b/maloja/proccontrol/control.py @@ -43,7 +43,7 @@ def start(): print("Visit your server address (Port " + str(port) + ") to see your web interface. Visit /setup to get started.") print("If you're installing this on your local machine, these links should get you there:") print("\t" + col["blue"]("http://localhost:" + str(port))) - print("\t" + col["blue"]("http://localhost:" + str(port) + "/setup")) + print("\t" + col["blue"]("http://localhost:" + str(port) + "/admin_setup")) return True except: print("Error while starting Maloja.") diff --git a/maloja/static/js/manualscrobble.js b/maloja/static/js/manualscrobble.js index 8b24c30..03ce272 100644 --- a/maloja/static/js/manualscrobble.js +++ b/maloja/static/js/manualscrobble.js @@ -1,30 +1,47 @@ +var lastArtists = [] +var lastTrack = "" + + +function addArtist(artist) { + var newartistfield = document.getElementById("artists"); + var artistelement = document.createElement("span"); + artistelement.innerHTML = artist; + artistelement.style = "padding:5px;"; + document.getElementById("artists_td").insertBefore(artistelement,newartistfield); + newartistfield.placeholder = "Backspace to remove last" +} + function keyDetect(event) { - if (event.key === "Enter" || event.key === "Tab") { addArtist() } + if (event.key === "Enter" || event.key === "Tab") { addEnteredArtist() } if (event.key === "Backspace" && document.getElementById("artists").value == "") { removeArtist() } } -function addArtist() { - element = document.getElementById("artists"); - newartist = element.value.trim(); - element.value = ""; +function addEnteredArtist() { + var newartistfield = document.getElementById("artists"); + var newartist = newartistfield.value.trim(); + newartistfield.value = ""; if (newartist != "") { - artist = document.createElement("span"); - artist.innerHTML = newartist; - artist.style = "padding:5px;"; - document.getElementById("artists_td").insertBefore(artist,element); - - element.placeholder = "Backspace to remove last" + addArtist(newartist); } } function removeArtist() { - artists = document.getElementById("artists_td").getElementsByTagName("span") - lastartist = artists[artists.length-1] + var artists = document.getElementById("artists_td").getElementsByTagName("span") + var lastartist = artists[artists.length-1] document.getElementById("artists_td").removeChild(lastartist); if (artists.length < 1) { document.getElementById("artists").placeholder = "Separate with Enter" } } +function clear() { + document.getElementById("title").value = ""; + document.getElementById("artists").value = ""; + var artists = document.getElementById("artists_td").getElementsByTagName("span") + while (artists.length > 0) { + removeArtist(); + } +} + function scrobbleIfEnter(event) { if (event.key === "Enter") { @@ -33,19 +50,22 @@ function scrobbleIfEnter(event) { } function scrobbleNew() { - artistnodes = document.getElementById("artists_td").getElementsByTagName("span"); - artists = []; + var artistnodes = document.getElementById("artists_td").getElementsByTagName("span"); + var artists = []; for (let node of artistnodes) { artists.push(node.innerHTML); } - title = document.getElementById("title").value; + var title = document.getElementById("title").value; scrobble(artists,title); } function scrobble(artists,title) { + lastArtists = artists; + lastTrack = title; - artist = artists.join(";"); + + var artist = artists.join(";"); if (title != "" && artists.length > 0) { xhttp = new XMLHttpRequest(); @@ -57,8 +77,7 @@ function scrobble(artists,title) { document.getElementById("title").value = ""; document.getElementById("artists").value = ""; - parent = document.getElementById("artists_td"); - artists = document.getElementById("artists_td").getElementsByTagName("span") + var artists = document.getElementById("artists_td").getElementsByTagName("span"); while (artists.length > 0) { removeArtist(); } @@ -76,6 +95,13 @@ function scrobbledone() { } +function repeatLast() { + clear(); + for (let artist of lastArtists) { + addArtist(artist); + } + document.getElementById("title").value = lastTrack; +} @@ -84,7 +110,7 @@ function scrobbledone() { /// function search_manualscrobbling(searchfield) { - txt = searchfield.value; + var txt = searchfield.value; if (txt == "") { } diff --git a/maloja/web/jinja/admin_manual.jinja b/maloja/web/jinja/admin_manual.jinja index 6c9a6f5..5f55c60 100644 --- a/maloja/web/jinja/admin_manual.jinja +++ b/maloja/web/jinja/admin_manual.jinja @@ -31,6 +31,7 @@
Scrobble! + Last Manual Scrobble