fuzzyworld

hawk / files / public / js / main.js

main.js

1.4 KB · history · blame

1// set favicon based on environment
2const isLocal = window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1";
3if (isLocal) {
4 document.querySelector("link[rel='icon']").href = "images/favicon-local.png";
5}
6
7// set version and updated info
8const params = {
9 version: hawkInfo.version,
10 updated: hawkInfo.updated
11};
12document.getElementById("info").innerHTML = createTemplatedHtml('app-info', params)
13
14// handle redirect from Spotify
15const urlParams = new URLSearchParams(window.location.search);
16const code = urlParams.get('code');
17const error = urlParams.get('error');
18if (code) {
19 getToken(code).then(() => {
20 window.history.replaceState({}, document.title, '/');
21 window.location = getSpotifyRedirectURL();
22 })
23} else if (error) {
24 console.error(error);
25 window.history.replaceState({}, document.title, '/');
26 window.location = getSpotifyRedirectURL();
27}
28
29// determine if the user is signed in or not
30// hide and show appropriate elements, based on class names
31const accessToken = localStorage.getItem('access_token');
32const userIsSignedIn = !accessToken
33if (userIsSignedIn) {
34 hideOrShow('signedin', false);
35 hideOrShow('signedout', true);
36} else {
37 hideOrShow('signedin', true);
38 hideOrShow('signedout', false);
39 setCurrentPlayingSong();
40 setInterval(setCurrentPlayingSong, 5 * 1000);
41}
42
43// periodically lookup the active device
44configureDevicesList();
45
46// configure times
47configureTimesList();