forked from MarseyWorld/MarseyWorld
dont play music in multiple tabs
parent
63f049f1b6
commit
8ccd8173a3
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue