stop the lightning strikes when videos or audio get played

master
Aevann 2024-10-28 00:20:35 +03:00
parent ca913a7310
commit 433f0001ec
2 changed files with 9 additions and 3 deletions

View File

@ -15,7 +15,7 @@ window.onload = function() {
lightningStrike("normal")
}
setInterval(function() {
const lightningInternval = setInterval(function() {
if (Math.floor(Math.random()*3) > 1) {
lightningStrike("haunted")
} else {
@ -28,15 +28,19 @@ function lightningStrike(strike) {
if (strike == "haunted") {
stylesheet_haunted.disabled = false
if (thunder1)
if (thunder1) {
thunder2.play()
prepare_to_pause(thunder2)
}
setTimeout(function() {
stylesheet_haunted.disabled = true
}, 700)
}
if (thunder1)
if (thunder1) {
thunder1.play()
prepare_to_pause(thunder1)
}
setTimeout(function() {
div.style.animation = "none"
}, 1000)

View File

@ -280,12 +280,14 @@ function prepare_to_pause(audio) {
if (e == audio) continue
e.addEventListener('play', () => {
if (!audio.paused) audio.pause();
if (lightningInternval) clearInterval(lightningInternval)
});
}
document.addEventListener('click', (e) => {
if ((e.target.tagName.toLowerCase() == "lite-youtube" || e.target.classList.contains('lty-playbtn')) && !audio.paused) {
audio.pause();
if (lightningInternval) clearInterval(lightningInternval)
}
});
}