2023-10-17 19:35:00 +00:00
|
|
|
if (localStorage.getItem("music_playing") != 'true') {
|
|
|
|
const audio = document.getElementById('profile-song')
|
2022-12-19 02:18:48 +00:00
|
|
|
|
2023-10-17 19:35:00 +00:00
|
|
|
audio.addEventListener('play', () => {
|
|
|
|
localStorage.setItem("music_playing", true);
|
|
|
|
})
|
2023-05-13 03:46:11 +00:00
|
|
|
|
2023-10-17 19:35:00 +00:00
|
|
|
window.addEventListener('beforeunload', () => {
|
|
|
|
localStorage.setItem("music_playing", false);
|
|
|
|
})
|
2023-05-13 03:46:11 +00:00
|
|
|
|
2023-10-17 19:35:00 +00:00
|
|
|
let u_username = document.getElementById('u_username')
|
|
|
|
const anthem_button = document.getElementById('toggle-anthem')
|
|
|
|
const anthem_button_mobile = document.getElementById('toggle-anthem-mobile')
|
2022-12-19 02:18:48 +00:00
|
|
|
|
2023-10-17 19:35:00 +00:00
|
|
|
function play_audio(audio) {
|
|
|
|
audio.play()
|
|
|
|
if (anthem_button && !audio.paused) {
|
|
|
|
anthem_button.classList.add('text-primary')
|
|
|
|
anthem_button_mobile.classList.add('text-primary')
|
2022-12-19 19:17:23 +00:00
|
|
|
}
|
2023-10-17 19:35:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function pause_audio(audio) {
|
|
|
|
audio.pause()
|
|
|
|
if (anthem_button && audio.paused) {
|
|
|
|
anthem_button.classList.remove('text-primary')
|
|
|
|
anthem_button_mobile.classList.remove('text-primary')
|
2022-12-19 19:17:23 +00:00
|
|
|
}
|
2022-12-19 02:18:48 +00:00
|
|
|
}
|
|
|
|
|
2023-10-17 19:35:00 +00:00
|
|
|
if (u_username)
|
|
|
|
{
|
|
|
|
function toggle() {
|
|
|
|
if (audio.paused) {
|
|
|
|
play_audio(audio);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pause_audio(audio);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
play_audio(audio);
|
|
|
|
document.addEventListener('click', (e) => {
|
|
|
|
if (e.target.id.startsWith("toggle-anthem"))
|
|
|
|
return
|
|
|
|
if (audio.paused) play_audio(audio);
|
|
|
|
}, {once : true});
|
2022-12-19 02:18:48 +00:00
|
|
|
|
2023-10-17 19:35:00 +00:00
|
|
|
prepare_to_pause(audio)
|
|
|
|
}
|
|
|
|
else
|
2022-12-19 02:18:48 +00:00
|
|
|
{
|
2023-10-17 19:35:00 +00:00
|
|
|
let v_username = document.getElementById('v_username')
|
|
|
|
if (v_username)
|
|
|
|
{
|
|
|
|
v_username = v_username.innerHTML
|
2022-12-19 02:18:48 +00:00
|
|
|
|
2023-10-17 19:35:00 +00:00
|
|
|
const paused = localStorage.getItem("paused")
|
2022-12-19 02:18:48 +00:00
|
|
|
|
2023-10-17 19:35:00 +00:00
|
|
|
function toggle() {
|
|
|
|
if (audio.paused)
|
|
|
|
{
|
|
|
|
play_audio(audio)
|
|
|
|
localStorage.setItem("paused", "")
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pause_audio(audio)
|
|
|
|
localStorage.setItem("paused", "1")
|
|
|
|
}
|
2022-12-19 02:18:48 +00:00
|
|
|
}
|
2023-10-17 19:35:00 +00:00
|
|
|
|
|
|
|
if (!paused)
|
2022-12-19 02:18:48 +00:00
|
|
|
{
|
2023-10-17 19:35:00 +00:00
|
|
|
play_audio(audio);
|
|
|
|
document.addEventListener('click', (e) => {
|
|
|
|
if (e.target.id.startsWith("toggle-anthem"))
|
|
|
|
return
|
|
|
|
if (audio.paused) play_audio(audio);
|
|
|
|
}, {once : true});
|
2022-12-19 02:18:48 +00:00
|
|
|
}
|
|
|
|
|
2023-10-17 19:35:00 +00:00
|
|
|
prepare_to_pause(audio)
|
2022-12-19 02:18:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|