diff --git a/files/assets/events/shared/js/music.js b/files/assets/events/shared/js/music.js index e9b137a6d..d187f0a18 100644 --- a/files/assets/events/shared/js/music.js +++ b/files/assets/events/shared/js/music.js @@ -1,7 +1,17 @@ -const audio = document.getElementById('event-song'); +if (localStorage.getItem("music_playing") != 'true') { + const audio = document.getElementById('event-song'); -audio.play(); -document.addEventListener('click', () => { - if (audio.paused) audio.play(); -}, {once : true}); -prepare_to_pause(audio) + audio.addEventListener('play', () => { + localStorage.setItem("music_playing", true); + }) + + window.addEventListener('beforeunload', () => { + localStorage.setItem("music_playing", false); + }) + + audio.play(); + document.addEventListener('click', () => { + if (audio.paused) audio.play(); + }, {once : true}); + prepare_to_pause(audio) +} diff --git a/files/assets/js/profile_song.js b/files/assets/js/profile_song.js index a2399d8d7..98387563f 100644 --- a/files/assets/js/profile_song.js +++ b/files/assets/js/profile_song.js @@ -1,79 +1,87 @@ -let u_username = document.getElementById('u_username') +if (localStorage.getItem("music_playing") != 'true') { + const audio = document.getElementById('profile-song') -const audio = document.getElementById('profile-song') -const anthem_button = document.getElementById('toggle-anthem') -const anthem_button_mobile = document.getElementById('toggle-anthem-mobile') + audio.addEventListener('play', () => { + localStorage.setItem("music_playing", true); + }) -function play_audio(audio) { - audio.play() - if (anthem_button && !audio.paused) { - anthem_button.classList.add('text-primary') - anthem_button_mobile.classList.add('text-primary') - } -} + window.addEventListener('beforeunload', () => { + localStorage.setItem("music_playing", false); + }) -function pause_audio(audio) { - audio.pause() - if (anthem_button && audio.paused) { - anthem_button.classList.remove('text-primary') - anthem_button_mobile.classList.remove('text-primary') - } -} + let u_username = document.getElementById('u_username') + const anthem_button = document.getElementById('toggle-anthem') + const anthem_button_mobile = document.getElementById('toggle-anthem-mobile') -if (u_username) -{ - u_username = u_username.innerHTML - - function toggle() { - if (audio.paused) { - play_audio(audio); - } - else { - pause_audio(audio); + function play_audio(audio) { + audio.play() + if (anthem_button && !audio.paused) { + anthem_button.classList.add('text-primary') + anthem_button_mobile.classList.add('text-primary') } } - play_audio(audio); - document.addEventListener('click', (e) => { - if (e.target.id.startsWith("toggle-anthem")) - return - if (audio.paused) play_audio(audio); - }, {once : true}); + function pause_audio(audio) { + audio.pause() + if (anthem_button && audio.paused) { + anthem_button.classList.remove('text-primary') + anthem_button_mobile.classList.remove('text-primary') + } + } - prepare_to_pause(audio) -} -else -{ - let v_username = document.getElementById('v_username') - if (v_username) + if (u_username) { - v_username = v_username.innerHTML - - const paused = localStorage.getItem("paused") - function toggle() { - if (audio.paused) - { - play_audio(audio) - localStorage.setItem("paused", "") + if (audio.paused) { + play_audio(audio); } - else - { - pause_audio(audio) - localStorage.setItem("paused", "1") + else { + pause_audio(audio); } } - if (!paused) - { - play_audio(audio); - document.addEventListener('click', (e) => { - if (e.target.id.startsWith("toggle-anthem")) - return - if (audio.paused) play_audio(audio); - }, {once : true}); - } + play_audio(audio); + document.addEventListener('click', (e) => { + if (e.target.id.startsWith("toggle-anthem")) + return + if (audio.paused) play_audio(audio); + }, {once : true}); prepare_to_pause(audio) } + else + { + let v_username = document.getElementById('v_username') + if (v_username) + { + v_username = v_username.innerHTML + + const paused = localStorage.getItem("paused") + + function toggle() { + if (audio.paused) + { + play_audio(audio) + localStorage.setItem("paused", "") + } + else + { + pause_audio(audio) + localStorage.setItem("paused", "1") + } + } + + if (!paused) + { + play_audio(audio); + document.addEventListener('click', (e) => { + if (e.target.id.startsWith("toggle-anthem")) + return + if (audio.paused) play_audio(audio); + }, {once : true}); + } + + prepare_to_pause(audio) + } + } }