Minefun Ultimate Weather FX

Real Rain + Thunder + Lava Sky

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, Greasemonkey alebo Violentmonkey.

Na inštaláciu tohto skriptu budete musieť nainštalovať rozšírenie, ako je napríklad Tampermonkey alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey alebo Userscripts.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie správcu používateľských skriptov.

(Už mám správcu používateľských skriptov, nechajte ma ho nainštalovať!)

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

(Už mám správcu používateľských štýlov, nechajte ma ho nainštalovať!)

// ==UserScript==
// @name         Minefun Ultimate Weather FX
// @namespace    http://tampermonkey.net/
// @version      5.0
// @description  Real Rain + Thunder + Lava Sky
// @author       You
// @match        *://minefun.io/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    // =========================
    // CANVAS
    // =========================
    const canvas = document.createElement("canvas");
    const ctx = canvas.getContext("2d");

    canvas.style.position = "fixed";
    canvas.style.top = "0";
    canvas.style.left = "0";
    canvas.style.width = "100%";
    canvas.style.height = "100%";
    canvas.style.pointerEvents = "none";
    canvas.style.zIndex = "999999";

    document.body.appendChild(canvas);

    function resize() {
        canvas.width = innerWidth;
        canvas.height = innerHeight;
    }

    resize();

    addEventListener("resize", resize);

    // =========================
    // STATES
    // =========================
    let rainEnabled = false;
    let lavaEnabled = false;
    let lightningEnabled = false;

    // =========================
    // DARK SKY
    // =========================
    const darkOverlay =
        document.createElement("div");

    darkOverlay.style.position = "fixed";
    darkOverlay.style.top = "0";
    darkOverlay.style.left = "0";
    darkOverlay.style.width = "100%";
    darkOverlay.style.height = "100%";
    darkOverlay.style.pointerEvents = "none";
    darkOverlay.style.zIndex = "999998";
    darkOverlay.style.transition = "0.5s";
    darkOverlay.style.background =
        "transparent";

    document.body.appendChild(darkOverlay);

    // =========================
    // RAIN
    // =========================
    const rain = [];

    for (let i = 0; i < 450; i++) {

        rain.push({
            x: Math.random() * innerWidth,
            y: Math.random() * innerHeight,
            speed: 16 + Math.random() * 8
        });
    }

    // =========================
    // LAVA PARTICLES
    // =========================
    const lava = [];

    for (let i = 0; i < 90; i++) {

        lava.push({
            x: Math.random() * innerWidth,
            y: Math.random() * innerHeight,
            r: 2 + Math.random() * 4,
            speed: 0.6 + Math.random() * 1.2,
            alpha: 0.2 + Math.random() * 0.4
        });
    }

    // =========================
    // LIGHTNING
    // =========================
    let bolts = [];

    function createBolt() {

        const startX =
            Math.random() * canvas.width;

        const points = [];

        let x = startX;
        let y = 0;

        points.push({ x, y });

        while (y < canvas.height * 0.9) {

            x +=
                (Math.random() - 0.5) * 45;

            y +=
                Math.random() * 40;

            points.push({ x, y });
        }

        bolts.push({
            points,
            alpha: 1
        });
    }

    // =========================
    // SOUNDS
    // =========================
    const rainAudio = new Audio(
        "https://cdn.pixabay.com/download/audio/2022/03/15/audio_c8d1d6d95f.mp3?filename=rain-ambient-110397.mp3"
    );

    rainAudio.loop = true;
    rainAudio.volume = 0.25;

    const thunderAudio = new Audio(
        "https://cdn.pixabay.com/download/audio/2022/03/15/audio_4d7f4e3130.mp3?filename=thunder-103602.mp3"
    );

    thunderAudio.volume = 0.45;

    // unlock browser audio
    document.addEventListener("click", () => {

        rainAudio.play()
            .then(() => rainAudio.pause())
            .catch(() => {});

    }, { once: true });

    // =========================
    // THUNDER TIMER
    // =========================
    setInterval(() => {

        if (!lightningEnabled) return;

        createBolt();

        thunderAudio.currentTime = 0;

        thunderAudio.play()
            .catch(() => {});

    }, 1500);

    // =========================
    // DRAW
    // =========================
    function draw() {

        ctx.clearRect(
            0,
            0,
            canvas.width,
            canvas.height
        );

        // =====================
        // LAVA SKY
        // =====================
        if (lavaEnabled) {

            // glow nền nhẹ
            ctx.fillStyle =
                "rgba(255,120,0,0.05)";

            ctx.fillRect(
                0,
                0,
                canvas.width,
                canvas.height
            );

            // hạt lava bay
            for (const l of lava) {

                ctx.beginPath();

                ctx.fillStyle =
                    `rgba(255,${80 + Math.random() * 120},0,${l.alpha})`;

                ctx.shadowBlur = 12;
                ctx.shadowColor = "orange";

                ctx.arc(
                    l.x,
                    l.y,
                    l.r,
                    0,
                    Math.PI * 2
                );

                ctx.fill();

                ctx.shadowBlur = 0;

                l.y += l.speed;

                if (l.y > canvas.height) {

                    l.y = -10;

                    l.x =
                        Math.random() *
                        canvas.width;
                }
            }
        }

        // =====================
        // RAIN
        // =====================
        if (rainEnabled) {

            ctx.strokeStyle =
                "rgba(180,200,255,0.78)";

            ctx.lineWidth = 1.4;

            for (const r of rain) {

                ctx.beginPath();

                ctx.moveTo(r.x, r.y);

                ctx.lineTo(
                    r.x - 3,
                    r.y + 18
                );

                ctx.stroke();

                r.y += r.speed;

                if (r.y > canvas.height) {

                    r.y = -20;

                    r.x =
                        Math.random() *
                        canvas.width;
                }
            }
        }

        // =====================
        // LIGHTNING
        // =====================
        for (
            let i = bolts.length - 1;
            i >= 0;
            i--
        ) {

            const bolt = bolts[i];

            ctx.beginPath();

            ctx.strokeStyle =
                `rgba(255,255,255,${bolt.alpha})`;

            ctx.shadowBlur = 18;
            ctx.shadowColor = "white";

            ctx.lineWidth = 3;

            const pts = bolt.points;

            ctx.moveTo(
                pts[0].x,
                pts[0].y
            );

            for (
                let p = 1;
                p < pts.length;
                p++
            ) {

                ctx.lineTo(
                    pts[p].x,
                    pts[p].y
                );
            }

            ctx.stroke();

            ctx.shadowBlur = 0;

            bolt.alpha -= 0.08;

            if (bolt.alpha <= 0) {

                bolts.splice(i, 1);
            }
        }

        requestAnimationFrame(draw);
    }

    draw();

    // =========================
    // UI
    // =========================
    const panel =
        document.createElement("div");

    panel.style.position = "fixed";
    panel.style.top = "12px";
    panel.style.left = "12px";

    panel.style.zIndex = "1000000";

    panel.style.display = "flex";
    panel.style.gap = "4px";

    panel.style.background =
        "rgba(0,0,0,0.25)";

    panel.style.backdropFilter =
        "blur(4px)";

    panel.style.padding = "4px";

    panel.style.borderRadius = "999px";

    panel.style.userSelect = "none";

    document.body.appendChild(panel);

    function makeBtn(text, color) {

        const b =
            document.createElement("button");

        b.textContent = text;

        b.style.width = "30px";
        b.style.height = "30px";

        b.style.border = "none";

        b.style.borderRadius = "50%";

        b.style.background = color;

        b.style.color = "white";

        b.style.fontSize = "11px";

        b.style.cursor = "pointer";

        b.style.opacity = "0.45";

        return b;
    }

    const rainBtn =
        makeBtn("🌧", "#3498db");

    const lavaBtn =
        makeBtn("🔥", "#ff6600");

    const lightBtn =
        makeBtn("⚡", "#cccccc");

    panel.appendChild(rainBtn);
    panel.appendChild(lavaBtn);
    panel.appendChild(lightBtn);

    // =========================
    // BUTTON EVENTS
    // =========================

    rainBtn.onclick = () => {

        rainEnabled =
            !rainEnabled;

        rainBtn.style.opacity =
            rainEnabled ? "1" : "0.45";

        if (rainEnabled) {

            darkOverlay.style.background =
                "rgba(0,0,0,0.18)";

            rainAudio.play()
                .catch(() => {});

        } else {

            rainAudio.pause();

            darkOverlay.style.background =
                "transparent";
        }
    };

    lavaBtn.onclick = () => {

        lavaEnabled =
            !lavaEnabled;

        lavaBtn.style.opacity =
            lavaEnabled ? "1" : "0.45";
    };

    lightBtn.onclick = () => {

        lightningEnabled =
            !lightningEnabled;

        lightBtn.style.opacity =
            lightningEnabled
                ? "1"
                : "0.45";
    };

    // =========================
    // DRAG UI
    // =========================
    let dragging = false;

    let offsetX = 0;
    let offsetY = 0;

    panel.addEventListener(
        "mousedown",
        (e) => {

            dragging = true;

            offsetX =
                e.clientX -
                panel.offsetLeft;

            offsetY =
                e.clientY -
                panel.offsetTop;
        }
    );

    document.addEventListener(
        "mouseup",
        () => {

            dragging = false;
        }
    );

    document.addEventListener(
        "mousemove",
        (e) => {

            if (!dragging) return;

            panel.style.left =
                (e.clientX - offsetX) +
                "px";

            panel.style.top =
                (e.clientY - offsetY) +
                "px";
        }
    );

})();