1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

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("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.")

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) {
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 == "") {
}

View File

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