From 339698cfb56c7216b3253423a12c7d4e98c73c0b Mon Sep 17 00:00:00 2001 From: Volpeon Date: Sat, 25 Dec 2021 12:15:14 +0100 Subject: Don't generate snow if tab is inactive --- content/script.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'content') diff --git a/content/script.js b/content/script.js index dd7729d..763734e 100644 --- a/content/script.js +++ b/content/script.js @@ -1,4 +1,10 @@ function createSnowFlake() { + setTimeout(() => createSnowFlake(), 50 / Math.log10(window.innerWidth / 1000 + 1)); + + if (document.hidden) { + return; + } + const snowFlake = document.createElementNS("http://www.w3.org/2000/svg", "svg"); const snowFlakeInner = document.createElementNS("http://www.w3.org/2000/svg", "use"); @@ -11,13 +17,11 @@ function createSnowFlake() { snowFlake.style.left = Math.random() * 100 + '%'; snowFlake.style.animationDuration = (Math.random() * 3 + 2) * 1000 + 'ms'; snowFlake.style.opacity = Math.random(); - + snowFlake.addEventListener("animationend", () => snowFlake.remove()); snowFlake.appendChild(snowFlakeInner); document.body.appendChild(snowFlake); - - setTimeout(() => createSnowFlake(), 50 / Math.log10(window.innerWidth / 1000 + 1)); } createSnowFlake(); -- cgit v1.2.3-54-g00ecf