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

View File

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