-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix flickering on reaload spotify page
Add the first api call to the template of the page, so it is in one file
- Loading branch information
1 parent
7f0e406
commit f93310f
Showing
3 changed files
with
33 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 26 additions & 24 deletions
50
narrowcast_content/spotify_now_playing/static/js/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,38 @@ | ||
function update_player(data) { | ||
if (data.authorized === false) { | ||
document.querySelector('.song').style.display = 'none'; | ||
document.querySelector('.unauthorized').style.display = 'grid'; | ||
document.querySelector('.not_playing').style.display = 'none'; | ||
} else if (data.anything_playing === false) { | ||
document.querySelector('.song').style.display = 'none'; | ||
document.querySelector('.unauthorized').style.display = 'none'; | ||
document.querySelector('.not_playing').style.display = 'grid'; | ||
} else { | ||
document.querySelector('.song').style.display = 'grid'; | ||
document.querySelector('.unauthorized').style.display = 'none'; | ||
document.querySelector('.not_playing').style.display = 'none'; | ||
document.querySelector('.title').textContent = data.title; | ||
document.querySelector('.artist').textContent = data.artist; | ||
document.querySelector('.album_cover img').src = data["album_cover"]; | ||
if (data.is_playing === true) { | ||
document.querySelector('.playing_symbol').classList.add('playing'); | ||
} else { | ||
document.querySelector('.playing_symbol').classList.remove('playing'); | ||
} | ||
} | ||
} | ||
|
||
// Function to update the now playing information | ||
function updateNowPlaying() { | ||
fetch('currently_playing',) | ||
.then(response => response.json()) | ||
.then(data => { | ||
if (data.authorized === false) { | ||
document.querySelector('.song').style.display = 'none'; | ||
document.querySelector('.unauthorized').style.display = 'grid'; | ||
document.querySelector('.not_playing').style.display = 'none'; | ||
} else if (data.anything_playing === false) { | ||
document.querySelector('.song').style.display = 'none'; | ||
document.querySelector('.unauthorized').style.display = 'none'; | ||
document.querySelector('.not_playing').style.display = 'grid'; | ||
} else { | ||
document.querySelector('.song').style.display = 'grid'; | ||
document.querySelector('.unauthorized').style.display = 'none'; | ||
document.querySelector('.not_playing').style.display = 'none'; | ||
document.querySelector('.title').textContent = data.title; | ||
document.querySelector('.artist').textContent = data.artist; | ||
document.querySelector('.album_cover img').src = data["album_cover"]; | ||
if (data.is_playing === true){ | ||
document.querySelector('.playing_symbol').classList.add('playing'); | ||
} else { | ||
document.querySelector('.playing_symbol').classList.remove('playing'); | ||
} | ||
} | ||
|
||
update_player(data); | ||
}) | ||
.catch(error => console.error('Error fetching data:', error)); | ||
} | ||
|
||
// Call updateNowPlaying every 5 seconds | ||
setInterval(updateNowPlaying, 5000); | ||
|
||
// Initial call to populate the information | ||
updateNowPlaying(); | ||
update_player(initial_data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters