Skip to content

Instantly share code, notes, and snippets.

@LyndonArmitage
Created September 11, 2013 19:34
Show Gist options
  • Save LyndonArmitage/6528669 to your computer and use it in GitHub Desktop.
Save LyndonArmitage/6528669 to your computer and use it in GitHub Desktop.
CookieClicker Bot
/*
Cookie Clicker Bot by Lyndon Armitage.
Cookie Clicker itself is a game copyright of Orteil 2013.
You can play it here: http://orteil.dashnet.org/cookieclicker/
This is a very basic bot for Cookie Clicker.
It is written in such a way that it does not interact directly with the game itself but instead it relies on reading
the CSS/HTML IDs and classes of the GUI elements on the page.
*/
// Example loading of bot
//var scriptTag = document.createElement("script");scriptTag.src = "http://lyndonarmitage.com/html/cookie/CookieClickerBot.js";document.body.appendChild(scriptTag);
// or like this to ensure there isn't any caching:
// var scriptTag = document.createElement("script");scriptTag.src = "http://lyndonarmitage.com/html/cookie/CookieClickerBot.js?v="+(Math.random()*99999);document.body.appendChild(scriptTag);
var bot_running = false;
var intervalIDs = [];
function addjQueryAndBegin() {
// Using jQuery for helpful methods
// First check if it has already been loaded
if(typeof jQuery === "undefined") {
var scriptTag = document.createElement("script");
scriptTag.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js";
scriptTag.onload = function() {
// This will run once jQuery has been loaded
startBot();
};
document.body.appendChild(scriptTag);
}
else {
startBot();
}
}
function startBot() {
function purchasePossibleItems(topId, className) {
// in div products
var $products = $("#" + topId);
var divs = [];
$products.children("."+className+".enabled").each(function(index, domEl) {
divs.push(domEl);
});
// Click each div starting from best to worst out of those available
for(var i = divs.length - 1; i >= 0; i --) {
divs[i].click();
}
}
var clickerInterval = setInterval(function() {
$("#bigCookie").click();
}, 10);
var goldenCookieClickerInterval = setInterval(function() {
var $goldenCookie = $("#goldenCookie");
if($goldenCookie.css("display") !== "none") {
$goldenCookie.click();
// click the golden cookie
}
}, 100);
var purchaserInterval = setInterval(function() {
purchasePossibleItems("upgrades", "upgrade");
purchasePossibleItems("products", "product");
}, 1000);
bot_running = true;
intervalIDs = [clickerInterval, goldenCookieClickerInterval, purchaserInterval];
console.log("Bot Started");
$getToggle().text("Stop Bot");
}
function stopBot() {
if(!bot_running) return;
for(var i = 0; i < intervalIDs.length; i ++) {
clearInterval(intervalIDs[i]);
}
bot_running = false;
intervalIDs = [];
console.log("Bot Stopped");
$getToggle().text("Start Bot");
}
function $getToggle() {
// Add toggle button if it doesn't exist
var $toggle = $("#botToggle");
if($toggle.length === 0) {
$toggle = $("<a id='botToggle'>Toggle Bot</a>");
$toggle.on("click", function() {
if(bot_running) {
stopBot();
}
else {
startBot();
}
});
$toggle.on("mouseover", function() {
Game.tooltip.draw(this, encodeURI("<div style='min-width: 200px'>Bot toggle button for Lyndon's Bot</div>"), 0, 16, "bottom-right");
});
$toggle.on("mouseout", function() {
Game.tooltip.hide();
});
$toggle.css("cursor", "pointer");
$toggle.insertBefore("#topBar #links");
}
return $toggle;
}
addjQueryAndBegin();
@srk101734
Copy link

how

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