forked from rDrama/rDrama
1
0
Fork 0

dont play music in multiple tabs

master
Aevann 2023-10-17 22:35:00 +03:00
parent 63f049f1b6
commit 8ccd8173a3
2 changed files with 85 additions and 67 deletions

View File

@ -1,7 +1,17 @@
const audio = document.getElementById('event-song'); if (localStorage.getItem("music_playing") != 'true') {
const audio = document.getElementById('event-song');
audio.play(); audio.addEventListener('play', () => {
document.addEventListener('click', () => { localStorage.setItem("music_playing", true);
})
window.addEventListener('beforeunload', () => {
localStorage.setItem("music_playing", false);
})
audio.play();
document.addEventListener('click', () => {
if (audio.paused) audio.play(); if (audio.paused) audio.play();
}, {once : true}); }, {once : true});
prepare_to_pause(audio) prepare_to_pause(audio)
}

View File

@ -1,29 +1,36 @@
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') audio.addEventListener('play', () => {
const anthem_button = document.getElementById('toggle-anthem') localStorage.setItem("music_playing", true);
const anthem_button_mobile = document.getElementById('toggle-anthem-mobile') })
function play_audio(audio) { window.addEventListener('beforeunload', () => {
localStorage.setItem("music_playing", false);
})
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() audio.play()
if (anthem_button && !audio.paused) { if (anthem_button && !audio.paused) {
anthem_button.classList.add('text-primary') anthem_button.classList.add('text-primary')
anthem_button_mobile.classList.add('text-primary') anthem_button_mobile.classList.add('text-primary')
} }
} }
function pause_audio(audio) { function pause_audio(audio) {
audio.pause() audio.pause()
if (anthem_button && audio.paused) { if (anthem_button && audio.paused) {
anthem_button.classList.remove('text-primary') anthem_button.classList.remove('text-primary')
anthem_button_mobile.classList.remove('text-primary') anthem_button_mobile.classList.remove('text-primary')
} }
} }
if (u_username)
{
u_username = u_username.innerHTML
if (u_username)
{
function toggle() { function toggle() {
if (audio.paused) { if (audio.paused) {
play_audio(audio); play_audio(audio);
@ -41,9 +48,9 @@ if (u_username)
}, {once : true}); }, {once : true});
prepare_to_pause(audio) prepare_to_pause(audio)
} }
else else
{ {
let v_username = document.getElementById('v_username') let v_username = document.getElementById('v_username')
if (v_username) if (v_username)
{ {
@ -76,4 +83,5 @@ else
prepare_to_pause(audio) prepare_to_pause(audio)
} }
}
} }