Greasy Fork is available in English.

Sploop Hat Macro & Menu

A script that includes hat macro & a menu

  1. // ==UserScript==
  2. // @name Sploop Hat Macro & Menu
  3. // @description A script that includes hat macro & a menu
  4. // @author DETIX
  5. // @version 2.1
  6. // @icon https://sploop.io/img/ui/favicon.png
  7. // @match *://sploop.io/*
  8. // @license MIT
  9. // @namespace https://greatest.deepsurf.us/users/1311498
  10. // ==/UserScript==
  11.  
  12. let DETIX;
  13.  
  14. function initialize(DETIX) {
  15. window.DETIX = DETIX;
  16. }
  17.  
  18. WebSocket.prototype.lastSend = WebSocket.prototype.send;
  19.  
  20. window.WebSocket = new Proxy(window.WebSocket, {
  21. construct(target, args) {
  22. const DETIX = new target(...args);
  23. if (!args[0].includes("sploop")) return DETIX;
  24. initialize(DETIX);
  25. return DETIX;
  26. }
  27. });
  28. WebSocket.prototype.lastSend = WebSocket.prototype.send;
  29. WebSocket.prototype.send = function(a) {
  30. this.lastSend(a);
  31. if (DETIX !== this) DETIX = this;
  32. };
  33.  
  34. const HATS = {
  35. BerserkerGear: {
  36. id: 2,
  37. defaultKey: "KeyB"
  38. },
  39. CrystalGear: {
  40. id: 4,
  41. defaultKey: "KeyG"
  42. },
  43. DemolistHat: {
  44. id: 11,
  45. defaultKey: "KeyZ"
  46. },
  47. SpikeGear: {
  48. id: 5,
  49. defaultKey: "KeyT"
  50. },
  51. BoostHat: {
  52. id: 7,
  53. defaultKey: "KeyH"
  54. },
  55. ScubaGear: {
  56. id: 9,
  57. defaultKey: "KeyM"
  58. }
  59. };
  60.  
  61. let chatWrapper = document.getElementById("chat-wrapper"),
  62. clanMenu = document.getElementById("clan-menu");
  63.  
  64. function check(){
  65. const chatWrapper = document.getElementById("chat-wrapper");
  66. const clanMenu = document.getElementById("clan-menu");
  67. if (chatWrapper.style.display === "block" || clanMenu.style.display === "block") return false;
  68. return true;
  69. }
  70. function EQUIP(id) {
  71. DETIX.send(new Uint8Array([5, id, 1]));
  72. DETIX.send(new Uint8Array([5, id, 0]));
  73. }
  74.  
  75. function handleKeys(event, pressedKey) {
  76. pressedKey = event.code;
  77. Object.keys(HATS).forEach(key => {
  78. if (HATS[key].defaultKey === pressedKey && check()) {
  79. EQUIP(HATS[key].id);
  80. }
  81. });
  82. }
  83. document.addEventListener("keypress", handleKeys);
  84. const menu = document.createElement("div");
  85. menu.id = "hatMacroMenu";
  86. menu.innerHTML = `
  87. <div class="hatMacroMenu-container">
  88. <h1>Menu<sub>By DETIX</sub></h1>
  89. ${Object.entries(HATS).map(([hatName, { defaultKey }]) => `
  90. <div class="hatMacroMenu-input">
  91. <label for="${hatName}">${hatName}:</label>
  92. <input type="text" id="${hatName}" value="${defaultKey}">
  93. </div>`).join('')}
  94. <button id="closeButton">Close</button>
  95. </div>`;
  96. menu.style.cssText = `
  97. position: absolute;
  98. top: 50%;
  99. left: 50%;
  100. transform: translate(-50%, -50%);
  101. background-color: #333;
  102. color: #fff;
  103. padding: 20px;
  104. border-radius: 10px;
  105. box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
  106. z-index: 9999;
  107. display: none;
  108. max-width: 300px;`;
  109.  
  110. const button = document.createElement("img");
  111. button.src = "https://sploop.io/img/ui/favicon.png";
  112. button.style.cssText = `
  113. position: fixed;
  114. top: 80px;
  115. left: 20px;
  116. width: 50px;
  117. cursor: pointer;`;
  118.  
  119. button.onclick = function() {
  120. menu.style.display = menu.style.display === "block" ? "none" : "block";
  121. };
  122.  
  123. document.body.appendChild(button);
  124. document.body.appendChild(menu);
  125.  
  126. const style = document.createElement("style");
  127. style.innerHTML = `
  128. .hatMacroMenu-container h1 {
  129. margin: 0 0 20px 0;
  130. padding: 0;
  131. text-align: center;
  132. font-size: 24px;
  133. }
  134. .hatMacroMenu-input {
  135. margin: 10px 0;
  136. }
  137. .hatMacroMenu-input label {
  138. display: block;
  139. font-size: 16px;
  140. margin-bottom: 5px;
  141. }
  142. .hatMacroMenu-input input {
  143. width: 100%;
  144. padding: 10px;
  145. font-size: 16px;
  146. border-radius: 5px;
  147. border: 1px solid #555;
  148. box-sizing: border-box;
  149. background-color: #444;
  150. color: #fff;
  151. }
  152. #closeButton {
  153. margin-top: 20px;
  154. padding: 10px 20px;
  155. background-color: #555;
  156. border: none;
  157. border-radius: 5px;
  158. color: #fff;
  159. font-size: 16px;
  160. cursor: pointer;
  161. }
  162. #closeButton:hover {
  163. background-color: #777;
  164. }`;
  165. document.head.appendChild(style);
  166.  
  167. document.getElementById("closeButton").addEventListener("click", function() {
  168. menu.style.display = "none";
  169. });
  170.  
  171. Object.keys(HATS).forEach(hatName => {
  172. const inputId = HATS[hatName].id;
  173. document.getElementById(hatName).addEventListener("keyup", function(event) {
  174. const pressedKey = event.code;
  175. document.getElementById(hatName).value = pressedKey;
  176. HATS[hatName].defaultKey = pressedKey;
  177. });
  178. });