forked from rDrama/rDrama
1
0
Fork 0

minor fix to profile song logic

master
Aevann 2023-10-18 22:07:06 +03:00
parent f9b8ba42d1
commit ca68b3f947
1 changed files with 63 additions and 61 deletions

View File

@ -1,45 +1,47 @@
if (localStorage.getItem("music_playing") != 'true') {
const audio = document.getElementById('profile-song')
const music_playing = localStorage.getItem("music_playing") == 'true'
audio.addEventListener('play', () => {
localStorage.setItem("music_playing", true);
})
const audio = document.getElementById('profile-song')
window.addEventListener('beforeunload', () => {
localStorage.setItem("music_playing", false);
})
audio.addEventListener('play', () => {
localStorage.setItem("music_playing", true);
})
let u_username = document.getElementById('u_username')
const anthem_button = document.getElementById('toggle-anthem')
const anthem_button_mobile = document.getElementById('toggle-anthem-mobile')
window.addEventListener('beforeunload', () => {
localStorage.setItem("music_playing", false);
})
function play_audio(audio) {
audio.play()
if (anthem_button && !audio.paused) {
anthem_button.classList.add('text-primary')
anthem_button_mobile.classList.add('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')
function play_audio(audio) {
audio.play()
if (anthem_button && !audio.paused) {
anthem_button.classList.add('text-primary')
anthem_button_mobile.classList.add('text-primary')
}
}
function pause_audio(audio) {
audio.pause()
if (anthem_button && audio.paused) {
anthem_button.classList.remove('text-primary')
anthem_button_mobile.classList.remove('text-primary')
}
}
if (u_username)
{
function toggle() {
if (audio.paused) {
play_audio(audio);
}
else {
pause_audio(audio);
}
}
function pause_audio(audio) {
audio.pause()
if (anthem_button && audio.paused) {
anthem_button.classList.remove('text-primary')
anthem_button_mobile.classList.remove('text-primary')
}
}
if (u_username)
{
function toggle() {
if (audio.paused) {
play_audio(audio);
}
else {
pause_audio(audio);
}
}
if (!music_playing) {
play_audio(audio);
document.addEventListener('click', (e) => {
if (e.target.id.startsWith("toggle-anthem"))
@ -49,37 +51,37 @@ if (localStorage.getItem("music_playing") != 'true') {
prepare_to_pause(audio)
}
else
}
else
{
let v_username = document.getElementById('v_username')
if (v_username)
{
let v_username = document.getElementById('v_username')
if (v_username)
{
v_username = v_username.innerHTML
v_username = v_username.innerHTML
const paused = localStorage.getItem("paused")
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)
function toggle() {
if (audio.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)
localStorage.setItem("paused", "")
}
else
{
pause_audio(audio)
localStorage.setItem("paused", "1")
}
}
if (!paused && !music_playing)
{
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)
}