diff --git a/assets/lastplayed.js b/assets/lastplayed.js index 5076da2..f0b3b8f 100644 --- a/assets/lastplayed.js +++ b/assets/lastplayed.js @@ -1,11 +1,13 @@ const lastPlayedBlock = document.getElementById('last-played'); -let xmlHttp = new XMLHttpRequest(); -xmlHttp.open("GET", "https://lastfm-last-played.biancarosa.com.br/catmpeg/latest-song", false); -xmlHttp.send(null); -if (xmlHttp.responseText != 0) { - const lastParse = JSON.parse(xmlHttp.responseText); - const lastPlayed = document.querySelector("#song"); - lastPlayed.innerHTML = "" + lastParse["track"]["name"] + " - " + lastParse["track"]["artist"]["#text"] + ""; - lastPlayedBlock.style.display = "block"; -} \ No newline at end of file +fetch("https://lastfm-last-played.biancarosa.com.br/catmpeg/latest-song") + .then(response => response.json()) + .then(data => { + if (data != 0) { + const lastPlayed = document.querySelector("#song"); + lastPlayed.innerHTML = ` + ${data.track.name} - ${data.track.artist["#text"]}`; + lastPlayedBlock.style.display = "block"; + } + }) + .catch(err => console.error(err)); \ No newline at end of file