Bonk.io Color Change Command

Adds a shared rainbow effect to the name, level, and the word 'level' in Bonk.io, visible to other users with this script.

נכון ליום 16-12-2024. ראה הגרסה האחרונה.

// ==UserScript==
// @name        Bonk.io Color Change Command
// @namespace   http://tampermonkey.net/
// @version     15.7.8
// @match       *://bonk.io/*
// @grant       GM_addStyle
// @description Adds a shared rainbow effect to the name, level, and the word 'level' in Bonk.io, visible to other users with this script.
// ==/UserScript==

// Listen for chat input to change colors
document.addEventListener('keydown', function (e) {
  if (e.key === 'Enter') {  // Check if the Enter key is pressed (for chat)
    setTimeout(() => {  // Wait for chat message to be input
      let chatInput = document.querySelector('input[type="text"]');
      if (!chatInput) return;

      let message = chatInput.value.trim();
      if (message.startsWith('/color')) {
        let args = message.split(' ');  // Split command and arguments
        let colorCommand = args[1];

        if (colorCommand) {
          // Apply the color or rainbow effect based on the command
          if (colorCommand === 'rainbow') {
            applyRainbowEffect();
          } else {
            applyColor(colorCommand);
          }
        }
      }
    }, 100);
  }
});

// Function to apply a single color to the player name and level
function applyColor(color) {
  GM_addStyle(`
    #player-name, #player-level, .level-text {
      color: ${color} !important;
    }
  `);
  console.log(`Changed name and level color to ${color}`);
}

// Function to apply a rainbow effect to the player name and level
function applyRainbowEffect() {
  GM_addStyle(`
    #player-name, #player-level, .level-text {
      color: red;
      animation: rainbow 3s infinite;
    }

    @keyframes rainbow {
      0% { color: red; }
      14% { color: orange; }
      28% { color: yellow; }
      42% { color: green; }
      57% { color: blue; }
      71% { color: indigo; }
      85% { color: violet; }
      100% { color: red; }
    }
  `);
  console.log('Applied rainbow effect to name and level');
}