Moomoo.io 1.8.0 Hat Macro & Interactive Menu

Toggle Macros with "L". Macros won't work while chatting or writing on the alliance tribe input.

  1. // ==UserScript==
  2. // @name Moomoo.io 1.8.0 Hat Macro & Interactive Menu
  3. // @author Seryo
  4. // @description Toggle Macros with "L". Macros won't work while chatting or writing on the alliance tribe input.
  5. // @version 1.8.2
  6. // @match *://*.moomoo.io/*
  7. // @namespace https://greasyfork.org/users/1190411
  8. // @icon https://cdn.glitch.com/82ae8945-dcc6-4276-98a9-665381b4cd2b/cursor12.png
  9. // @license MIT
  10. // @grant none
  11. // @run-at document-end
  12. // ==/UserScript==
  13.  
  14. (function () {
  15. var mt = 0;
  16. var mel = null;
  17. var mv = false;
  18. var isd = false;
  19. var ix;
  20. var iy;
  21. var menuElement = null;
  22.  
  23. var hhk = {
  24. 0: 0, 51: 0, 50: 0, 28: 0, 29: 0, 30: 0, 36: 0, 37: 0, 38: 0, 44: 0,
  25. 35: 0, 42: 0, 43: 0, 49: 0, 57: 0, 8: 0, 2: 0, 15: 0, 5: 0, 4: 0,
  26. 18: 0, 31: 0, 1: 0, 10: 0, 48: 0, 6: 0, 23: 0, 13: 0, 9: 0, 32: 0,
  27. 7: 0, 22: 0, 12: 0, 26: 0, 21: 0, 46: 0, 14: 0, 11: 0, 53: 0, 20: 0,
  28. 58: 0, 27: 0, 40: 0, 52: 0, 55: 0, 56: 0
  29. };
  30.  
  31. function iso() {
  32. return document.activeElement.id.toLowerCase() === 'chatbox';
  33. }
  34.  
  35. function iaia() {
  36. return document.activeElement.id.toLowerCase() === 'allianceinput';
  37. }
  38.  
  39. function shhk() {
  40. return !iso() && !iaia();
  41. }
  42.  
  43. function toggleMacros() {
  44. mt = (mt + 1) % 2;
  45. document.title = mt === 1 ? "𝙷𝚊𝚝𝚜 𝙾𝙽" : "𝙷𝚊𝚝𝚜 𝙾𝙵𝙵";
  46.  
  47. var macroStateElement = document.getElementById("macroState");
  48. macroStateElement.textContent = mt === 1 ? "On" : "Off";
  49.  
  50. if (mt === 1) {
  51. mel = function (e) {
  52. if (shhk()) {
  53. for (var hatId in hhk) {
  54. if (e.keyCode === hhk[hatId]) {
  55. storeEquip(hatId);
  56. break;
  57. }
  58. }
  59. }
  60. };
  61.  
  62. document.addEventListener('keydown', mel);
  63. } else {
  64. document.removeEventListener('keydown', mel);
  65. mel = null;
  66. }
  67. }
  68.  
  69. function toggleMenu() {
  70. var menuElement = document.getElementById('hatMacroMenu');
  71. if (mv) {
  72. menuElement.style.display = 'none';
  73. mv = false;
  74. } else {
  75. menuElement.style.display = 'block';
  76. mv = true;
  77. }
  78. }
  79.  
  80. function dragStart(e) {
  81. isd = true;
  82. ix = e.clientX - menuElement.getBoundingClientRect().left;
  83. iy = e.clientY - menuElement.getBoundingClientRect().top;
  84. }
  85.  
  86. function dragEnd() {
  87. isd = false;
  88. }
  89.  
  90. function drag(e) {
  91. if (!isd) return;
  92. menuElement.style.left = (e.clientX - ix) + 'px';
  93. menuElement.style.top = (e.clientY - iy) + 'px';
  94. }
  95.  
  96. function createMenu() {
  97. menuElement = document.createElement('div');
  98. menuElement.id = 'hatMacroMenu';
  99. menuElement.style.display = 'none';
  100. menuElement.style.background = 'rgba(0, 0, 0, 0.8)';
  101. menuElement.style.fontFamily = 'Hammersmith One, sans-serif';
  102. menuElement.style.position = 'absolute';
  103. menuElement.style.width = '300px';
  104. menuElement.style.height = '250px';
  105. menuElement.style.border = '1.5px solid #000';
  106. menuElement.style.borderRadius = '8px';
  107. menuElement.style.boxShadow = '0px 0px 10px rgba(0, 0, 0, 1)';
  108. menuElement.style.top = 'calc(20px + 2vh)';
  109. menuElement.style.right = 'calc(20px + 2vw)';
  110. menuElement.style.zIndex = '9999';
  111. menuElement.style.overflowY = 'auto';
  112. menuElement.style.color = '#fff';
  113. menuElement.style.fontSize = '17px !important';
  114. menuElement.style.boxShadow = '5px 5px 10px rgba(0, 0, 0, 0.4)';
  115. menuElement.style.padding = '18px';
  116. document.body.appendChild(menuElement);
  117.  
  118. var ohti = {0: "No Hat",51: "Moo Cap",50: "Apple Cap",28: "Moo Head",29: "Pig Head",30: "Fluff Head",
  119. 36: "Pandou Head",37: "Bear Head",38: "Monkey Head",44: "Polar Head",35: "Fez Hat",42: "Enigma Hat",
  120. 43: "Blitz Hat",49: "Bob XIII Hat",57: "Pumpkin",8: "Bummle Hat",2: "Straw Hat",15: "Winter Cap",
  121. 5: "Cowboy Hat",4: "Ranger Hat",18: "Explorer Hat",31: "Flipper Hat",1: "Marksman Cap",10: "Bush Gear",
  122. 48: "Halo",6: "Soldier Helmet",23: "Anti Venom Gear",13: "Medic Gear",9: "Miners Helmet",32: "Musketeer Hat",
  123. 7: "Bull Helmet",22: "Emp Helmet",12: "Booster Hat",26: "Barbarian Armor",21: "Plague Mask",46: "Bull Mask",
  124. 14: "Windmill Hat",11: "Spike Gear",53: "Turret Gear",20: "Samurai Armor",58: "Dark Knight",27: "Scavenger Gear",
  125. 40: "Tank Gear",52: "Thief Gear",55: "Bloodthirster",56: "Assassin Gear"};
  126.  
  127. var predefinedKeycodes = {
  128. "No Hat": 16,
  129. "Soldier Helmet": 71,
  130. "Bull Helmet": 82,
  131. "Spike Gear": 77,
  132. "Booster Hat": 66,
  133. "Winter Cap": 78,
  134. "Samurai Armor": 85,
  135. "Bearbarian Armor": 75,
  136. "Flipper Hat": 89,
  137. "Tank Gear": 90,
  138. "Assassin Gear": 73,
  139. "Turret Gear": 84
  140. };
  141.  
  142. for (var hatId in ohti) {
  143. var input = ohti[hatId];
  144. var keycode = predefinedKeycodes[input];
  145. hhk[hatId] = keycode;
  146. }
  147.  
  148. var tableHTML = `
  149. <h1 style="font-size: 28px !important; margin-top: 15px; text-align: center;">Hat Shortcuts <span id="macroState"">Off</span></h1>
  150. <hr>
  151. <table style="margin: 0 auto; text-align: center;">
  152. <tr>
  153. <td><b>Hats</b></td>
  154. <td></td>
  155. <td><b>Keycodes</b></td>
  156. </tr>`;
  157.  
  158. var ukwii = {
  159. 51: "https://static.wikia.nocookie.net/moom/images/a/ac/Hat_51.png",
  160. 50: "https://static.wikia.nocookie.net/moom/images/2/2e/Hat_50.png",
  161. 28: "https://static.wikia.nocookie.net/moom/images/5/58/Hat_28.png",
  162. 29: "https://static.wikia.nocookie.net/moom/images/0/0d/Hat_29.png",
  163. 30: "https://static.wikia.nocookie.net/moom/images/4/49/Hat_30.png",
  164. 36: "https://static.wikia.nocookie.net/moom/images/4/4e/Hat_36.png",
  165. 37: "https://static.wikia.nocookie.net/moom/images/b/bf/Hat_37.png",
  166. 38: "https://static.wikia.nocookie.net/moom/images/b/b6/Hat_38.png",
  167. 44: "https://static.wikia.nocookie.net/moom/images/2/21/Hat_44.png",
  168. 35: "https://static.wikia.nocookie.net/moom/images/d/df/Hat_35.png",
  169. 42: "https://static.wikia.nocookie.net/moom/images/9/90/Hat_42.png",
  170. 43: "https://static.wikia.nocookie.net/moom/images/f/fb/Hat_43.png",
  171. 49: "https://static.wikia.nocookie.net/moom/images/b/b7/Hat_49.png",
  172. 57: "https://static.wikia.nocookie.net/moom/images/7/7c/Hat_57.png",
  173. 8: "https://static.wikia.nocookie.net/moom/images/e/e9/Hat_8.png",
  174. 2: "https://static.wikia.nocookie.net/moom/images/9/9b/Hat_2.png",
  175. 15: "https://static.wikia.nocookie.net/moom/images/6/66/Hat_15.png",
  176. 5: "https://static.wikia.nocookie.net/moom/images/5/51/Hat_5.png",
  177. 4: "https://static.wikia.nocookie.net/moom/images/e/e8/Hat_4.png",
  178. 18: "https://static.wikia.nocookie.net/moom/images/a/ad/Hat_18.png",
  179. 31: "https://static.wikia.nocookie.net/moom/images/4/43/Hat_31.png",
  180. 1: "https://static.wikia.nocookie.net/moom/images/b/b1/Hat_1.png",
  181. 10: "https://static.wikia.nocookie.net/moom/images/9/90/Hat_10.png",
  182. 48: "https://static.wikia.nocookie.net/moom/images/d/d4/Hat_48.png",
  183. 6: "https://static.wikia.nocookie.net/moom/images/3/3f/Hat_6.png",
  184. 23: "https://static.wikia.nocookie.net/moom/images/b/b1/Hat_23.png",
  185. 13: "https://static.wikia.nocookie.net/moom/images/b/b0/Hat_13.png",
  186. 9: "https://static.wikia.nocookie.net/moom/images/e/eb/Hat_9.png",
  187. 32: "https://static.wikia.nocookie.net/moom/images/4/45/Hat_32.png",
  188. 7: "https://static.wikia.nocookie.net/moom/images/f/f9/Hat_7.png",
  189. 22: "https://static.wikia.nocookie.net/moom/images/f/fd/Hat_22.png",
  190. 12: "https://static.wikia.nocookie.net/moom/images/3/31/Hat_12.png",
  191. 26: "https://static.wikia.nocookie.net/moom/images/1/11/Hat_26.png",
  192. 21: "https://static.wikia.nocookie.net/moom/images/c/c6/Hat_21.png",
  193. 46: "https://static.wikia.nocookie.net/moom/images/3/3f/Hat_46.png",
  194. 14: "https://static.wikia.nocookie.net/moom/images/4/42/Hat_14_P.png",
  195. 11: "https://static.wikia.nocookie.net/moom/images/a/a3/Hat_11_P.png",
  196. 53: "https://static.wikia.nocookie.net/moom/images/e/e8/Hat_53_P.png",
  197. 20: "https://static.wikia.nocookie.net/moom/images/2/2a/Hat_20.png",
  198. 58: "https://static.wikia.nocookie.net/moom/images/d/da/Hat_58.png",
  199. 27: "https://static.wikia.nocookie.net/moom/images/8/88/Hat_27.png",
  200. 40: "https://static.wikia.nocookie.net/moom/images/0/08/Hat_40.png",
  201. 52: "https://static.wikia.nocookie.net/moom/images/9/9b/Hat_52.png",
  202. 55: "https://static.wikia.nocookie.net/moom/images/0/0d/Hat_55.png",
  203. 56: "https://static.wikia.nocookie.net/moom/images/5/53/Hat_56.png"
  204. };
  205.  
  206. for (hatId in ohti) {
  207. input = ohti[hatId];
  208. keycode = hhk[hatId];
  209. var imagePath = ukwii[hatId];
  210.  
  211. if (keycode === undefined) {
  212. keycode = "";
  213. }
  214.  
  215. if (hatId === "0") {
  216. tableHTML += `
  217. <tr>
  218. <td>${input}</td>
  219. <td></td>
  220. <td>
  221. <input type="text" id="${input}Key" value="${keycode}" maxlength="3" oninput="this.value = this.value.replace(/[^0-9]/g, '')" style="width: 3em;">
  222. <span id="${input}KeyLabel" style="color: gray;"></span>
  223. </td>
  224. </tr>`;
  225. } else {
  226.  
  227. var imageWidth = "35px";
  228. var imageHeight = "35px";
  229.  
  230. tableHTML += `
  231. <tr>
  232. <td>${input}</td>
  233. <td><img src="${ukwii[hatId]}" alt="${input}" style="width: ${imageWidth}; height: ${imageHeight};"></td>
  234. <td>
  235. <input type="text" id="${input}Key" value="${keycode}" maxlength="3" oninput="this.value = this.value.replace(/[^0-9]/g, '')" style="width: 3em;">
  236. <span id="${input}KeyLabel" style="color: gray;"></span>
  237. </td>
  238. </tr>`;
  239. }
  240. }
  241.  
  242. tableHTML += `
  243. </tr>
  244. </table>
  245. <hr>
  246. <div style="text-align: center; margin-top: 20px;">
  247. <button id="Save">Save</button>
  248. </div>`;
  249.  
  250. menuElement.innerHTML = tableHTML;
  251.  
  252. function saveHotkeys() {
  253. var savedHotkeys = {};
  254.  
  255. for (var hatId in hhk) {
  256. var inputField = document.getElementById(`${ohti[hatId]}Key`);
  257. var nkc = parseInt(inputField.value);
  258. savedHotkeys[hatId] = nkc;
  259. }
  260.  
  261. localStorage.setItem('hhk', JSON.stringify(savedHotkeys));
  262. }
  263.  
  264. function loadHotkeys() {
  265. var savedHotkeysStr = localStorage.getItem('hhk');
  266. if (savedHotkeysStr) {
  267. var savedHotkeys = JSON.parse(savedHotkeysStr);
  268.  
  269. for (var hatId in savedHotkeys) {
  270. hhk[hatId] = savedHotkeys[hatId];
  271. var inputField = document.getElementById(`${ohti[hatId]}Key`);
  272. inputField.value = savedHotkeys[hatId];
  273. }
  274. }
  275. }
  276.  
  277. document.getElementById("Save").addEventListener("click", function () {
  278. for (var hatId in ohti) {
  279. var input = ohti[hatId];
  280. var nkc = parseInt(document.getElementById(`${input}Key`).value);
  281. hhk[hatId] = nkc;
  282. var keyLabel = document.getElementById(`${input}KeyLabel`);
  283. keyLabel.textContent = keyCodeToLabel(nkc);
  284. keyLabel.style.color = '#909090';
  285.  
  286. var macroStateElement = document.getElementById("macroState");
  287. macroStateElement.style.fontSize = "28px";
  288. }
  289. saveHotkeys();
  290. });
  291.  
  292. loadHotkeys();
  293.  
  294. function keyCodeToLabel(keyCode) {
  295. const keyMap = {
  296. 3: 'Cancel', 8: 'Backspace', 9: 'Tab', 12: 'Clear', 13: 'Enter', 16: 'Shift', 160: 'Shift', 17: 'Control', 161: 'Control',
  297. 18: 'Alt', 162: 'Alt', 19: 'Pause', 20: 'Caps Lock', 21: 'Unidentified', 25: 'Unidentified', 27: 'Escape', 28: 'Henkan',
  298. 29: 'Muhenkan', 32: '(blank space)', 33: 'PageUp', 34: 'PageDown', 35: 'End', 36: 'Home', 37: 'ArrowLeft', 38: 'ArrowUp',
  299. 39: 'ArrowRight', 40: 'ArrowDown', 41: 'Select', 42: 'Print', 43: 'Execute', 44: 'F13', 45: 'Insert', 46: 'Delete',
  300. 47: 'Help', 48: '0', 49: '1', 50: '2', 51: '3', 52: '4', 53: '5', 54: '6', 55: '7', 56: '8', 57: '9', 58: ':', 59: ';',
  301. 60: '<', 61: '=', 63: 'ß', 64: '@', 65: 'A', 66: 'B', 67: 'C', 68: 'D', 69: 'E', 70: 'F', 71: 'G', 72: 'H', 73: 'I',
  302. 74: 'J', 75: 'K', 76: 'L', 77: 'M', 78: 'N', 79: 'O', 80: 'P', 81: 'Q', 82: 'R', 83: 'S', 84: 'T', 85: 'U', 86: 'V',
  303. 87: 'W', 88: 'X', 89: 'Y', 90: 'Z', 91: 'Meta', 224: 'Meta', 92: 'Meta', 225: 'AltGraph', 93: 'ContextMenu', 95: 'Standby',
  304. 96: '0', 97: '1', 98: '2', 99: '3', 100: '4', 101: '5', 102: '6', 103: '7', 104: '8', 105: '9', 106: '*', 107: '+',
  305. 108: ',', 109: '-', 110: '.', 111: '/', 112: 'F1', 113: 'F2', 114: 'F3', 115: 'F4', 116: 'F5', 117: 'F6', 118: 'F7', 119: 'F8',
  306. 120: 'F9', 121: 'F10', 122: 'F11', 123: 'F12', 124: 'F13', 125: 'F14', 126: 'F15', 127: 'F16', 128: 'F17', 129: 'F18',
  307. 130: 'F19', 131: 'F20', 132: 'F21', 133: 'F22', 134: 'F23', 135: 'F24', 136: 'F25', 137: 'F26', 138: 'F27', 139: 'F28',
  308. 140: 'F29', 141: 'F30', 142: 'F31', 143: 'F32', 144: 'NumLock', 145: 'ScrollLock', 151: 'Airplane Mode', 161: 'Volume Mute',
  309. 162: 'Volume Down', 163: 'Volume Up', 186: ';', 187: '=', 188: ',', 189: '-', 190: '.', 191: '/', 192: '`', 193: '/',
  310. 219: '[', 220: '\\', 221: ']', 222: "'", 223: '`', 224: 'Meta', 225: 'AltGraph', 226: '\\', 229: 'Non-conversion',
  311. 230: 'Alphanumeric', 231: 'Hiragana/Katakana', 233: 'Zenkaku/Hankaku', 234: 'Kanji Mode', 240: 'WakeUp', 255: 'WakeUp',
  312. default: '',
  313. };
  314.  
  315. return keyMap[keyCode] || '';
  316. }
  317.  
  318. menuElement.querySelectorAll('span, td, p').forEach(element => {
  319. element.style.fontSize = '17px';
  320. element.style.color = '#fff';
  321. });
  322.  
  323. menuElement.addEventListener('mousedown', dragStart);
  324. menuElement.addEventListener('mouseup', dragEnd);
  325. menuElement.addEventListener('mousemove', drag);
  326. document.getElementById("Save").click();
  327.  
  328. var Save = document.getElementById("Save");
  329. Save.addEventListener('click', saveHotkeys);
  330. document.getElementById("Save").click();
  331.  
  332. }
  333.  
  334. createMenu();
  335.  
  336. function saveHotkeys() {
  337. for (var hatId in hhk) {
  338. (function (currentHatId) {
  339. var inputField = document.getElementById("hat" + currentHatId + "Key");
  340. var nkc = parseInt(inputField.value);
  341. hhk[currentHatId] = nkc;
  342.  
  343. document.removeEventListener('keydown', onKeydown);
  344. document.addEventListener('keydown', onKeydown);
  345.  
  346. function onKeydown(e) {
  347. if (e.keyCode === nkc && shhk()) {
  348. storeEquip(currentHatId);
  349. }
  350. }
  351. })(hatId);
  352. }
  353. }
  354.  
  355. document.addEventListener('keydown', function (e) {
  356. if (e.keyCode === 76 && !iso() && !iaia()) {
  357. toggleMacros();
  358. } else if (e.keyCode === 27 && shhk() && storeMenu.style.display !== 'block') {
  359. toggleMenu();
  360. }
  361. });
  362.  
  363. var headerText = document.querySelector('h1').textContent;
  364. var macrosEnabled = headerText.includes('Macros On');
  365.  
  366. if (macrosEnabled) {
  367. toggleMacros();
  368. }
  369. })();