Greasy Fork

Greasy Fork is available in English.

MooMoo.io Key Rebinder

F -> Hold Trap/Boost Pad / V -> Hold Spike / N -> Hold Windmill

目前为 2023-11-06 提交的版本,查看 最新版本

// ==UserScript==
// @name         MooMoo.io Key Rebinder
// @description  F -> Hold Trap/Boost Pad  /  V -> Hold Spike / N -> Hold Windmill
// @author       KOOKY WARRIOR
// @match        *://*.moomoo.io/*
// @icon         https://moomoo.io/img/favicon.png?v=1
// @require      https://cdnjs.cloudflare.com/ajax/libs/msgpack-lite/0.1.26/msgpack.min.js
// @require 	 http://greasyfork.icu/scripts/478839-moomoo-io-packet-code/code/MooMooio%20Packet%20Code.js?version=1274028
// @run-at       document-start
// @grant        unsafeWindow
// @license      MIT
// @version      0.7
// @namespace    http://greasyfork.icu/users/999838
// ==/UserScript==

;(async () => {
	unsafeWindow.keyRebinder = true

	let items = [],
		weapons = [],
		inGame = false,
		keys = {},
		ws = await new Promise(async (resolve) => {
			let { send } = WebSocket.prototype

			WebSocket.prototype.send = function (...x) {
				send.apply(this, x)
				this.send = send
				this.iosend = function (...datas) {
					const [packet, data] = datas
					this.send(msgpack.encode([packet, data]))
				}
				this.addEventListener("message", (e) => {
					if (!e.origin.includes("moomoo.io") && unsafeWindow.privateServer) return
					const [packet, data] = msgpack.decode(new Uint8Array(e.data))
					switch (packet) {
						case OLDPACKETCODE.RECEIVE["1"]:
							inGame = true
							items = [0, 3, 6, 10]
							weapons = [0]
							break
						case OLDPACKETCODE.RECEIVE["11"]:
							inGame = false
							break
						case OLDPACKETCODE.RECEIVE["17"]:
							if (data[0]) {
								if (data[1]) weapons = data[0]
								else items = data[0]
							}
							break
					}
				})
				resolve(this)
			}
		})

	var observer = new MutationObserver((mutations) => {
		mutations.forEach((mutationRecord) => {
			if (document.getElementById("allianceMenu").style.display == "block" || document.getElementById("chatHolder").style.display == "block") {
				keys = {}
			}
		})
	})
	observer.observe(document.getElementById("allianceMenu"), {
		attributes: true,
		attributeFilter: ["style"]
	})
	observer.observe(document.getElementById("chatHolder"), {
		attributes: true,
		attributeFilter: ["style"]
	})

	unsafeWindow.addEventListener("keydown", (event) => {
		if (
			inGame &&
			!keys[event.code] &&
			document.getElementById("allianceMenu").style.display != "block" &&
			document.getElementById("chatHolder").style.display != "block"
		) {
			keys[event.code] = true
			if (event.code == "KeyF" && items[4]) {
				ws.iosend(OLDPACKETCODE.SEND["5"], [items[4], null])
			} else if (event.code == "KeyV") {
				ws.iosend(OLDPACKETCODE.SEND["5"], [items[2], null])
			} else if (event.code == "KeyN") {
				ws.iosend(OLDPACKETCODE.SEND["5"], [items[3], null])
			}
		}
	})

	unsafeWindow.addEventListener("keyup", (event) => {
		if (
			inGame &&
			keys[event.code] &&
			document.getElementById("allianceMenu").style.display != "block" &&
			document.getElementById("chatHolder").style.display != "block"
		) {
			keys[event.code] = false
		}
	})
})()