Skip to content

Instantly share code, notes, and snippets.

@teppeis
Created September 16, 2013 04:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teppeis/6576829 to your computer and use it in GitHub Desktop.
Save teppeis/6576829 to your computer and use it in GitHub Desktop.
// Auto clicking and optimal shopping for Cookie Clicker.
// http://orteil.dashnet.org/cookieclicker/
//
// Input this into developer console of your browser!
// You can stop with "stop()" in console.
var stop = (function(){
var def = [0.5, 0.5, 2, 10, 40, 100, 400, 6666, 98765, 999999];
function toNum(str) {
return Number(str.replace(/,/g, ''));
}
function getCPS(num) {
var el = document.getElementById('rowInfoContent' + num);
if (!el) return def[num];
var match = /• ([\d,]+)[\s\S]*producing ([\d,.]+)/.exec(el.innerText);
if (match[1] === '0') {
return def[num];
}
return toNum(match[2]) / toNum(match[1]);
}
function getCost(num) {
var a = document.querySelector('#product' + num + ' .price').innerText;
return toNum(a) / getCPS(num);
}
function getMinCostIdx() {
var minIdx = 0;
var ar = [0,1,2,3,4,5,6,7,8,9].map(getCost);
console.log(ar.map(function(item) {return Math.round(item).toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,")}));
ar.reduce(function(min, cur, idx) {
if (min > cur) {
minIdx = idx; return cur;
}
return min;
});
return minIdx;
}
function buyMinCostProduct() {
document.getElementById('product' + getMinCostIdx()).click();
}
function buyUpgrade(num) {
var el = document.querySelectorAll('#upgrades .upgrade')[num];
el && el.click();
}
function clickGoldenCookie() {
var el = document.getElementById('goldenCookie');
el && el.click();
}
var buyTimer = setInterval(function() {
clickGoldenCookie();
buyUpgrade(0);
buyMinCostProduct();
}, 500);
var bigCookie = document.getElementById('bigCookie');
var clickTimer = setInterval(function() {bigCookie.click();}, 0);
return function() {
clearInterval(buyTimer);
clearInterval(clickTimer);
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment