Instantly share code, notes, and snippets.
Last active
February 9, 2016 21:09
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save enolan/dc8aabdc0c19583d443d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// rev 6 (updated for cookieclicker 2) | |
// use as bookmarket: | |
javascript:var Util = { maxBy: function (arr, gt) { 'use strict'; return arr.reduce(function (p, c) { if (gt(p, c)) { return p; } else { return c; } }); }, buildingValue: function (b) { 'use strict'; /* I don't think Orteil has any idea how JavaScript is supposed to work*/ return b.cps(b)*Game.globalCpsMult/b.price; }};function Automaton() { 'use strict'; this.plannedBuy = false; this.rafId = 0; this.controlPanel = {};}Automaton.prototype.update = function () { 'use strict'; var buybuildings = document.getElementById("buybuildingscheckbox").checked; var buyupgrades = document.getElementById("buyupgradescheckbox").checked; var click = document.getElementById("clickcheckbox").checked; var goldenClick = document.getElementById("goldencheckbox").checked; if (click) {document.getElementById("bigCookie").click();} var poppableWrinklers = Game.wrinklers.filter(x=>x.sucked>0 && x.hp > 0); for (let x of poppableWrinklers) { x.hp = 0; } let buildings = Game.ObjectsById.filter (function (x) {return x.locked === 0;}); if (!this.plannedBuy) { for (let x of buildings) { x.l.children[2].children[2].style.color = ""; } /* Plan our next building purchase*/ let purchasableSoon = buildings.filter(function (x) { return x.price <= Game.cookies + Game.cookiesPs * 120; }); if (purchasableSoon.length !== 0) { let bestValue = Util.maxBy(purchasableSoon, function (x,y) { return Util.buildingValue(x) > Util.buildingValue(y); }); bestValue.l.children[2].children[2].style.color="yellow"; this.plannedBuy = bestValue; } } if (buybuildings) { if (Game.cookies >= this.plannedBuy.price) { this.plannedBuy.buy(1); this.plannedBuy = false; } } else { this.plannedBuy = false; } if (goldenClick) { if (Game.goldenCookie.life > 0) { Game.goldenCookie.click(); console.log("golden cookie!"); } if (Game.seasonPopup.life > 0 && Game.seasonPopup.type === "reindeer") { Game.seasonPopup.click(); console.log("reindeer!"); } } if (buyupgrades) { let upgrade = Game.UpgradesById.filter(function (x) { return !x.hide && x.unlocked && !x.bought && !(x.pool=="toggle"); }).sort(function (a, b) { return a.getPrice() - b.getPrice(); })[0]; if (typeof upgrade !== "undefined" && upgrade.getPrice() <= Game.cookies) { upgrade.buy(true); this.plannedBuy = false; } } this.rafId = requestAnimationFrame(this.update.bind(this));};Automaton.prototype.start = function () { 'use strict'; this.controlPanel = document.createElement("div"); this.controlPanel.innerHTML = "hi"; this.controlPanel.style.position = "fixed"; this.controlPanel.style.left = "100px"; this.controlPanel.style.top = "600px"; this.controlPanel.style.zIndex = 1000; this.controlPanel.style.border ="1px solid white"; this.controlPanel.style.background = "black"; this.controlPanel.style.padding = "5px"; this.controlPanel.innerHTML = "<label>Buy buildings: <input type='checkbox' id='buybuildingscheckbox'/></label> <label>Buy upgrades: <input type='checkbox' id='buyupgradescheckbox'/></label> <label>Click: <input type='checkbox' id='clickcheckbox'/></label><label>Golden/etc: <input type='checkbox' id='goldencheckbox'/></label><button>reset</button>"; this.controlPanel.children[4].onclick = this.destroy.bind(this); document.body.appendChild(this.controlPanel); this.update();};Automaton.prototype.destroy = function () { 'use strict'; document.body.removeChild(this.controlPanel); this.controlPanel = {}; cancelAnimationFrame(this.rafId); Util = {}; Automaton = {};};var a = new Automaton();a.start();// tr -d '\n'< cookieclicker.js | |
// unmangled source: | |
var Util = { | |
maxBy: function (arr, gt) { | |
'use strict'; | |
return arr.reduce(function (p, c) { | |
if (gt(p, c)) { | |
return p; | |
} else { | |
return c; | |
} | |
}); | |
}, | |
buildingValue: function (b) { | |
'use strict'; | |
/* I don't think Orteil has any idea how JavaScript is supposed to work*/ | |
return b.cps(b)*Game.globalCpsMult/b.price; | |
} | |
}; | |
function Automaton() { | |
'use strict'; | |
this.plannedBuy = false; | |
this.rafId = 0; | |
this.controlPanel = {}; | |
} | |
Automaton.prototype.update = function () { | |
'use strict'; | |
var buybuildings = document.getElementById("buybuildingscheckbox").checked; | |
var buyupgrades = document.getElementById("buyupgradescheckbox").checked; | |
var click = document.getElementById("clickcheckbox").checked; | |
var goldenClick = document.getElementById("goldencheckbox").checked; | |
if (click) {document.getElementById("bigCookie").click();} | |
var poppableWrinklers = Game.wrinklers.filter(x=>x.sucked>0 && x.hp > 0); | |
for (let x of poppableWrinklers) { | |
x.hp = 0; | |
} | |
let buildings = Game.ObjectsById.filter | |
(function (x) {return x.locked === 0;}); | |
if (!this.plannedBuy) { | |
for (let x of buildings) { | |
x.l.children[2].children[2].style.color = ""; | |
} | |
/* Plan our next building purchase*/ | |
let purchasableSoon = buildings.filter(function (x) { | |
return x.price <= Game.cookies + Game.cookiesPs * 120; | |
}); | |
if (purchasableSoon.length !== 0) { | |
let bestValue = Util.maxBy(purchasableSoon, function (x,y) { | |
return Util.buildingValue(x) > Util.buildingValue(y); | |
}); | |
bestValue.l.children[2].children[2].style.color="yellow"; | |
this.plannedBuy = bestValue; | |
} | |
} | |
if (buybuildings) { | |
if (Game.cookies >= this.plannedBuy.price) { | |
this.plannedBuy.buy(1); | |
this.plannedBuy = false; | |
} | |
} else { | |
this.plannedBuy = false; | |
} | |
if (goldenClick) { | |
if (Game.goldenCookie.life > 0) { | |
Game.goldenCookie.click(); | |
console.log("golden cookie!"); | |
} | |
if (Game.seasonPopup.life > 0 && Game.seasonPopup.type === "reindeer") { | |
Game.seasonPopup.click(); | |
console.log("reindeer!"); | |
} | |
} | |
if (buyupgrades) { | |
let upgrade = Game.UpgradesById.filter(function (x) { | |
return !x.hide && x.unlocked && !x.bought && !(x.pool=="toggle"); | |
}).sort(function (a, b) { | |
return a.getPrice() - b.getPrice(); | |
})[0]; | |
if (typeof upgrade !== "undefined" && upgrade.getPrice() <= Game.cookies) { | |
upgrade.buy(true); | |
this.plannedBuy = false; | |
} | |
} | |
this.rafId = requestAnimationFrame(this.update.bind(this)); | |
}; | |
Automaton.prototype.start = function () { | |
'use strict'; | |
this.controlPanel = document.createElement("div"); | |
this.controlPanel.innerHTML = "hi"; | |
this.controlPanel.style.position = "fixed"; | |
this.controlPanel.style.left = "100px"; | |
this.controlPanel.style.top = "600px"; | |
this.controlPanel.style.zIndex = 1000; | |
this.controlPanel.style.border ="1px solid white"; | |
this.controlPanel.style.background = "black"; | |
this.controlPanel.style.padding = "5px"; | |
this.controlPanel.innerHTML = "<label>Buy buildings: <input type='checkbox' id='buybuildingscheckbox'/></label> <label>Buy upgrades: <input type='checkbox' id='buyupgradescheckbox'/></label> <label>Click: <input type='checkbox' id='clickcheckbox'/></label><label>Golden/etc: <input type='checkbox' id='goldencheckbox'/></label><button>reset</button>"; | |
this.controlPanel.children[4].onclick = this.destroy.bind(this); | |
document.body.appendChild(this.controlPanel); | |
this.update(); | |
}; | |
Automaton.prototype.destroy = function () { | |
'use strict'; | |
document.body.removeChild(this.controlPanel); | |
this.controlPanel = {}; | |
cancelAnimationFrame(this.rafId); | |
Util = {}; | |
Automaton = {}; | |
}; | |
var a = new Automaton(); | |
a.start(); | |
// tr -d '\n'< cookieclicker.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment