Skip to content

Instantly share code, notes, and snippets.

@scott-maddox
Forked from thexa4/showbest.js
Last active July 8, 2017 13:51
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save scott-maddox/dadb6c74f3e5db98aad6bbaa71a05302 to your computer and use it in GitHub Desktop.
Save scott-maddox/dadb6c74f3e5db98aad6bbaa71a05302 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)
@scott-maddox
Copy link
Author

scott-maddox commented Aug 13, 2016

Cleaned up the code and fixed for latest version of Spaceplan

@scott-maddox
Copy link
Author

Fixed unaffordable items being ignored. Changed highlight color to yellow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment