Moomoo.io - Hat Macro

This script can be toggled on or off with the 'P' key, and macros won't work while you're chatting or creating a tribe in the alliance menu.

目前為 2023-10-07 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Moomoo.io - Hat Macro
// @version      Beta
// @description  This script can be toggled on or off with the 'P' key, and macros won't work while you're chatting or creating a tribe in the alliance menu.
// @             Shortcuts:
// @             - No Hat: Shift
// @             - Bull Helmet: R
// @             - Tank Gear: Z
// @             - Soldier Helmet: G
// @             - Booster Hat: B
// @             - Flipper Hat: Y
// @             - Winter Cap: N
// @             - EMP Helmet: J
// @             - Fluff Head: I
// @             - Turret Gear: T
// @             - Spike Gear: H
// @             - Samurai Armor: U
// @             - Bearbarian Armor: M
// @             Feel free to mix and match.
// @author       Seryo
// @match        *://*.moomoo.io/*
// @icon         https://i.imgur.com/bA52hfN.jpg
// @license      MIT
// @grant        none
// @namespace https://greasyfork.org/users/1190411
// ==/UserScript==

(function() {
    var macrosToggle = 1;
    var macroEventListener = null;

    function isChatOpen() {
        return document.activeElement.id.toLowerCase() === 'chatbox';
    }

    function isAllianceInputActive() {
        return document.activeElement.id.toLowerCase() === 'allianceinput';
    }

    function shouldHandleHotkeys() {
        return !isChatOpen() && !isAllianceInputActive();
    }

    function toggleMacros() {
        macrosToggle = (macrosToggle + 1) % 2;
        document.title = macrosToggle === 1 ? "нaтѕ-on" : "нaтѕ-oғғ";

        if (macrosToggle === 1) {
            macroEventListener = function(e) {
                if (shouldHandleHotkeys()) {
                    switch (e.keyCode) {
                        case 16: storeEquip(0); break; // Shift
                        case 82: storeEquip(7); break; // R
                        case 90: storeEquip(40); break; // Z
                        case 71: storeEquip(6); break; // G
                        case 66: storeEquip(12); break; // B
                        case 89: storeEquip(31); break; // Y
                        case 78: storeEquip(15); break; // N
                        case 74: storeEquip(22); break; // J
                        case 73: storeEquip(30); break; // I
                        case 84: storeEquip(53); break; // T
                        case 77: storeEquip(26); break; // H
                        case 85: storeEquip(20); break; // U
                        case 72: storeEquip(11); break; // M
                    }
                }
            };

            document.addEventListener('keydown', macroEventListener);
        } else {
            document.removeEventListener('keydown', macroEventListener);
            macroEventListener = null;
        }
    }

    document.addEventListener('keydown', (e) => {
        if (e.keyCode === 80 && !isChatOpen() && !isAllianceInputActive()) {
            toggleMacros();
        }
    });

    var headerText = document.querySelector("h1").textContent;
    var macrosEnabled = headerText.includes("Macros On");

    if (macrosEnabled) {
        toggleMacros();
    }
})();