Sploop.io Hat Hotkeys

Allows to equip hats by pressing keys!

  1. // ==UserScript==
  2. // @name Sploop.io Hat Hotkeys
  3. // @author mohammad
  4. // @description Allows to equip hats by pressing keys!
  5. // @icon https://i.imgur.com/Q7vI76D.png
  6. // @version 0.2
  7. // @match *://sploop.io/*
  8. // @run-at document-start
  9. // @grant none
  10. // @license MIT
  11. // @namespace https://greasyfork.org/users/919633
  12. // ==/UserScript==
  13. /* jshint esversion:8 */
  14. (function() {
  15. "use strict";
  16.  
  17. const HATS = {
  18. BUSH_HAT: 0,
  19. BERSERKER: 1,
  20. JUNGLE_GEAR: 2,
  21. CRYSTAL_GEAR: 3,
  22. SPIKE_GEAR: 4,
  23. IMMUNITY_GEAR: 5,
  24. BOOST_HAT: 6,
  25. APPLE_HAT: 7,
  26. SCUBA_GEAR: 8,
  27. HOOD: 9,
  28. DEMOLIST: 10
  29. };
  30.  
  31. // Change your keybinds if you need to, get list of the key codes here: https://keycode.info
  32. // Please use `event.code` to change keybind
  33. // If you don't need a keybind, leave the field empty ""
  34.  
  35. const KEYBINDS = {
  36. [HATS.BUSH_HAT]: "",
  37. [HATS.BERSERKER]: "KeyB",
  38. [HATS.JUNGLE_GEAR]: "",
  39. [HATS.CRYSTAL_GEAR]: "KeyG",
  40. [HATS.SPIKE_GEAR]: "KeyT",
  41. [HATS.IMMUNITY_GEAR]: "KeyV",
  42. [HATS.BOOST_HAT]: "KeyM",
  43. [HATS.APPLE_HAT]: "",
  44. [HATS.SCUBA_GEAR]: "",
  45. [HATS.HOOD]: "KeyU",
  46. [HATS.DEMOLIST]: "KeyZ"
  47. };
  48.  
  49. // HAT EQUIP LOGIC GOES BELOW
  50.  
  51.  
  52.  
  53. const log = console.log;
  54. const storage = {
  55. get(key) {
  56. const value = localStorage.getItem(key);
  57. return value === null ? null : JSON.parse(value);
  58. },
  59. set(key, value) {
  60. localStorage.setItem(key, JSON.stringify(value));
  61. }
  62. };
  63.  
  64. function sleep(ms) {
  65. return new Promise(resolve => setTimeout(resolve, ms));
  66. }
  67.  
  68. function isInput() {
  69. return document.activeElement.tagName === "INPUT";
  70. }
  71.  
  72. function inGame() {
  73. const homepage = document.querySelector("#homepage");
  74. return homepage && homepage.style.display !== "flex";
  75. }
  76.  
  77. function canEquip() {
  78. return !isInput() && inGame();
  79. }
  80.  
  81. function createKeyboardEvent(type, code) {
  82. return new Proxy(new KeyboardEvent(type), {
  83. get(target, prop) {
  84. if (prop === "isTrusted") return true;
  85. if (prop === "target") return document.body;
  86. if (prop === "code") return code;
  87. return target[prop];
  88. }
  89. })
  90. }
  91.  
  92. function keypress(code) {
  93. const keydown = createKeyboardEvent("keydown", code);
  94. const keyup = createKeyboardEvent("keyup", code);
  95. window.onkeydown(keydown);
  96. window.onkeyup(keyup);
  97. }
  98.  
  99. function mouseup(target) {
  100. target.onmouseup(new Proxy(new MouseEvent("mouseup"), {
  101. get(target, prop) {
  102. if (prop === "isTrusted") return true;
  103. if (prop === "target") return target;
  104. return target[prop];
  105. }
  106. }));
  107. }
  108.  
  109. let equipToggle = false;
  110. async function equipHat(index) {
  111. if (!canEquip() || equipToggle) return;
  112. equipToggle = true;
  113.  
  114. const hatActionButton = document.querySelectorAll(".hat_action_button")[index];
  115. if (!hatActionButton) throw new Error("Failed to find hat with index: " + index);
  116.  
  117. const keybinds = storage.get("keybinds");
  118. const OpenShopKey = keybinds && keybinds[18] || "KeyN";
  119.  
  120. keypress(OpenShopKey);
  121. await sleep(150);
  122. if (hatActionButton.textContent === "BUY") {
  123. mouseup(hatActionButton);
  124. }
  125. mouseup(hatActionButton);
  126. await sleep(150);
  127. keypress(OpenShopKey);
  128.  
  129. await sleep(1500);
  130. equipToggle = false;
  131. }
  132.  
  133. window.addEventListener("keydown", function(event) {
  134. if (event.repeat) return;
  135.  
  136. for (const key in KEYBINDS) {
  137. if (event.code === KEYBINDS[key]) {
  138. equipHat(key);
  139. break;
  140. }
  141. }
  142. })
  143.  
  144. })();