Bloxd Keep Run / Crouch

Help you keep running or crouching in Bloxd.io with the key X and V.

当前为 2024-01-25 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Bloxd Keep Run / Crouch
// @namespace    http://tampermonkey.net/
// @version      2.0.1
// @description  Help you keep running or crouching in Bloxd.io with the key X and V.
// @icon         https://bloxd.io/apple-touch-icon.png?v=2
// @author       Gnosis
// @grant        none
// @run-at       document-start
// @license      GPL3
// @match        https://bloxd.io/*
// ==/UserScript==

(function() {
    'use strict';

    const infoDisplay = document.createElement('div')

    infoDisplay.style.position = 'absolute'
    infoDisplay.style.left = '0px'
    infoDisplay.style.bottom = '10em'
    infoDisplay.style.whiteSpace = 'pre'
    infoDisplay.style.padding = '5px'
    infoDisplay.style.background = '#00000088'
    infoDisplay.style.zIndex = '999'

    window.addEventListener('load', () => document.body.appendChild(infoDisplay))

    let isRunning = ''
    let isCrouching = ''
    let isKeepingRunning = false
    let isKeepingCrouching = false

    function updateInfoDisplay() {
        infoDisplay.textContent = `Running: ${isRunning || 'no'}\nCrouching: ${isCrouching || 'no'}`
    }

    const shiftKeyData = {
        key: 'Shift',
        code: 'ShiftLeft',
        keyCode: 16,
        which: 16,
        shiftKey: true,
        ctrlKey: false,
        altKey: false,
        metaKey: false,
        repeat: false,
        bubbles: true,
        cancelable: true
    }

    const cKeyData = {
        key: 'c',
        code: 'KeyC',
        keyCode: 67,
        which: 67,
        shiftKey: false,
        ctrlKey: false,
        altKey: false,
        metaKey: false,
        repeat: false,
        bubbles: true,
        cancelable: true
    }

    const shiftDown = new KeyboardEvent('keydown', shiftKeyData)

    const shiftUp = new KeyboardEvent('keyup', shiftKeyData)

    const cDown = new KeyboardEvent('keydown', cKeyData)

    const cUp = new KeyboardEvent('keyup', cKeyData)

    document.addEventListener('keyup', e => {
        if (e.key === 'x') {
            if (isRunning === '') {
                document.dispatchEvent(shiftDown)
                isRunning = 'Shift'
                isKeepingRunning = true
            } else if (isRunning === 'Shift') {
                document.dispatchEvent(shiftUp)
                isRunning = ''
                isKeepingRunning = false
            }
        } else if (e.key === 'v') {
            if (isCrouching === '') {
                document.dispatchEvent(cDown)
                isCrouching = 'c'
                isKeepingCrouching = true
            } else if (isCrouching === 'c') {
                document.dispatchEvent(cUp)
                isCrouching = ''
                isKeepingCrouching = false
            }
        } else if (e.key === 'Shift' && isRunning === 'Shift') {
            if (isKeepingRunning) {
                e.stopImmediatePropagation()
                return
            }
            isRunning = ''
        } else if (e.key === 'Ctrl' && isRunning === 'Ctrl') {
            isRunning = ''
        } else if (e.key === 'z' && isCrouching === 'z') {
            isCrouching = ''
        } else if (e.key === 'c' && isCrouching === 'c') {
            if (isKeepingCrouching) {
                e.stopImmediatePropagation()
                return
            }
            isCrouching = ''
        }
        updateInfoDisplay()
    })

    document.addEventListener('keydown', e => {
        if (e.key === 'Shift' && isRunning === '') {
            isRunning = 'Shift'
        } else if (e.key === 'Ctrl' && isRunning === '') {
            isRunning = 'Ctrl'
        } else if (e.key === 'z' && isCrouching === '') {
            isCrouching = 'z'
        } else if (e.key === 'c' && isCrouching === '') {
            isCrouching = 'c'
        }
        updateInfoDisplay()
    })

    updateInfoDisplay()
})();