Hat Switcher

When you log into the game, open the store and click on Z or R or Y. After that everything will work correctly.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Hat Switcher
// @namespace    -
// @version      0.1
// @description  When you log into the game, open the store and click on Z or R or Y. After that everything will work correctly.
// @author       Nudo
// @match        *://sploop.io/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=sploop.io
// @grant        none
// ==/UserScript==

(function anonymous() {
    const Switcher = {}

    Switcher.getHatElement = function(name) {
        return document.querySelector(`img[src="/img/entity/${name}.png?v=1923912"]`)
    }

    Switcher.getHatButton = function(name) {
        return this.getHatElement(name).nextSibling.nextSibling.querySelector("button")
    }

    Switcher.onMouseUp = function(event) {
        if (!event.target && !event.isTrusted) {
            return void 0
        }

        Switcher.event = event
    }

    document.addEventListener('mouseup', Switcher.onMouseUp)

    Switcher.getListener = function(button) {
        return window.getEventListeners(button).mouseup[0]
    }

    Switcher.getShop = function() {
        return document.getElementById("hat-menu")
    }

    Switcher.sleep = function() {
        return new Promise((resolve) => {
            setTimeout(resolve, 1000)
        })
    }

    Switcher.doClick = function(button) {
        if (!this.event) {
            return void 0
        }

        this.getShop().style.display = "flex"

        button.onmouseup(this.event)

        this.getShop().style.display = "none"
    }

    Switcher.clickToButton = function(name) {
        const button = this.getHatButton(name)

        this.doClick(button)
    }

    Switcher.hats = {
        "KeyY": "hat_3",
        "KeyT": "hat_1",
        "KeyZ": "hat_11",
        "LeftShift": "hat_6"
    }

    Switcher.onKeyDown = function(event) {
        const name = Switcher.hats[event.code]

        if (!name) {
            return void 0
        }

        Switcher.clickToButton(name)
    }

    document.addEventListener("keydown", Switcher.onKeyDown)
})()