forked from rDrama/rDrama
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();
|
audio.addEventListener('play', () => {
|
||||||
document.addEventListener('click', () => {
|
localStorage.setItem("music_playing", true);
|
||||||
if (audio.paused) audio.play();
|
})
|
||||||
}, {once : true});
|
|
||||||
prepare_to_pause(audio)
|
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')
|
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', () => {
|
||||||
audio.play()
|
localStorage.setItem("music_playing", false);
|
||||||
if (anthem_button && !audio.paused) {
|
})
|
||||||
anthem_button.classList.add('text-primary')
|
|
||||||
anthem_button_mobile.classList.add('text-primary')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function pause_audio(audio) {
|
let u_username = document.getElementById('u_username')
|
||||||
audio.pause()
|
const anthem_button = document.getElementById('toggle-anthem')
|
||||||
if (anthem_button && audio.paused) {
|
const anthem_button_mobile = document.getElementById('toggle-anthem-mobile')
|
||||||
anthem_button.classList.remove('text-primary')
|
|
||||||
anthem_button_mobile.classList.remove('text-primary')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (u_username)
|
function play_audio(audio) {
|
||||||
{
|
audio.play()
|
||||||
u_username = u_username.innerHTML
|
if (anthem_button && !audio.paused) {
|
||||||
|
anthem_button.classList.add('text-primary')
|
||||||
function toggle() {
|
anthem_button_mobile.classList.add('text-primary')
|
||||||
if (audio.paused) {
|
|
||||||
play_audio(audio);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
pause_audio(audio);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
play_audio(audio);
|
function pause_audio(audio) {
|
||||||
document.addEventListener('click', (e) => {
|
audio.pause()
|
||||||
if (e.target.id.startsWith("toggle-anthem"))
|
if (anthem_button && audio.paused) {
|
||||||
return
|
anthem_button.classList.remove('text-primary')
|
||||||
if (audio.paused) play_audio(audio);
|
anthem_button_mobile.classList.remove('text-primary')
|
||||||
}, {once : true});
|
}
|
||||||
|
}
|
||||||
|
|
||||||
prepare_to_pause(audio)
|
if (u_username)
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
let v_username = document.getElementById('v_username')
|
|
||||||
if (v_username)
|
|
||||||
{
|
{
|
||||||
v_username = v_username.innerHTML
|
|
||||||
|
|
||||||
const paused = localStorage.getItem("paused")
|
|
||||||
|
|
||||||
function toggle() {
|
function toggle() {
|
||||||
if (audio.paused)
|
if (audio.paused) {
|
||||||
{
|
play_audio(audio);
|
||||||
play_audio(audio)
|
|
||||||
localStorage.setItem("paused", "")
|
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
pause_audio(audio);
|
||||||
pause_audio(audio)
|
|
||||||
localStorage.setItem("paused", "1")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!paused)
|
play_audio(audio);
|
||||||
{
|
document.addEventListener('click', (e) => {
|
||||||
play_audio(audio);
|
if (e.target.id.startsWith("toggle-anthem"))
|
||||||
document.addEventListener('click', (e) => {
|
return
|
||||||
if (e.target.id.startsWith("toggle-anthem"))
|
if (audio.paused) play_audio(audio);
|
||||||
return
|
}, {once : true});
|
||||||
if (audio.paused) play_audio(audio);
|
|
||||||
}, {once : true});
|
|
||||||
}
|
|
||||||
|
|
||||||
prepare_to_pause(audio)
|
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