Bonk.io RainbowStyle Enhanced

Similar to rstyle in bonk commands! :)

当前为 2024-12-16 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Bonk.io RainbowStyle Enhanced
  3. // @namespace http://tampermonkey.net/
  4. // @version 6.8
  5. // @description Similar to rstyle in bonk commands! :)
  6. // @author hello_me101
  7. // @match *://bonk.io/* *://bonkisback.io/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. 'use strict';
  13.  
  14. console.log("Enhanced RainbowStyle script loaded!");
  15.  
  16. // Rainbow color generator
  17. function generateRainbowColor(hue) {
  18. return `hsl(${hue}, 100%, 50%)`;
  19. }
  20.  
  21. // Apply rainbow effect to an element (name, level, or "level" label)
  22. function startRainbowEffect(targetElement) {
  23. let hue = 0;
  24. const interval = setInterval(() => {
  25. hue = (hue + 5) % 360; // Cycle through hues
  26. targetElement.style.color = generateRainbowColor(hue);
  27. }, 100); // Update every 100ms
  28. return interval;
  29. }
  30.  
  31. // Broadcast the RainbowStyle command via DOM
  32. function broadcastRainbowStyle(playerName) {
  33. const signal = document.createElement('div');
  34. signal.className = 'rainbow-command';
  35. signal.dataset.playerName = playerName;
  36. signal.style.display = 'none'; // Hidden element
  37. document.body.appendChild(signal);
  38.  
  39. setTimeout(() => signal.remove(), 100); // Remove signal after broadcasting
  40. }
  41.  
  42. // Listen for RainbowStyle broadcasts
  43. function listenForRainbowCommands() {
  44. const observer = new MutationObserver((mutations) => {
  45. for (const mutation of mutations) {
  46. mutation.addedNodes.forEach((node) => {
  47. if (node.className === 'rainbow-command') {
  48. const playerName = node.dataset.playerName;
  49. applyRainbowToPlayer(playerName);
  50. }
  51. });
  52. }
  53. });
  54.  
  55. observer.observe(document.body, { childList: true, subtree: true });
  56. }
  57.  
  58. // Apply the rainbow effect to a player by their name
  59. function applyRainbowToPlayer(playerName) {
  60. const playerElements = findPlayerElementsByName(playerName);
  61. if (playerElements) {
  62. console.log(`Applying rainbow effect to ${playerName}`);
  63. // Apply to all relevant parts: name, level, and "level" label
  64. if (playerElements.name) startRainbowEffect(playerElements.name);
  65. if (playerElements.level) startRainbowEffect(playerElements.level);
  66. if (playerElements.levelLabel) startRainbowEffect(playerElements.levelLabel);
  67. } else {
  68. console.warn(`Player elements for ${playerName} not found!`);
  69. }
  70. }
  71.  
  72. // Find the elements corresponding to a player's name, level, and "level" label
  73. function findPlayerElementsByName(playerName) {
  74. const playerList = document.querySelectorAll('.playerContainer'); // Adjust to Bonk.io structure
  75. for (const playerContainer of playerList) {
  76. const nameElement = playerContainer.querySelector('.playerName'); // Name element
  77. if (nameElement && nameElement.textContent.trim() === playerName) {
  78. // Assuming level and label are siblings of the name element; adjust selectors as needed
  79. const levelElement = playerContainer.querySelector('.playerLevel');
  80. const levelLabelElement = playerContainer.querySelector('.levelLabel');
  81. return {
  82. name: nameElement,
  83. level: levelElement,
  84. levelLabel: levelLabelElement
  85. };
  86. }
  87. }
  88. return null;
  89. }
  90.  
  91. // Monitor chat for the !rainbowstyle command
  92. function monitorChat() {
  93. const chatBox = document.querySelector(".chatBox"); // Adjust selector
  94. if (!chatBox) {
  95. console.warn("Chat box not found!");
  96. return;
  97. }
  98.  
  99. chatBox.addEventListener("keydown", (event) => {
  100. if (event.key === "Enter") {
  101. const chatInput = chatBox.value;
  102. if (chatInput.startsWith("!rainbowstyle")) {
  103. const playerName = getLocalPlayerName(); // Get your own name
  104. broadcastRainbowStyle(playerName);
  105. }
  106. chatBox.value = ""; // Clear input
  107. }
  108. });
  109. }
  110.  
  111. // Get the local player's name
  112. function getLocalPlayerName() {
  113. const localPlayer = document.querySelector('.localPlayerName'); // Adjust selector
  114. return localPlayer ? localPlayer.textContent.trim() : "UnknownPlayer";
  115. }
  116.  
  117. // Wait for game to load, then initialize
  118. function init() {
  119. const gameLoadedCheck = setInterval(() => {
  120. const chatBox = document.querySelector(".chatBox"); // Adjust selector
  121. if (chatBox) {
  122. clearInterval(gameLoadedCheck);
  123. listenForRainbowCommands();
  124. monitorChat();
  125. console.log("Enhanced RainbowStyle initialized!");
  126. }
  127. }, 1000); // Check every second
  128. }
  129.  
  130. // Start the script
  131. init();
  132. })();