Sploop.io Zoom hack

Allows to change zoom of the game using mouse wheels

ही स्क्रिप्ट इंस्टॉल करा?
लेखकाने सुचवलेली स्क्रिप्ट

तुम्हाला कदाचित ही स्क्रिप्टदेखील आवडेल: Dsync Client [Sploop.io].

ही स्क्रिप्ट इंस्टॉल करा

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name Sploop.io Zoom hack
// @author Murka
// @description Allows to change zoom of the game using mouse wheels
// @icon https://sploop.io/img/ui/favicon.png
// @version 1.1
// @match *://sploop.io/*
// @run-at document-start
// @grant none
// @license MIT
// @namespace https://greasyfork.org/users/919633
// ==/UserScript==
/* jshint esversion:6 */

/*
    Author: Murka
    Github: https://github.com/Murka007
    Discord: https://discord.gg/cPRFdcZkeD
    Greasyfork: https://greasyfork.org/en/users/919633
*/

(function() {
    "use strict";

    const log = console.log;
    function createHook(target, prop, callback) {
        const symbol = Symbol(prop);
        Object.defineProperty(target, prop, {
            get() {
                return this[symbol];
            },
            set(value) {
                callback(this, symbol, value);
            },
            configurable: true
        })
    }

    function findKey(target, value) {
        for (const key in target) {
            if (target[key] === value) return key;
        }
        return null;
    }

    const CONFIG = {
        maxWidth: {
            key: null,
            value: 1824 + 100 * 5,
            actual: 1824 + 100 * 5,
        },
        maxHeight: {
            key: null,
            value: 1026 + 100 * 5,
            actual: 1026 + 100 * 5,
        }
    };

    const dW = CONFIG.maxWidth.value;
    const dH = CONFIG.maxHeight.value;
    createHook(Object.prototype, "_a", function(that, symbol, value) {
        delete Object.prototype._a;
        that._a = value;

        const { maxWidth, maxHeight } = CONFIG;
        maxWidth.key = findKey(that, 1824);
        maxHeight.key = findKey(that, 1026);

        Object.defineProperty(that, maxWidth.key, { get: () => maxWidth.value })
        Object.defineProperty(that, maxHeight.key, { get: () => maxHeight.value })
    });

    const lerp = (start, end, factor) => {
        return (1 - factor) * start + factor * end;
    }

    const event = new Event("resize");
    const loop = () => {
        window.requestAnimationFrame(loop);

        const { maxWidth, maxHeight } = CONFIG;
        const blend = 0.09;
        maxWidth.value = lerp(maxWidth.value, maxWidth.actual, blend);
        maxHeight.value = lerp(maxHeight.value, maxHeight.actual, blend);
        window.dispatchEvent(event);
    }
    window.requestAnimationFrame(loop);

    let scale = 1;
    window.addEventListener("wheel", function(event) {
        const { maxWidth, maxHeight } = CONFIG;
        if (event.target.id !== "game-canvas" || maxWidth.key === null || maxHeight.key === null) return;

        if (event.deltaY < 0) {
            scale *= 1.1;
        } else {
            scale /= 1.1;
        }
        maxWidth.actual = dW * scale;
        maxHeight.actual = dH * scale;
    })

})();