Last active
August 14, 2023 03:22
-
-
Save m-byte918/c6fdd659bfa960f80156bf843ca952d3 to your computer and use it in GitHub Desktop.
Tampermonkey userscript to calculate and show "meta scores" for each combo on mk8dxbuilder.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name mk8dxbuilder meta scores | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description calculate and show meta scores for each combo | |
// @author chrod64 | |
// @match https://mk8dxbuilder.com/ | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=mk8dxbuilder.com | |
// @grant none | |
// ==/UserScript== | |
// From my gist: https://gist.github.com/m-byte918/98e47d96102eee4dd3b166ee684d68ca | |
(function() { | |
// Ordered from least -> most important | |
// See: https://strawpoll.com/polls/B2ZBEWz5zgJ/results | |
const stats = [ "traction", "invincibility", "handling", "weight", "acceleration", "speed", "miniturbo" ]; | |
// nth triangle number - https://math.stackexchange.com/questions/593318/factorial-but-with-addition | |
const n = stats.length; | |
const statWeightScalar = 1 / ((n**2 + n) / 2); | |
const statWeights = { }; | |
for (let i = 0; i < n; ++i) { | |
statWeights[stats[i]] = (i + 1) * statWeightScalar; | |
} | |
// Different weights for each speed/handling type, see: https://vikemk.com/posts/mk8dx-combos | |
// and https://docs.google.com/spreadsheets/d/1idLq3OYkEjRI0U64LCLxVY-GvdhRPgO75KZUPS4m70o/edit#gid=0 | |
statWeights.speed = { | |
ground: statWeights.speed * 0.737, | |
antigrav: statWeights.speed * 0.181, | |
air: statWeights.speed * 0.056, | |
water: statWeights.speed * 0.026, | |
}; | |
statWeights.handling = { | |
ground: statWeights.handling * 0.737, | |
antigrav: statWeights.handling * 0.181, | |
air: statWeights.handling * 0.056, | |
water: statWeights.handling * 0.026, | |
}; | |
function calcMetaScore(buildElem) { | |
const statsUnparsed = buildElem.getElementsByClassName("loading-container-def"); | |
const stats = []; // Stats is an array containing each stat in order (top-to-bottom) on mk8dxbuilder | |
for (let stat of statsUnparsed) { | |
stat = parseFloat(stat.lastElementChild.getAttribute("title").split(": ")[1]); | |
stats.push(stat); | |
} | |
const metaScore = stats[0] * statWeights.speed.ground + | |
stats[1] * statWeights.speed.water + | |
stats[2] * statWeights.speed.air + | |
stats[3] * statWeights.speed.antigrav + | |
stats[4] * statWeights.acceleration + | |
// Weight is no longer floored to the nearest whole number as of version 2.1.0. | |
// see https://media.discordapp.net/attachments/905144339385159783/1140484171165356093/gKbcfRh.png | |
stats[5] * statWeights.weight + | |
stats[6] * statWeights.handling.ground + | |
stats[7] * statWeights.handling.water + | |
stats[8] * statWeights.handling.air + | |
stats[9] * statWeights.handling.antigrav + | |
stats[10] * statWeights.traction + | |
stats[11] * statWeights.miniturbo + | |
stats[12] * statWeights.invincibility; | |
buildElem.lastElementChild.innerHTML = "Meta Score: " + metaScore.toFixed(3); | |
} | |
// Just calculate it on every click | |
document.querySelectorAll('*').forEach(element => element.addEventListener('click', e => { | |
const build1Div = document.getElementById("regionBuild1").lastElementChild; | |
const build2Div = document.getElementById("regionBuild2").lastElementChild; | |
const build3Div = document.getElementById("regionBuild3").lastElementChild; | |
if (build1Div.lastElementChild.nodeName !== "H4") { | |
build1Div.innerHTML += "<br><h4>Meta Score: 0</h4>"; | |
build2Div.innerHTML += "<br><h4>Meta Score: 0</h4>"; | |
build3Div.innerHTML += "<br><h4>Meta Score: 0</h4>"; | |
} else { | |
// Update | |
calcMetaScore(build1Div); | |
calcMetaScore(build2Div); | |
calcMetaScore(build3Div); | |
} | |
})); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment