Updated manual scrobbling, GH-68

This commit is contained in:
Krateng 2021-01-10 15:45:59 +01:00
parent c86f3597fd
commit 5bfd1e49dd

View File

@ -64,15 +64,13 @@ function scrobble(artists,title) {
lastArtists = artists; lastArtists = artists;
lastTrack = title; lastTrack = title;
var payload = {
var artist = artists.join(";"); "artists":artists,
"title":title
}
if (title != "" && artists.length > 0) { if (title != "" && artists.length > 0) {
xhttp = new XMLHttpRequest(); neo.xhttpreq("/apis/mlj_1/newscrobble",data=payload,method="POST",callback=scrobbledone,json=true)
xhttp.onreadystatechange = scrobbledone
xhttp.open("GET","/api/newscrobble?artist=" + encodeURIComponent(artist) +
"&title=" + encodeURIComponent(title), true);
xhttp.send();
} }
document.getElementById("title").value = ""; document.getElementById("title").value = "";
@ -83,14 +81,12 @@ function scrobble(artists,title) {
} }
} }
function scrobbledone() { function scrobbledone(req) {
if (this.readyState == 4 && this.status == 200) { result = req.response;
result = JSON.parse(this.responseText); txt = result["track"]["title"] + " by " + result["track"]["artists"][0];
txt = result["track"]["title"] + " by " + result["track"]["artists"][0]; if (result["track"]["artists"].length > 1) {
if (result["track"]["artists"].length > 1) { txt += " et al.";
txt += " et al."; document.getElementById("notification").innerHTML = "Scrobbled " + txt + "!";
}
document.getElementById("notification").innerHTML = "Scrobbled " + txt + "!";
} }
} }