diff --git a/Statsify/static/js/home.js b/Statsify/static/js/home.js index db2fbb9..c9d5670 100644 --- a/Statsify/static/js/home.js +++ b/Statsify/static/js/home.js @@ -43,26 +43,47 @@ $(".ta").click(function(){ $( document ).ready(function() { $.get("/ajax/currently_playing?type=original", function(data) { - let oldname = data.item.name; - let oldimage = data.item.album.images[0].url; + let oldname = null; + let oldimage = null; + if (data != null) { + oldname = data.item.name; + oldimage = data.item.album.images[0].url; + } setInterval(function() { $.get("/ajax/currently_playing?type=now", function(data) { - var song_name = data.item.name; - var image = data.item.album.images[0].url; - if (oldname != song_name && oldimage != image) { + if (data == null) { + oldname = null; + oldimage = null; + $(".song-now-playing").text(""); + $(".song-now-playing").append( + `
${artist}
`); + } + if (oldname != song_name && oldimage != image) { + var now_playing = $("div.now-playing"); + now_playing.find("img").attr("src", image); + now_playing.find(".song-info").find("#song-title").text(song_name); + now_playing.find(".song-info").find("#song-artist").text(artist); + oldname = song_name; + oldimage = image; + } } }); }, 10000); diff --git a/Statsify/templates/home.html b/Statsify/templates/home.html index ebb3720..bd94df1 100644 --- a/Statsify/templates/home.html +++ b/Statsify/templates/home.html @@ -10,15 +10,15 @@