Krunker CSS editor

The best Krunker CSS editor

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==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);
})();