Skip to content

Instantly share code, notes, and snippets.

@tabatkins
Last active August 29, 2015 14:17
CookieBot
CookieBot = {
$bigCookie: null,
$products: null,
running: true,
init: function() {
CookieBot.$bigCookie = document.querySelector("#bigCookie");
CookieBot.$products = [].slice.call(document.querySelectorAll(".product"));
},
clickCookie: function() {
for(var i = 0; i < 5; i++)
CookieBot.$bigCookie.click();
if(CookieBot.running)
setTimeout(CookieBot.clickCookie, 0);
},
clickGolden: function() {
var golden = document.querySelector("#goldenCookie");
// Don't click angry grandmas' wrath cookies.
if (/wrath/.test(golden.style.background)) {
return;
}
golden.click();
// Click season popups, too.
Game.seasonPopup.click();
if(CookieBot.running)
setTimeout(CookieBot.clickGolden, 1000);
},
buyBuilding: function() {
var $unlocked = CookieBot.$products.filter(function(x) {return x.classList.contains("unlocked");});
var maxId, maxEfficiency=-1;
for(var i = 0; i < $unlocked.length; i++) {
var $b = $unlocked[i];
var ob = Game.ObjectsById[i];
if(ob.bought == 0 && $b.classList.contains("enabled")) {
// Pure eff calcs can be perverse when buying the first of a building.
// More efficient *timewise* to just buy one of everything.
maxId = i;
break;
}
var eff = ob.cps()/ob.price;
if(eff > maxEfficiency) {
maxId = i;
maxEfficiency = eff;
}
}
if(maxId === undefined) return;
if($unlocked[maxId].classList.contains("enabled")) {
$unlocked[maxId].click();
}
if(CookieBot.running)
setTimeout(CookieBot.buyBuilding, 100);
},
buyUpgrade: function() {
var upgrades = [].slice.call(document.querySelectorAll(".upgrade.enabled"));
for(var i = 0; i < upgrades.length; i++) {
if(upgrades[i].onclick == null) continue;
var id = /\d+/.exec(upgrades[i].onclick)[0];
if(id == 84 || id == 85) {
// Grandmatriarch switches, avoid auto-clicking
continue;
}
if(id == 182 || id == 183 || id == 184 || id == 185 || id == 209) {
// Season activators, avoid auto-clicking
continue;
}
if(id == 227) {
// Chocolate Egg should be saved til the end and manually clicked.
continue;
}
upgrades[i].click();
}
if(CookieBot.running)
setTimeout(CookieBot.buyUpgrade, 500);
},
start: function() {
CookieBot.running = true;
CookieBot.init();
CookieBot.clickCookie();
CookieBot.clickGolden();
CookieBot.buyBuilding();
CookieBot.buyUpgrade();
},
stop: function() {
CookieBot.running = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment