View your weapon evolving
当前为
// ==UserScript==
// @name MooMoo.io Weapon Variant Progress
// @description View your weapon evolving
// @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
// @run-at document-start
// @grant unsafeWindow
// @license MIT
// @version 0.1.1
// @namespace https://greasyfork.org/users/999838
// ==/UserScript==
;(async () => {
unsafeWindow.weaponVariantProgress = true
document.addEventListener("DOMContentLoaded", () => {
const style = document.createElement("style")
style.innerText = `
.weaponVariantBar {
margin-top: 63px;
height: 3px;
border-radius: 4px;
}
@media only screen and (max-width: 896px) {
.weaponVariantBar {
margin-top: 41px;
}
}
`
document.head.appendChild(style)
})
let init = false,
playerSID,
weaponXP = {},
weaponIndex,
resources = {}
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(new Uint8Array(Array.from(msgpack.encode([packet, data]))))
}
if (!init) {
init = true
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 "1":
playerSID = data[0]
weaponXP = {}
weaponVariant = {}
const moofoll = localStorage.getItem("moofoll")
resources = {
food: moofoll ? 100 : 0,
stone: moofoll ? 100 : 0,
wood: moofoll ? 100 : 0,
points: moofoll ? 100 : 0
}
for (let i = 0; i < 16; i++) {
waitForElm("#variantBar" + i).then((element) => {
element.style.width = null
})
}
break
case "33":
for (let i = 0; i < data[0].length; i += 13) {
if (data[0][i] === playerSID) {
weaponIndex = data[0][i + 5]
if (weaponXP[weaponIndex] < unsafeWindow.config.weaponVariants[data[0][i + 6]].xp) {
weaponXP[weaponIndex] = unsafeWindow.config.weaponVariants[data[0][i + 6]].xp
}
break
}
}
break
case "9":
if (data[0] === "kills") break
const tmpIndex = weaponIndex
if (weaponXP[tmpIndex] == null) weaponXP[tmpIndex] = 0
if (data[1] - resources[data[0]] > 0) weaponXP[tmpIndex] += data[1] - resources[data[0]]
resources[data[0]] = data[1]
let tmpStyle
let tmpWidth
if (weaponXP[tmpIndex] >= 12000) {
tmpStyle = "none"
tmpWidth = 0
} else if (weaponXP[tmpIndex] >= 7000) {
tmpStyle = "rgb(255, 113, 111)"
tmpWidth = ((weaponXP[tmpIndex] - 7000) / 5000) * 100
} else if (weaponXP[tmpIndex] >= 3000) {
tmpStyle = "rgb(134, 181, 255)"
tmpWidth = ((weaponXP[tmpIndex] - 3000) / 4000) * 100
} else if (weaponXP[tmpIndex] >= 0) {
tmpStyle = "rgb(247, 207, 69)"
tmpWidth = (weaponXP[tmpIndex] / 3000) * 100
}
document.getElementById("variantBar" + tmpIndex).style.width = tmpWidth + "%"
document.getElementById("variantBar" + tmpIndex).style.backgroundColor = tmpStyle
break
}
})
}
resolve(this)
}
})
function waitForElm(selector) {
return new Promise((resolve) => {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector))
}
const observer = new MutationObserver((mutations) => {
if (document.querySelector(selector)) {
resolve(document.querySelector(selector))
observer.disconnect()
}
})
observer.observe(document.body, {
childList: true,
subtree: true
})
})
}
for (let i = 0; i < 16; i++) {
waitForElm("#actionBarItem" + i).then((parent) => {
const element = document.createElement("div")
element.id = "variantBar" + i
element.className = "weaponVariantBar"
parent.appendChild(element)
})
}
})()