summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolpeon <git@volpeon.ink>2021-12-25 12:15:14 +0100
committerVolpeon <git@volpeon.ink>2021-12-25 12:15:14 +0100
commit339698cfb56c7216b3253423a12c7d4e98c73c0b (patch)
tree34ffc42b9b9141d724010a8c857555297e4e4b61
parentMore compact snowfall (diff)
downloadvolpeon.ink-339698cfb56c7216b3253423a12c7d4e98c73c0b.tar.gz
volpeon.ink-339698cfb56c7216b3253423a12c7d4e98c73c0b.tar.bz2
volpeon.ink-339698cfb56c7216b3253423a12c7d4e98c73c0b.zip
Don't generate snow if tab is inactive
-rw-r--r--content/script.js10
1 files changed, 7 insertions, 3 deletions
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 @@
1function createSnowFlake() { 1function createSnowFlake() {
2 setTimeout(() => createSnowFlake(), 50 / Math.log10(window.innerWidth / 1000 + 1));
3
4 if (document.hidden) {
5 return;
6 }
7
2 const snowFlake = document.createElementNS("http://www.w3.org/2000/svg", "svg"); 8 const snowFlake = document.createElementNS("http://www.w3.org/2000/svg", "svg");
3 const snowFlakeInner = document.createElementNS("http://www.w3.org/2000/svg", "use"); 9 const snowFlakeInner = document.createElementNS("http://www.w3.org/2000/svg", "use");
4 10
@@ -11,13 +17,11 @@ function createSnowFlake() {
11 snowFlake.style.left = Math.random() * 100 + '%'; 17 snowFlake.style.left = Math.random() * 100 + '%';
12 snowFlake.style.animationDuration = (Math.random() * 3 + 2) * 1000 + 'ms'; 18 snowFlake.style.animationDuration = (Math.random() * 3 + 2) * 1000 + 'ms';
13 snowFlake.style.opacity = Math.random(); 19 snowFlake.style.opacity = Math.random();
14 20
15 snowFlake.addEventListener("animationend", () => snowFlake.remove()); 21 snowFlake.addEventListener("animationend", () => snowFlake.remove());
16 22
17 snowFlake.appendChild(snowFlakeInner); 23 snowFlake.appendChild(snowFlakeInner);
18 document.body.appendChild(snowFlake); 24 document.body.appendChild(snowFlake);
19
20 setTimeout(() => createSnowFlake(), 50 / Math.log10(window.innerWidth / 1000 + 1));
21} 25}
22 26
23createSnowFlake(); 27createSnowFlake();