diff --git a/files/assets/js/core.js b/files/assets/js/core.js index de51a9dd2..6957893ba 100644 --- a/files/assets/js/core.js +++ b/files/assets/js/core.js @@ -370,3 +370,20 @@ function areyousure(t) { if (t.dataset.dismiss) t.setAttribute("data-bs-dismiss", t.dataset.dismiss); } + +function prepare_to_pause(audio) { + for (const e of document.querySelectorAll('video,audio')) + { + console.log(e) + e.addEventListener('play', () => { + if (!audio.paused) audio.pause(); + }); + } + + for (const e of document.getElementsByTagName('lite-youtube')) + { + e.addEventListener('click', (event) => { + if (!audio.paused) audio.pause(); + }); + } +} diff --git a/files/assets/js/userpage.js b/files/assets/js/userpage.js index 344590b85..7b2763894 100644 --- a/files/assets/js/userpage.js +++ b/files/assets/js/userpage.js @@ -16,6 +16,8 @@ if (u_username) document.getElementById('userpage').addEventListener('click', () => { if (audio.paused) audio.play(); }, {once : true}); + + prepare_to_pause(audio) } else { @@ -49,29 +51,11 @@ else if (audio.paused) audio.play(); }, {once : true}); } + + prepare_to_pause(audio) } } -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") diff --git a/files/templates/submission.html b/files/templates/submission.html index 3d6116ca0..82798bf9a 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -1166,25 +1166,7 @@ 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(); - } - }); - } + prepare_to_pause(audio) {% endif %}