MooMoo.io - 1.8.0 Toggle Menus

Press "." to Toggle the Store menu and Press "," to Toggle the Alliance menu

您需要先安裝使用者腳本管理器擴展,如 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 - 1.8.0 Toggle Menus
// @author      Seryo
// @description Press "." to Toggle the Store menu and Press "," to Toggle the Alliance menu
// @version     0.1
// @match       *://*.moomoo.io/*
// @namespace   https://greasyfork.org/users/1190411
// @icon        https://cdn.glitch.com/82ae8945-dcc6-4276-98a9-665381b4cd2b/cursor12.png
// @run-at      document-end
// @license     MIT
// @grant       GM_info
// ==/UserScript==

(function () {
  'use strict';

  let allianceMenu = document.getElementById('allianceMenu');
  let storeMenu = document.getElementById('storeMenu');

  document.addEventListener('keydown', function (event) {
    if (shouldHandleMenus(event)) {
      if (event.key === ',') {
        toggleMenu(allianceMenu, storeMenu);
      } else if (event.key === '.') {
        toggleMenu(storeMenu, allianceMenu);
      }
    }
  });

  function shouldHandleMenus(event) {
    const chatboxActive = document.activeElement.id.toLowerCase() === 'chatbox';
    const allianceInputActive = document.activeElement.id.toLowerCase() === 'allianceinput';

    return !chatboxActive && !allianceInputActive;
  }

  function toggleMenu(menu, otherMenu) {
    if (menu.style.display === 'none' || menu.style.display === '') {
      menu.style.display = 'block';
      if (otherMenu.style.display !== 'none') {
        otherMenu.style.display = 'none';
      }
    } else {
      menu.style.display = 'none';
    }
  }
})();