Krunker CSS editor

The best Krunker CSS editor

  1. // ==UserScript==
  2. // @name Krunker CSS editor
  3. // @version 6.9.5
  4. // @description The best Krunker CSS editor
  5. // @author iCottage
  6. // @match *://krunker.io/*
  7. // @exclude *://krunker.io/editor*
  8. // @exclude *://krunker.io/social*
  9. // @run-at document-end
  10. // @license MIT
  11. // @grant none
  12. // @icon https://www.google.com/s2/favicons?domain=krunker.io
  13. // @namespace https://greasyfork.org/users/1229506
  14. // ==/UserScript==
  15.  
  16. (function () {
  17. const defaultCssUrl = "https://css.reizu.moe/reizu/main_custom.css";
  18. let cssUrl = defaultCssUrl;
  19.  
  20. // Create CSS input field
  21. const cssInputField = document.createElement('input');
  22. cssInputField.type = 'text';
  23. cssInputField.value = cssUrl;
  24. cssInputField.placeholder = 'Enter CSS URL';
  25. cssInputField.style.position = 'fixed';
  26. cssInputField.style.top = '10px';
  27. cssInputField.style.left = '10px';
  28. cssInputField.style.zIndex = '9999';
  29. cssInputField.style.display = 'none';
  30. document.body.appendChild(cssInputField);
  31.  
  32. // Function to toggle CSS input field visibility
  33. function toggleCssInputField() {
  34. cssInputField.style.display = (cssInputField.style.display === 'none') ? 'block' : 'none';
  35. if (cssInputField.style.display === 'block') {
  36. releaseMouseLock();
  37. }
  38. }
  39.  
  40. // Function to release mouse lock
  41. function releaseMouseLock() {
  42. document.exitPointerLock();
  43. }
  44.  
  45. // Function to apply new CSS
  46. function applyNewCss() {
  47. Array.from(document.styleSheets).forEach(css => {
  48. if (css.href && css.href.includes("main_custom.css")) {
  49. if (cssUrl.startsWith("http") && cssUrl.endsWith(".css")) {
  50. css.ownerNode.href = cssUrl;
  51. }
  52. }
  53. });
  54. }
  55.  
  56. // Event listener to toggle CSS input field on P key press
  57. window.addEventListener('keydown', (event) => {
  58. if (event.key.toUpperCase() === 'P') {
  59. toggleCssInputField();
  60. }
  61. });
  62.  
  63. // Event listener to apply new CSS on Enter key press
  64. cssInputField.addEventListener('keydown', (event) => {
  65. if (event.key === 'Enter') {
  66. cssUrl = cssInputField.value.trim() || defaultCssUrl;
  67. applyNewCss();
  68. toggleCssInputField();
  69. }
  70. });
  71.  
  72. // Event listener to hide CSS input field when clicked outside
  73. document.addEventListener('click', (event) => {
  74. if (!cssInputField.contains(event.target)) {
  75. cssInputField.style.display = 'none';
  76. }
  77. });
  78.  
  79. // Apply initial CSS on page load
  80. window.addEventListener('DOMContentLoaded', applyNewCss);
  81. })();