MineCraft Keybind

Rebinds the MineFun.io controls for easier use by MineCraft players

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

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

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

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

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

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

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

Advertisement:

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

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

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

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

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

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

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

Advertisement:

// ==UserScript==
// @name         MineCraft Keybind
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Rebinds the MineFun.io controls for easier use by MineCraft players
// @author  Qwerty Matthew
// @license  MIT
// @match        https://minefun.io/*
// @match        https://*.minefun.io/*
// @run-at       document-start
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function remapKey(e) {
        // Leave the keys alone if you're typing in chat
        if (document.activeElement.tagName === 'INPUT' || document.activeElement.tagName === 'TEXTAREA') return;

        // 1. CROUCH: Left Shift triggers 'C'.
        if (e.code === 'ShiftLeft') {
            Object.defineProperty(e, 'code', { value: 'KeyC' });
        }
        // DISABLE ORIGINAL C: If you press physical C, stop it from triggering crouch
        else if (e.code === 'KeyC') {
            e.preventDefault();
            e.stopPropagation();
            Object.defineProperty(e, 'code', { value: 'None' });
        }

        // 2. SPRINT: Right Option / Alt (right of spacebar) triggers 'ShiftLeft'
        else if (e.code === 'AltRight') {
            Object.defineProperty(e, 'code', { value: 'ShiftLeft' });
        }

        // 3. INVENTORY: 'E' triggers 'X'.
        else if (e.code === 'KeyE') {
            Object.defineProperty(e, 'code', { value: 'KeyX' });
        }
        // DISABLE ORIGINAL X: If you press physical X, stop it from opening inventory
        else if (e.code === 'KeyX') {
            e.preventDefault();
            e.stopPropagation();
            Object.defineProperty(e, 'code', { value: 'None' });
        }
    }

    // Capture everything instantly on the way down and up
    window.addEventListener('keydown', remapKey, true);
    window.addEventListener('keyup', remapKey, true);

})();