Bloxd Keep Run / Crouch

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

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Bloxd Keep Run / Crouch
// @namespace    http://tampermonkey.net/
// @version      2.0.3
// @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'}${isKeepingRunning ? '(x)' : ''}\nCrouching: ${isCrouching || 'no'}${isKeepingCrouching ? '(v)': ''}`
    }

    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 === '') {
                isRunning = 'Shift'
                isKeepingRunning = true
                document.dispatchEvent(shiftDown)
            } else if (isRunning === 'Shift') {
                isRunning = ''
                isKeepingRunning = false
                document.dispatchEvent(shiftUp)
            }
        } else if (e.key === 'v') {
            if (isCrouching === '') {
                isCrouching = 'c'
                isKeepingCrouching = true
                document.dispatchEvent(cDown)
            } else if (isCrouching === 'c') {
                isCrouching = ''
                isKeepingCrouching = false
                document.dispatchEvent(cUp)
            }
        } 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()
})();