Snowfall Effect

Snowfall animation with wind effect

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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);
})();