fuzzyworld

hawk / files / public / js / main.js

main.js

Blame: the commit that last changed each line · file · history

a95a53d1 2023-10-17 Pavel Safronov1// set favicon based on environment
c188f134 2023-10-16 Pavel Safronov2const 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
a95a53d1 2023-10-17 Pavel Safronov7// set version and updated info
1e82c571 2023-10-17 Pavel Safronov8const params = {
9 version: hawkInfo.version,
10 updated: hawkInfo.updated
11};
12document.getElementById("info").innerHTML = createTemplatedHtml('app-info', params)
187c6bc2 2023-10-13 Pavel Safronov13
a95a53d1 2023-10-17 Pavel Safronov14// handle redirect from Spotify
601035fb 2023-10-12 Pavel Safronov15const 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, '/');
0e0eaeff 2023-10-13 Pavel Safronov21 window.location = getSpotifyRedirectURL();
601035fb 2023-10-12 Pavel Safronov22 })
23} else if (error) {
24 console.error(error);
25 window.history.replaceState({}, document.title, '/');
0e0eaeff 2023-10-13 Pavel Safronov26 window.location = getSpotifyRedirectURL();
601035fb 2023-10-12 Pavel Safronov27}
28
a95a53d1 2023-10-17 Pavel Safronov29// determine if the user is signed in or not
30// hide and show appropriate elements, based on class names
601035fb 2023-10-12 Pavel Safronov31const accessToken = localStorage.getItem('access_token');
a95a53d1 2023-10-17 Pavel Safronov32const userIsSignedIn = !accessToken
33if (userIsSignedIn) {
731cddfd 2023-10-14 Pavel Safronov34 hideOrShow('signedin', false);
35 hideOrShow('signedout', true);
601035fb 2023-10-12 Pavel Safronov36} else {
731cddfd 2023-10-14 Pavel Safronov37 hideOrShow('signedin', true);
38 hideOrShow('signedout', false);
cc1af884 2023-10-13 Pavel Safronov39 setCurrentPlayingSong();
40 setInterval(setCurrentPlayingSong, 5 * 1000);
2c1835af 2023-10-19 Pavel Safronov41}
42
43// periodically lookup the active device
660845f9 2023-10-20 Pavel Safronov44configureDevicesList();
45
46// configure times
47configureTimesList();