Aevann 2023-05-13 06:46:11 +03:00
parent 9e9899788f
commit e8a6203329
2 changed files with 29 additions and 12 deletions

View File

@ -1,5 +1,24 @@
let u_username = document.getElementById('u_username') 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) if (u_username)
{ {
u_username = u_username.innerHTML u_username = u_username.innerHTML
@ -9,18 +28,16 @@ if (u_username)
function toggle() { function toggle() {
if (audio.paused) { if (audio.paused) {
audio.play(); play_audio(audio);
audio.play();
} }
else { else {
audio.pause(); pause_audio(audio);
audio.pause();
} }
} }
audio.play(); play_audio(audio);
document.addEventListener('click', () => { document.addEventListener('click', () => {
if (audio.paused) audio.play(); if (audio.paused) play_audio(audio);
}, {once : true}); }, {once : true});
prepare_to_pause(audio) prepare_to_pause(audio)
@ -40,21 +57,21 @@ else
function toggle() { function toggle() {
if (audio.paused) if (audio.paused)
{ {
audio.play() play_audio(audio)
localStorage.setItem("paused", "") localStorage.setItem("paused", "")
} }
else else
{ {
audio.pause() pause_audio(audio)
localStorage.setItem("paused", "1") localStorage.setItem("paused", "1")
} }
} }
if (!paused) if (!paused)
{ {
audio.play(); play_audio(audio);
document.addEventListener('click', () => { document.addEventListener('click', () => {
if (audio.paused) audio.play(); if (audio.paused) play_audio(audio);
}, {once : true}); }, {once : true});
} }

View File

@ -187,7 +187,7 @@
{% endif %} {% endif %}
{% if FEATURES['USERS_PROFILE_SONG'] and u.song and v and (v.id == u.id or v.mute and not u.unmutable) %} {% if FEATURES['USERS_PROFILE_SONG'] and u.song and v and (v.id == u.id or v.mute and not u.unmutable) %}
<button type="button" class="btn btn-secondary" data-nonce="{{g.nonce}}" data-onclick="toggle()" {% if v.id == u.id %}style="margin-bottom:0!important;padding:0.3rem 0.75rem!important"{% endif %}><i class="fas fa-music mr-1"></i> Toggle Anthem</button> <button id="toggle-anthem" type="button" class="btn btn-secondary" data-nonce="{{g.nonce}}" data-onclick="toggle()" {% if v.id == u.id %}style="margin-bottom:0!important;padding:0.3rem 0.75rem!important"{% endif %}><i class="fas fa-music mr-1"></i> Profile Anthem</button>
{% endif %} {% endif %}
{% if v and v.id == u.id %} {% if v and v.id == u.id %}
@ -413,7 +413,7 @@
{% endif %} {% endif %}
{% if FEATURES['USERS_PROFILE_SONG'] and u.song and v and (v.id == u.id or v.mute and not u.unmutable) %} {% if FEATURES['USERS_PROFILE_SONG'] and u.song and v and (v.id == u.id or v.mute and not u.unmutable) %}
<button type="button" class="btn btn-secondary" data-nonce="{{g.nonce}}" data-onclick="toggle()" {% if v.id == u.id %}style="margin-bottom:0!important;padding:0.3rem 0.75rem!important"{% endif %}><i class="fas fa-music mr-1"></i> Toggle Anthem</button> <button id="toggle-anthem-mobile" type="button" class="btn btn-secondary" data-nonce="{{g.nonce}}" data-onclick="toggle()" {% if v.id == u.id %}style="margin-bottom:0!important;padding:0.3rem 0.75rem!important"{% endif %}><i class="fas fa-music mr-1"></i> Profile Anthem</button>
{% endif %} {% endif %}
{% if v and v.id == u.id %} {% if v and v.id == u.id %}