pause background music when a video or audio is played

master
Aevann1 2022-10-24 23:16:38 +02:00
parent 67a6676bf8
commit b2317a4563
2 changed files with 41 additions and 1 deletions

View File

@ -52,6 +52,26 @@ else
}
}
for (const video of document.getElementsByTagName('video'))
{
video.addEventListener('play', (event) => {
if (!audio.paused)
{
audio.pause();
}
});
}
for (const a of document.getElementsByTagName('audio'))
{
a.addEventListener('play', (event) => {
if (!audio.paused)
{
audio.pause();
}
});
}
function badge_timestamp(t) {
const date = new Date(t.dataset.until*1000);
const text = t.getAttribute("data-bs-original-title")

View File

@ -1165,6 +1165,26 @@
window.addEventListener('click', () => {
if (audio.paused) audio.play();
}, {once : true});
for (const video of document.getElementsByTagName('video'))
{
video.addEventListener('play', (event) => {
if (!audio.paused)
{
audio.pause();
}
});
}
for (const a of document.getElementsByTagName('audio'))
{
a.addEventListener('play', (event) => {
if (!audio.paused)
{
audio.pause();
}
});
}
</script>
{% endif %}