Enables smooth zoom with mouse wheel, zoom reset, and persistent zoom after deaths in Wormax.IO.
目前為
// ==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();
})();