Added ability to quickly prefill manual scrobble form with last scrobble

This commit is contained in:
Krateng 2020-08-16 20:08:17 +02:00
parent 3e1331b0e3
commit a88afe40ec
3 changed files with 48 additions and 21 deletions

View File

@ -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("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("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)))
print("\t" + col["blue"]("http://localhost:" + str(port) + "/setup")) print("\t" + col["blue"]("http://localhost:" + str(port) + "/admin_setup"))
return True return True
except: except:
print("Error while starting Maloja.") print("Error while starting Maloja.")

View File

@ -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) { 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() } if (event.key === "Backspace" && document.getElementById("artists").value == "") { removeArtist() }
} }
function addArtist() { function addEnteredArtist() {
element = document.getElementById("artists"); var newartistfield = document.getElementById("artists");
newartist = element.value.trim(); var newartist = newartistfield.value.trim();
element.value = ""; newartistfield.value = "";
if (newartist != "") { if (newartist != "") {
artist = document.createElement("span"); addArtist(newartist);
artist.innerHTML = newartist;
artist.style = "padding:5px;";
document.getElementById("artists_td").insertBefore(artist,element);
element.placeholder = "Backspace to remove last"
} }
} }
function removeArtist() { function removeArtist() {
artists = document.getElementById("artists_td").getElementsByTagName("span") var artists = document.getElementById("artists_td").getElementsByTagName("span")
lastartist = artists[artists.length-1] var lastartist = artists[artists.length-1]
document.getElementById("artists_td").removeChild(lastartist); document.getElementById("artists_td").removeChild(lastartist);
if (artists.length < 1) { if (artists.length < 1) {
document.getElementById("artists").placeholder = "Separate with Enter" 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) { function scrobbleIfEnter(event) {
if (event.key === "Enter") { if (event.key === "Enter") {
@ -33,19 +50,22 @@ function scrobbleIfEnter(event) {
} }
function scrobbleNew() { function scrobbleNew() {
artistnodes = document.getElementById("artists_td").getElementsByTagName("span"); var artistnodes = document.getElementById("artists_td").getElementsByTagName("span");
artists = []; var artists = [];
for (let node of artistnodes) { for (let node of artistnodes) {
artists.push(node.innerHTML); artists.push(node.innerHTML);
} }
title = document.getElementById("title").value; var title = document.getElementById("title").value;
scrobble(artists,title); scrobble(artists,title);
} }
function scrobble(artists,title) { function scrobble(artists,title) {
lastArtists = artists;
lastTrack = title;
artist = artists.join(";");
var artist = artists.join(";");
if (title != "" && artists.length > 0) { if (title != "" && artists.length > 0) {
xhttp = new XMLHttpRequest(); xhttp = new XMLHttpRequest();
@ -57,8 +77,7 @@ function scrobble(artists,title) {
document.getElementById("title").value = ""; document.getElementById("title").value = "";
document.getElementById("artists").value = ""; document.getElementById("artists").value = "";
parent = document.getElementById("artists_td"); var artists = document.getElementById("artists_td").getElementsByTagName("span");
artists = document.getElementById("artists_td").getElementsByTagName("span")
while (artists.length > 0) { while (artists.length > 0) {
removeArtist(); 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) { function search_manualscrobbling(searchfield) {
txt = searchfield.value; var txt = searchfield.value;
if (txt == "") { if (txt == "") {
} }

View File

@ -31,6 +31,7 @@
<br/> <br/>
<span class="button" onclick="scrobbleNew(event)">Scrobble!</span> <span class="button" onclick="scrobbleNew(event)">Scrobble!</span>
<span class="button" onclick="repeatLast()">Last Manual Scrobble</span>
<br/> <br/>