Hat Switcher

When you log into the game, open the store and click on Z or R or Y. After that everything will work correctly.

  1. // ==UserScript==
  2. // @name Hat Switcher
  3. // @namespace -
  4. // @version 0.1
  5. // @description When you log into the game, open the store and click on Z or R or Y. After that everything will work correctly.
  6. // @author Nudo
  7. // @match *://sploop.io/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=sploop.io
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function anonymous() {
  13. const Switcher = {}
  14.  
  15. Switcher.getHatElement = function(name) {
  16. return document.querySelector(`img[src="/img/entity/${name}.png?v=1923912"]`)
  17. }
  18.  
  19. Switcher.getHatButton = function(name) {
  20. return this.getHatElement(name).nextSibling.nextSibling.querySelector("button")
  21. }
  22.  
  23. Switcher.onMouseUp = function(event) {
  24. if (!event.target && !event.isTrusted) {
  25. return void 0
  26. }
  27.  
  28. Switcher.event = event
  29. }
  30.  
  31. document.addEventListener('mouseup', Switcher.onMouseUp)
  32.  
  33. Switcher.getListener = function(button) {
  34. return window.getEventListeners(button).mouseup[0]
  35. }
  36.  
  37. Switcher.getShop = function() {
  38. return document.getElementById("hat-menu")
  39. }
  40.  
  41. Switcher.sleep = function() {
  42. return new Promise((resolve) => {
  43. setTimeout(resolve, 1000)
  44. })
  45. }
  46.  
  47. Switcher.doClick = function(button) {
  48. if (!this.event) {
  49. return void 0
  50. }
  51.  
  52. this.getShop().style.display = "flex"
  53.  
  54. button.onmouseup(this.event)
  55.  
  56. this.getShop().style.display = "none"
  57. }
  58.  
  59. Switcher.clickToButton = function(name) {
  60. const button = this.getHatButton(name)
  61.  
  62. this.doClick(button)
  63. }
  64.  
  65. Switcher.hats = {
  66. "KeyY": "hat_3",
  67. "KeyT": "hat_1",
  68. "KeyZ": "hat_11",
  69. "LeftShift": "hat_6"
  70. }
  71.  
  72. Switcher.onKeyDown = function(event) {
  73. const name = Switcher.hats[event.code]
  74.  
  75. if (!name) {
  76. return void 0
  77. }
  78.  
  79. Switcher.clickToButton(name)
  80. }
  81.  
  82. document.addEventListener("keydown", Switcher.onKeyDown)
  83. })()