mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Added albums to manual scrobbling
This commit is contained in:
parent
501984d04e
commit
d5c457a2e9
@ -26,6 +26,21 @@
|
||||
<input placeholder='Enter to scrobble' class='simpleinput' id='title' onKeydown='scrobbleIfEnter(event)' />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding-right:7px;">
|
||||
Album artists (Optional):
|
||||
</td><td id="albumartists_td">
|
||||
<input placeholder='Separate with Enter' class='simpleinput' id='albumartists' onKeydown='keyDetect2(event)' onblur='addEnteredAlbumartist()' />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding-right:7px;">
|
||||
Album (Optional):
|
||||
</td><td>
|
||||
<input placeholder='Enter to scrobble' class='simpleinput' id='album' onKeydown='scrobbleIfEnter(event)' />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
<br/>
|
||||
|
@ -10,11 +10,23 @@ function addArtist(artist) {
|
||||
document.getElementById("artists_td").insertBefore(artistelement,newartistfield);
|
||||
newartistfield.placeholder = "Backspace to remove last"
|
||||
}
|
||||
function addAlbumartist(artist) {
|
||||
var newartistfield = document.getElementById("albumartists");
|
||||
var artistelement = document.createElement("span");
|
||||
artistelement.innerHTML = artist;
|
||||
artistelement.style = "padding:5px;";
|
||||
document.getElementById("albumartists_td").insertBefore(artistelement,newartistfield);
|
||||
newartistfield.placeholder = "Backspace to remove last"
|
||||
}
|
||||
|
||||
function keyDetect(event) {
|
||||
if (event.key === "Enter" || event.key === "Tab") { addEnteredArtist() }
|
||||
if (event.key === "Backspace" && document.getElementById("artists").value == "") { removeArtist() }
|
||||
}
|
||||
function keyDetect2(event) {
|
||||
if (event.key === "Enter" || event.key === "Tab") { addEnteredAlbumartist() }
|
||||
if (event.key === "Backspace" && document.getElementById("albumartists").value == "") { removeAlbumartist() }
|
||||
}
|
||||
|
||||
function addEnteredArtist() {
|
||||
var newartistfield = document.getElementById("artists");
|
||||
@ -24,6 +36,14 @@ function addEnteredArtist() {
|
||||
addArtist(newartist);
|
||||
}
|
||||
}
|
||||
function addEnteredAlbumartist() {
|
||||
var newartistfield = document.getElementById("albumartists");
|
||||
var newartist = newartistfield.value.trim();
|
||||
newartistfield.value = "";
|
||||
if (newartist != "") {
|
||||
addAlbumartist(newartist);
|
||||
}
|
||||
}
|
||||
function removeArtist() {
|
||||
var artists = document.getElementById("artists_td").getElementsByTagName("span")
|
||||
var lastartist = artists[artists.length-1]
|
||||
@ -32,14 +52,28 @@ function removeArtist() {
|
||||
document.getElementById("artists").placeholder = "Separate with Enter"
|
||||
}
|
||||
}
|
||||
function removeAlbumartist() {
|
||||
var artists = document.getElementById("albumartists_td").getElementsByTagName("span")
|
||||
var lastartist = artists[artists.length-1]
|
||||
document.getElementById("albumartists_td").removeChild(lastartist);
|
||||
if (artists.length < 1) {
|
||||
document.getElementById("albumartists").placeholder = "Separate with Enter"
|
||||
}
|
||||
}
|
||||
|
||||
function clear() {
|
||||
document.getElementById("title").value = "";
|
||||
document.getElementById("artists").value = "";
|
||||
document.getElementById("album").value = "";
|
||||
document.getElementById("albumartists").value = "";
|
||||
var artists = document.getElementById("artists_td").getElementsByTagName("span")
|
||||
while (artists.length > 0) {
|
||||
removeArtist();
|
||||
}
|
||||
var albumartists = document.getElementById("albumartists_td").getElementsByTagName("span")
|
||||
while (albumartists.length > 0) {
|
||||
removeAlbumartist();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -55,18 +89,30 @@ function scrobbleNew() {
|
||||
for (let node of artistnodes) {
|
||||
artists.push(node.textContent);
|
||||
}
|
||||
|
||||
var albumartistnodes = document.getElementById("albumartists_td").getElementsByTagName("span");
|
||||
var albumartists = [];
|
||||
for (let node of albumartistnodes) {
|
||||
albumartists.push(node.textContent);
|
||||
}
|
||||
|
||||
var title = document.getElementById("title").value;
|
||||
scrobble(artists,title);
|
||||
var album = document.getElementById("album").value;
|
||||
scrobble(artists,title,albumartists,album);
|
||||
}
|
||||
|
||||
function scrobble(artists,title) {
|
||||
function scrobble(artists,title,albumartists,album) {
|
||||
|
||||
lastArtists = artists;
|
||||
lastTrack = title;
|
||||
lastAlbum = album;
|
||||
lastAlbumartists = albumartists;
|
||||
|
||||
var payload = {
|
||||
"artists":artists,
|
||||
"title":title
|
||||
"title":title,
|
||||
"albumartists": albumartists,
|
||||
"album": album
|
||||
}
|
||||
|
||||
|
||||
@ -74,12 +120,7 @@ function scrobble(artists,title) {
|
||||
neo.xhttpreq("/apis/mlj_1/newscrobble",data=payload,method="POST",callback=notifyCallback,json=true)
|
||||
}
|
||||
|
||||
document.getElementById("title").value = "";
|
||||
document.getElementById("artists").value = "";
|
||||
var artists = document.getElementById("artists_td").getElementsByTagName("span");
|
||||
while (artists.length > 0) {
|
||||
removeArtist();
|
||||
}
|
||||
clear()
|
||||
}
|
||||
|
||||
function scrobbledone(req) {
|
||||
@ -98,6 +139,10 @@ function repeatLast() {
|
||||
addArtist(artist);
|
||||
}
|
||||
document.getElementById("title").value = lastTrack;
|
||||
for (let artist of lastAlbumartists) {
|
||||
addAlbumartist(artist);
|
||||
}
|
||||
document.getElementById("album").value = lastAlbum;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user