2024-10-11 18:46:00 -04:00
|
|
|
const albumlabel = document.getElementById("albumLabel");
|
2024-10-11 17:38:29 -04:00
|
|
|
const albumart = document.getElementById("album-art");
|
|
|
|
const song = document.getElementById("song");
|
|
|
|
const artist = document.getElementById("artist");
|
|
|
|
const album = document.getElementById("album");
|
|
|
|
|
|
|
|
async function getLatestSong() {
|
|
|
|
const api = "https://lastfm-last-played.biancarosa.com.br/aidxn_/latest-song";
|
|
|
|
try {
|
|
|
|
const lsResponse = await fetch(api);
|
|
|
|
if (lsResponse.ok) {
|
|
|
|
const latestSongJSON = await lsResponse.json();
|
|
|
|
if (!latestSongJSON.track["@attr"]) {
|
2024-10-11 18:46:00 -04:00
|
|
|
albumlabel.textContent = "Last Listen:";
|
2024-10-11 17:38:29 -04:00
|
|
|
} else {
|
2024-10-11 18:46:00 -04:00
|
|
|
// noinspection JSUnresolvedReference
|
|
|
|
if (latestSongJSON.track["@attr"].nowplaying) {
|
|
|
|
albumlabel.textContent = "Now Playing:";
|
|
|
|
} else {
|
|
|
|
console.log("[WARN] Invalid value in now playing status, or something else messed up");
|
|
|
|
albumlabel.textContent = "Last Listen:";
|
|
|
|
}
|
2024-10-11 17:38:29 -04:00
|
|
|
}
|
2024-10-11 18:46:00 -04:00
|
|
|
// noinspection JSUnresolvedReference
|
2024-10-11 17:38:29 -04:00
|
|
|
albumart.src = latestSongJSON.track.image[1]["#text"];
|
|
|
|
song.textContent = latestSongJSON.track.name;
|
|
|
|
artist.textContent = latestSongJSON.track.artist["#text"];
|
|
|
|
album.textContent = latestSongJSON.track.album["#text"];
|
2024-10-11 18:46:00 -04:00
|
|
|
} else console.log(`Error: ${lsResponse.status}`);
|
2024-10-11 17:38:29 -04:00
|
|
|
} catch (error) {
|
|
|
|
console.log(`Error: ${error.message}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-11 18:46:00 -04:00
|
|
|
(async function() {
|
|
|
|
await getLatestSong();
|
|
|
|
})();
|