Skip to content

Instantly share code, notes, and snippets.

@SippieCup
Forked from scott-maddox/showbest.js
Created July 8, 2017 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SippieCup/57022bea9379b86fd4e9b67d36ece1cd to your computer and use it in GitHub Desktop.
Save SippieCup/57022bea9379b86fd4e9b67d36ece1cd to your computer and use it in GitHub Desktop.
For use with spaceplan
// Paste in console
var getThings = function(){
var divs = [...document.querySelectorAll("#manufacture__container > div")]
var things = divs.map(function(e){
var result = {e};
var spans = [...e.getElementsByTagName("span")]
spans.map(function(s){
var str = s.innerText.replace(/[^/.0-9]/g, '');
var a = str.split("/");
var num = +a[0];
var den = +a[1] || 1;
result[s.id] = (+num) / (+den)
})
if(e.id === "item__spudGun" || e.id === "item__potatoLauncher") result.powerGain *= 1000;
var cur_power = +document.querySelector("#watts--total").innerText.replace(/[^0-9]/g, '');
result.score = result.cost * (cur_power + result.powerGain)/result.powerGain;
result.name = e.getElementsByClassName("manufacture__name")[0].innerText;
return result
})
return things
}
var getFilteredThings = function(){
return getThings().filter(function(e){ return e.cost !== 0 })
}
//console.info(getThings())
//console.info(getFilteredThings())
//console.info(getFilteredThings().map(function(e){return e.score.toExponential()}))
var highlightBestThing = function(){
var things = getFilteredThings().sort(function(a,b){return a.score - b.score});
var bestThing = things[0];
console.info("highlighting " + bestThing.name);
for(var i = 0; i < things.length; i++) {
things[i].e.style.color="#fff";
}
things[0].e.style.color="#ff0";
}
//console.info(highlightBestThing())
var timer = setInterval(highlightBestThing, 500)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment