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( + `

No song is playing currently.

` + ); + } else { + var song_name = data.item.name; + var image = data.item.album.images[0].url; var artistsRaw = data.item.artists; var artistsName = []; for (var i = 0; i < artistsRaw.length; i++) { artistsName.push(artistsRaw[i].name); } var artist = artistsName.join(", "); - - 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; + if ((oldname == null && oldimage == null)) { + $(".song-now-playing").text(""); + $(".song-now-playing").append( + `` + ); + $(".song-now-playing").append('
'); + $(".song-info-np").append(`

${song_name}

`); + $(".song-info-np").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 @@

Now Playing


-
+
{% if cp is not none %} -
+

{{ cp.title }}

{{ cp.artists }}

{% else %} -

No song is playing currently.

+

No song is playing currently.

{% endif %}