Krunker CSS editor

The best Krunker CSS editor

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Krunker CSS editor
// @version      6.9.5
// @description  The best Krunker CSS editor
// @author       iCottage
// @match        *://krunker.io/*
// @exclude      *://krunker.io/editor*
// @exclude      *://krunker.io/social*
// @run-at       document-end
// @license      MIT
// @grant        none
// @icon         https://www.google.com/s2/favicons?domain=krunker.io
// @namespace https://greasyfork.org/users/1229506
// ==/UserScript==

(function () {
    const defaultCssUrl = "https://css.reizu.moe/reizu/main_custom.css";
    let cssUrl = defaultCssUrl;

    // Create CSS input field
    const cssInputField = document.createElement('input');
    cssInputField.type = 'text';
    cssInputField.value = cssUrl;
    cssInputField.placeholder = 'Enter CSS URL';
    cssInputField.style.position = 'fixed';
    cssInputField.style.top = '10px';
    cssInputField.style.left = '10px';
    cssInputField.style.zIndex = '9999';
    cssInputField.style.display = 'none';
    document.body.appendChild(cssInputField);

    // Function to toggle CSS input field visibility
    function toggleCssInputField() {
        cssInputField.style.display = (cssInputField.style.display === 'none') ? 'block' : 'none';
        if (cssInputField.style.display === 'block') {
            releaseMouseLock();
        }
    }

    // Function to release mouse lock
    function releaseMouseLock() {
        document.exitPointerLock();
    }

    // Function to apply new CSS
    function applyNewCss() {
        Array.from(document.styleSheets).forEach(css => {
            if (css.href && css.href.includes("main_custom.css")) {
                if (cssUrl.startsWith("http") && cssUrl.endsWith(".css")) {
                    css.ownerNode.href = cssUrl;
                }
            }
        });
    }

    // Event listener to toggle CSS input field on P key press
    window.addEventListener('keydown', (event) => {
        if (event.key.toUpperCase() === 'P') {
            toggleCssInputField();
        }
    });

    // Event listener to apply new CSS on Enter key press
    cssInputField.addEventListener('keydown', (event) => {
        if (event.key === 'Enter') {
            cssUrl = cssInputField.value.trim() || defaultCssUrl;
            applyNewCss();
            toggleCssInputField();
        }
    });

    // Event listener to hide CSS input field when clicked outside
    document.addEventListener('click', (event) => {
        if (!cssInputField.contains(event.target)) {
            cssInputField.style.display = 'none';
        }
    });

    // Apply initial CSS on page load
    window.addEventListener('DOMContentLoaded', applyNewCss);
})();