Motion Blur Thingy

Ehh kinda works but not REAL Motion Blur...

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey, Greasemonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Userscripts.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een gebruikersscriptbeheerder nodig.

(Ik heb al een user script manager, laat me het downloaden!)

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

(Ik heb al een beheerder - laat me doorgaan met de installatie!)

// ==UserScript==
// @name         Motion Blur Thingy
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Ehh kinda works but not REAL Motion Blur...
// @author       Ankit
// @match        https://bloxd.io/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    let lastHeading = null;
    let lastPitch = null;
    let currentBlur = 0;

    const MAX_BLUR = 6;
    const MULTIPLIER = 12;
    const SMOOTHING = 0.15;
    const THRESHOLD = 0.0005;

    function findNoa() {
        const isNoa = o =>
        o && typeof o === "object" &&
              o.entities?.getState &&
              o.camera?.getDirection &&
              o.world?.getBlock;

        const isEntityMgr = o =>
        o && typeof o === "object" &&
              o.entities?.getState;

        function scan(obj, check, seen = new Set()) {
            if (!obj || typeof obj !== "object" || seen.has(obj)) return null;
            seen.add(obj);

            try {
                if (check(obj)) return obj;
                for (const v of Object.values(obj)) {
                    const hit = scan(v, check, seen);
                    if (hit) return hit;
                }
            } catch {}
            return null;
        }

        function walk(fiber) {
            let n = fiber, i = 0;
            while (n && i++ < 40) {
                if (n.memoizedProps) {
                    const r =
                          scan(n.memoizedProps, isNoa) ||
                          scan(n.memoizedProps, isEntityMgr);
                    if (r) return r;
                }
                if (n.memoizedState) {
                    const r =
                          scan(n.memoizedState, isNoa) ||
                          scan(n.memoizedState, isEntityMgr);
                    if (r) return r;
                }
                n = n.return;
            }
            return null;
        }

        for (const el of document.querySelectorAll("*")) {
            const k = Object.keys(el).find(x => x.startsWith("__reactFiber$"));
            if (!k) continue;
            const r = walk(el[k]);
            if (r) return r;
        }

        return null;
    }

    function logNoa() {
        const InGame = document.querySelector(".HotBarContainer");

        if (InGame && !window.__noa) {
            window.__noa = findNoa();
        }
    }

    function normalizeAngle(delta) {
        if (delta > Math.PI) delta -= Math.PI * 2;
        if (delta < -Math.PI) delta += Math.PI * 2;
        return delta;
    }

    function motionBlurLoop() {
        const container = document.querySelector("#noa-container");
        if (!container || !window.__noa) {
            requestAnimationFrame(motionBlurLoop);
            return;
        }

        const cam = window.__noa.camera;

        const heading = cam.heading;
        const pitch = cam.pitch;

        if (lastHeading !== null) {
            let deltaYaw = normalizeAngle(heading - lastHeading);
            let deltaPitch = pitch - lastPitch;

            let velocity = Math.sqrt(deltaYaw * deltaYaw + deltaPitch * deltaPitch);

            let targetBlur = velocity > THRESHOLD
            ? Math.min(velocity * MULTIPLIER, MAX_BLUR)
            : 0;

            // Smooth interpolation
            currentBlur += (targetBlur - currentBlur) * SMOOTHING;

            container.style.filter =
                currentBlur > 0.01
                ? `blur(${currentBlur}px) brightness(1.03)`
            : "none";
        }

        lastHeading = heading;
        lastPitch = pitch;

        requestAnimationFrame(motionBlurLoop);
    }

    requestAnimationFrame(motionBlurLoop);
    requestAnimationFrame(logNoa);
})();