MarseyWorld/files/assets/js/profile_song.js

77 lines
1.5 KiB
JavaScript
Raw Normal View History

2023-10-18 19:07:06 +00:00
const audio = document.getElementById('profile-song')
2023-10-19 18:58:44 +00:00
handle_playing_music(audio)
2022-12-19 02:18:48 +00:00
2023-10-18 19:07:06 +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')
function play_audio(audio) {
audio.play()
if (anthem_button && !audio.paused) {
anthem_button.classList.add('text-primary')
anthem_button_mobile.classList.add('text-primary')
2023-10-17 19:35:00 +00:00
}
2023-10-18 19:07:06 +00:00
}
2023-10-17 19:35:00 +00:00
2023-10-18 19:07:06 +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 02:18:48 +00:00
}
2023-10-18 19:07:06 +00:00
}
2022-12-19 02:18:48 +00:00
2023-10-19 19:00:24 +00:00
function play_profile_song() {
addEventListener("load", () => {
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)
})
}
2023-10-18 19:07:06 +00:00
if (u_username)
{
function toggle() {
if (audio.paused) {
play_audio(audio);
}
else {
pause_audio(audio);
2023-10-17 19:35:00 +00:00
}
2023-10-18 19:07:06 +00:00
}
2023-10-17 19:35:00 +00:00
2023-10-19 19:00:24 +00:00
play_profile_song()
2023-10-18 19:07:06 +00:00
}
else
{
let v_username = document.getElementById('v_username')
if (v_username)
2022-12-19 02:18:48 +00:00
{
2023-10-18 19:07:06 +00:00
v_username = v_username.innerHTML
2022-12-19 02:18:48 +00:00
2023-10-18 19:07:06 +00:00
const paused = localStorage.getItem("paused")
2022-12-19 02:18:48 +00:00
2023-10-18 19:07:06 +00:00
function toggle() {
if (audio.paused)
{
play_audio(audio)
localStorage.setItem("paused", "")
2022-12-19 02:18:48 +00:00
}
2023-10-18 19:07:06 +00:00
else
2022-12-19 02:18:48 +00:00
{
2023-10-18 19:07:06 +00:00
pause_audio(audio)
localStorage.setItem("paused", "1")
2022-12-19 02:18:48 +00:00
}
2023-10-18 19:07:06 +00:00
}
2023-10-19 19:00:24 +00:00
if (!paused)
play_profile_song()
2022-12-19 02:18:48 +00:00
}
}