Clear chat input - Bonk.io

Clears the chat input after a delay when you return to the lobby or go into a game

  1. // ==UserScript==
  2. // @name Clear chat input - Bonk.io
  3. // @version 1.0.4
  4. // @description Clears the chat input after a delay when you return to the lobby or go into a game
  5. // @author Excigma
  6. // @namespace https://gf.qytechs.cn/users/416480
  7. // @license GPL-3.0
  8. // @match https://bonk.io/gameframe-release.html
  9. // @run-at document-end
  10. // ==/UserScript==
  11.  
  12. // I have not thoroughly tested this to see if it works. Preliminary testing suggests it does.
  13.  
  14. // What this does:
  15. // - Clears the chat inputs after a delay after the round ends so some characters don't stay
  16. // bonk.io does it, but sometimes leaves a few characters if you're typing whilst the round ends
  17.  
  18. // I need to use semicolons correc;tky;;;;;
  19.  
  20. (() => {
  21. // Where the actual game is shown
  22. const gamerenderer = document.getElementById("gamerenderer");
  23.  
  24. // In-game chat input
  25. const ingamechatinputtext = document.getElementById("ingamechatinputtext");
  26. // Lobby chat input
  27. const newbonklobby_chat_input = document.getElementById("newbonklobby_chat_input");
  28.  
  29. // If all elements are found, run the code. If they're not found it'll error
  30. // shouldn't ever be false unless the button's IDs are renamed
  31. if (gamerenderer) {
  32. new MutationObserver(mutationsList => {
  33. for (const mutation of mutationsList) {
  34. // The "gamerenderer" has been hidden (this is used to render the match and stuffs)
  35. // In short, this means we have left the game or returned to the lobby
  36. if (gamerenderer.style.visibility === "hidden") {
  37. // Reset the chat in game after a small delay (should be copied to lobby chat by bonk)
  38. // Will "fix" bonk not clearing the chat properly (hopefully)
  39. setTimeout(() => {
  40. // Check if it's still hidden, otherwise it will break with map cycler
  41. if (gamerenderer.style.visibility === "hidden") ingamechatinputtext.value = "";
  42. }, 100);
  43. } else if (gamerenderer.style.visibility === "inherit") {
  44. // Reset the lobby chat due to the game starting
  45. setTimeout(() => {
  46. if (gamerenderer.style.visibility === "inherit") newbonklobby_chat_input.value = "";
  47. }, 100);
  48. }
  49. }
  50. }).observe(gamerenderer, {
  51. attributeFilter: ["style"]
  52. });
  53. }
  54. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址