Snowfall Effect

Snowfall animation with wind effect

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Snowfall Effect
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Snowfall animation with wind effect
// @match        *://*/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    const maxSnowflakes = 75;
    let snowflakeCount = 0;

    const style = document.createElement("style");
    style.innerHTML = `
        .snowflake {
            position: fixed;
            top: -50px;
            color: #FFF;
            font-size: 10px;
            opacity: 0.8;
            pointer-events: none;
            user-select: none;
            z-index: 9999;
        }
        @keyframes snowfall {
            to {
                transform: translateX(var(--wind)) translateY(100vh);
            }
        }
    `;
    document.head.appendChild(style);

    function createSnowflake() {
        if (snowflakeCount >= maxSnowflakes) return;
        const snowflake = document.createElement("div");
        snowflake.className = "snowflake";
        snowflake.innerHTML = "❄";
        snowflake.style.left = `${Math.random() * 100}vw`;
        snowflake.style.fontSize = `${Math.random() * 10 + 10}px`;
        snowflake.style.animation = `snowfall ${Math.random() * 3 + 5}s linear infinite`;
        snowflake.style.setProperty("--wind", `${Math.random() * 20 - 10}vw`);
        document.body.appendChild(snowflake);
        snowflakeCount++;

        snowflake.addEventListener("animationend", () => {
            snowflake.remove();
            snowflakeCount--;
        });
    }

    setInterval(createSnowflake, 200);
})();