Wormax.IO Smooth Zoom Enhancer (Fixed After Death)

Enables smooth zoom with mouse wheel, zoom reset, and persistent zoom after deaths in Wormax.IO.

目前為 2025-07-12 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Wormax.IO Smooth Zoom Enhancer (Fixed After Death)
// @namespace    http://tampermonkey.net/
// @version      1.4
// @description  Enables smooth zoom with mouse wheel, zoom reset, and persistent zoom after deaths in Wormax.IO.
// @author       you
// @match        *://*.wormax.io/*
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
    'use strict';

    let __cameraController = null;
    let __forcedZoom = 0.6;
    let __currentZoom = 1;
    let __smoothingLoop = null;
    let __zoomPatched = false;

    function scanForCameraController(root = window, visited = new WeakSet(), depth = 0, path = "window") {
        if (!root || typeof root !== "object" || visited.has(root) || depth > 10) return;
        visited.add(root);

        for (const key in root) {
            try {
                const val = root[key];
                const fullPath = `${path}['${key}']`;

                if (val && typeof val === "object") {
                    if (
                        typeof val.updateZoom === "boolean" &&
                        "follow" in val &&
                        val.camera && typeof val.camera.zoom === "number"
                    ) {
                        console.log("🎯 CameraController found at path:", fullPath);
                        __cameraController = val;
                        window.__cameraController = val;
                        return val;
                    }
                    const found = scanForCameraController(val, visited, depth + 1, fullPath);
                    if (found) return found;
                }
            } catch (e) {}
        }
        return null;
    }

    function patchZoomProperty() {
        if (!__cameraController || !__cameraController.camera) return;

        try {
            Object.defineProperty(__cameraController.camera, "zoom", {
                get() {
                    return __currentZoom;
                },
                set(v) {
                    __forcedZoom = Math.max(0.1, Math.min(5.0, v));
                },
                configurable: true
            });
            __zoomPatched = true;
            console.log("🔁 Zoom property patched");
        } catch (e) {
            console.warn("⚠️ Could not redefine zoom (may already be patched)");
        }
    }

    function startSmoothZoomLoop() {
        if (__smoothingLoop) clearInterval(__smoothingLoop);

        __smoothingLoop = setInterval(() => {
            if (!__cameraController || !__cameraController.camera) return;

            // Re-patch if zoom reverted (after death)
            if (!__zoomPatched || typeof __cameraController.camera.zoom !== "number") {
                patchZoomProperty();
            }

            const diff = __forcedZoom - __currentZoom;
            __currentZoom += diff * 0.02;
            if (Math.abs(diff) < 0.0001) {
                __currentZoom = __forcedZoom;
            }
            __cameraController.camera.update?.();
        }, 30);
    }

    function setupInputHandlers() {
        window.addEventListener("wheel", (e) => {
            const step = e.shiftKey ? 1.0 : e.altKey ? 0.1 : 0.5;
            const delta = e.deltaY > 0 ? step : -step;

            __forcedZoom += delta;
            __forcedZoom = Math.max(0.1, Math.min(5.0, __forcedZoom));
        }, { passive: false });

        document.addEventListener("keydown", (e) => {
            if (e.key.toLowerCase() === "r") {
                __forcedZoom = 1.0;
                console.log("🔄 Zoom reset to 1.0");
            }
        });
    }

    function observeGameLoop() {
        const observer = new MutationObserver(() => {
            const found = scanForCameraController();
            if (found) {
                __cameraController.updateZoom = false;
                patchZoomProperty();
                startSmoothZoomLoop();
            }
        });

        observer.observe(document.body, { childList: true, subtree: true });
    }

    // Init
    setupInputHandlers();
    observeGameLoop();
})();