Bloxd Keep Run / Crouch

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

目前為 2024-01-28 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Bloxd Keep Run / Crouch
// @namespace    http://tampermonkey.net/
// @version      2.0.5
// @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.querySelector('.WholeAppWrapper').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()
    })

    setInterval(() => {
        if (isKeepingRunning && !isKeepingCrouching) {
            document.dispatchEvent(shiftDown)
        }
        if (isKeepingCrouching && !isKeepingRunning) {
            document.dispatchEvent(cDown)
        }
    }, 100)

    updateInfoDisplay()
})();