Skip to content

Instantly share code, notes, and snippets.

@yuanotes
Created November 3, 2015 10:44
Show Gist options
  • Save yuanotes/fad19cd43e916596a3d6 to your computer and use it in GitHub Desktop.
Save yuanotes/fad19cd43e916596a3d6 to your computer and use it in GitHub Desktop.
A helper script for playing http://minmaxia.com/basic/
function hackElement(el){
var priceText = el.getElementsByTagName("tr")[0].getElementsByTagName("td")[1].innerText.replace(/[,$]/g, "");
var tickText = el.getElementsByTagName("tr")[1].getElementsByTagName("td")[1].innerText.replace(/,/g, "");
if (priceText === "" || tickText === "") {
return;
}
var price = parseInt(priceText);
var tick = parseInt(/(\d+)\/tick/.exec(tickText)[1]);
var value = price/tick;
var tbody = el.getElementsByTagName("tbody")[0];
var newTR;
var value;
var valueLB;
if (tbody.childNodes.length > 2){
newTR = el.getElementsByTagName("tr")[2];
value = newTR.getElementsByTagName("td")[1];
valueLB = newTR.getElementsByTagName("td")[0];
} else {
newTR = document.createElement("tr");
valueLB = document.createElement("td");
value = document.createElement("td");
newTR.appendChild(valueLB);
newTR.appendChild(value);
tbody.appendChild(newTR);
}
valueLB.innerText = "Value";
value.style.textAlign="right";
value.innerHTML = (price/tick).toFixed(2);
var container = el.getElementsByClassName("game-building-container")[0];
container.style.height = "55px";
}
function refresh(){
var all = document.getElementById("buildingContainer").childNodes;
for (var i = 0; i < all.length; i++){
var el = all[i];
hackElement(el);
}
}
document.onclick = function(e){
refresh();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment