forked from rDrama/rDrama
fix music playing
parent
3c98efea52
commit
285ac4d67d
|
@ -1,14 +1,8 @@
|
||||||
if (localStorage.getItem("music_playing") != 'true') {
|
if (!playing_music()) {
|
||||||
addEventListener("load", () => {
|
addEventListener("load", () => {
|
||||||
const audio = document.getElementById('event-song');
|
const audio = document.getElementById('event-song');
|
||||||
|
|
||||||
audio.addEventListener('play', () => {
|
handle_playing_music(audio)
|
||||||
localStorage.setItem("music_playing", true);
|
|
||||||
})
|
|
||||||
|
|
||||||
window.addEventListener('beforeunload', () => {
|
|
||||||
localStorage.setItem("music_playing", false);
|
|
||||||
})
|
|
||||||
|
|
||||||
audio.play();
|
audio.play();
|
||||||
document.addEventListener('click', () => {
|
document.addEventListener('click', () => {
|
||||||
|
|
|
@ -284,6 +284,22 @@ function prepare_to_pause(audio) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handle_playing_music(audio) {
|
||||||
|
audio.addEventListener('play', () => {
|
||||||
|
localStorage.setItem("playing_music", Date.now());
|
||||||
|
window.addEventListener('beforeunload', () => {
|
||||||
|
localStorage.setItem("playing_music", 0);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
audio.addEventListener('pause', () => {
|
||||||
|
localStorage.setItem("playing_music", 0);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function playing_music() {
|
||||||
|
return (Date.now() - localStorage.getItem("playing_music", 0) < 300000)
|
||||||
|
}
|
||||||
|
|
||||||
function reload() {
|
function reload() {
|
||||||
location.reload();
|
location.reload();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,6 @@
|
||||||
const music_playing = localStorage.getItem("music_playing") == 'true'
|
|
||||||
|
|
||||||
const audio = document.getElementById('profile-song')
|
const audio = document.getElementById('profile-song')
|
||||||
|
|
||||||
audio.addEventListener('play', () => {
|
handle_playing_music(audio)
|
||||||
localStorage.setItem("music_playing", true);
|
|
||||||
})
|
|
||||||
|
|
||||||
audio.addEventListener('pause', () => {
|
|
||||||
localStorage.setItem("music_playing", false);
|
|
||||||
})
|
|
||||||
|
|
||||||
window.addEventListener('beforeunload', () => {
|
|
||||||
localStorage.setItem("music_playing", false);
|
|
||||||
})
|
|
||||||
|
|
||||||
let u_username = document.getElementById('u_username')
|
let u_username = document.getElementById('u_username')
|
||||||
const anthem_button = document.getElementById('toggle-anthem')
|
const anthem_button = document.getElementById('toggle-anthem')
|
||||||
|
@ -45,7 +33,7 @@ if (u_username)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!music_playing) {
|
if (!playing_music()) {
|
||||||
addEventListener("load", () => {
|
addEventListener("load", () => {
|
||||||
play_audio(audio);
|
play_audio(audio);
|
||||||
document.addEventListener('click', (e) => {
|
document.addEventListener('click', (e) => {
|
||||||
|
@ -80,7 +68,7 @@ else
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!paused && !music_playing)
|
if (!paused && !playing_music())
|
||||||
{
|
{
|
||||||
addEventListener("load", () => {
|
addEventListener("load", () => {
|
||||||
play_audio(audio);
|
play_audio(audio);
|
||||||
|
|
Loading…
Reference in New Issue