Instantly share code, notes, and snippets.
Last active
December 22, 2015 01: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 pBun/6394697 to your computer and use it in GitHub Desktop.
Cookie Clicker (http://orteil.dashnet.org/cookieclicker/) cheat bookmarklet
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
| javascript:(function(){function n(t,n){if(!e.buttons[t]){return}e.buttons[t].interval=setInterval(n,e.intervalDelay)}function r(t){clearInterval(e.buttons[t].interval)}function s(t,i){if(!e.buttons[t].on){n(t,i);e.buttons[t].on=true;e.buttons[t].element.className="active"}else{r(t);e.buttons[t].on=false;e.buttons[t].element.className=""}}function o(){if(document.getElementById(e.panelId)){document.getElementById(e.panelId).remove()}e.panel=document.createElement("div");e.panel.id=e.panelId;document.body.appendChild(e.panel)}function u(t,n,r){if(!e.buttons[t]){return}e.buttons[t].element=document.createElement("button");e.buttons[t].element[typeof document.body.style.WebkitAppearance=="string"?"innerText":"innerHTML"]=n;e.buttons[t].element.addEventListener("click",r);e.panel.appendChild(e.buttons[t].element)}function a(){var t=e.panelId+"-styles";var n=document.getElementsByClassName(t);if(n.length<=0){n=document.createElement("style");n.type="text/css";n.className+=" "+t;document.body.appendChild(n)}var r="#"+e.panelId+"{position:fixed;top:0;right:0;background:#fff;color:#000;padding:5px;z-index:9999;}#"+e.panelId+" button{margin-left: 5px;}#"+e.panelId+' button.active:after{content:"*";color:red;}';n[typeof document.body.style.WebkitAppearance=="string"?"innerText":"innerHTML"]=r}var e={panelId:"cookie-cheater",intervalDelay:1,buttons:{bigCookie:{label:"Auto-click cookie",action:function(){s("bigCookie",function(){Game.ClickCookie()})}},autoGoldenCookie:{label:"Auto-click golden cookie",action:function(){s("autoGoldenCookie",function(){Game.goldenCookie.click()})}},spawnGoldenCookie:{label:"Spawn golden cookie",action:function(){Game.goldenCookie.spawn()}},autoSpawnGoldenCookie:{label:"Auto-spawn golden cookie",action:function(){s("autoSpawnGoldenCookie",function(){e.buttons["spawnGoldenCookie"].action()})}},buyProducts:{label:"Buy products",action:function(){var e=document.getElementsByClassName("product");for(i=0;i<e.length;i++){e[i].click()}}},autoBuyProducts:{label:"Auto-buy products",action:function(){s("autoBuyProducts",function(){e.buttons["buyProducts"].action()})}},buyUpgrades:{label:"Buy upgrades",action:function(){if(Game.UpgradesInStore.length>0){Game.UpgradesInStore[0].buy()}}},autoBuyUpgrades:{label:"Auto-buy upgrades",action:function(){s("autoBuyUpgrades",function(){e.buttons["buyUpgrades"].action()})}},showGoldenCookieDelay:{label:"Show golden cookie delay in title",action:function(){s("showGoldenCookieDelay",function(){document.title="("+Math.floor(Game.goldenCookie.delay/Game.fps)+" s) "+Beautify(Game.cookies)+" "+(Game.cookies==1?"cookie":"cookies")})}},optimalWin:{label:"Auto-win",action:function(){s("optimalWin",function(){Game.ClickCookie();Game.goldenCookie.spawn();Game.goldenCookie.click();var e=Game.Objects.Cursor;var t=Game.ObjectsById[Game.ObjectsById.length-1];var n;if(e.amount<10){e.buy();return}n=Game.UpgradesById[0];if(!n.bought&&n.unlocked){n.buy();return}n=Game.UpgradesById[1];if(!n.bought&&n.unlocked){n.buy();return}n=Game.UpgradesById[2];if(!n.bought&&n.unlocked){n.buy();return}n=Game.UpgradesById[75];if(!n.bought&&n.unlocked){n.buy();return}n=Game.UpgradesById[76];if(!n.bought&&n.unlocked){n.buy();return}if(Game.UpgradesInStore.length>0&&Game.UpgradesInStore[0].basePrice<t.price/4){Game.UpgradesInStore[0].buy()}t.buy()})}}}};a();o();for(var t in e.buttons){if(!e.buttons[t]){return}u(t,e.buttons[t].label,e.buttons[t].action)}})() |
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
| javascript:(function() { | |
| var options = { | |
| panelId: 'cookie-cheater', | |
| intervalDelay: 1, | |
| buttons: { | |
| 'bigCookie': { | |
| label: 'Auto-click cookie', | |
| action: function(){ | |
| toggleAutoAction('bigCookie', function(){ | |
| Game.ClickCookie(); | |
| }) | |
| } | |
| }, | |
| 'autoGoldenCookie': { | |
| label: 'Auto-click golden cookie', | |
| action: function(){ | |
| toggleAutoAction('autoGoldenCookie', function(){ | |
| Game.goldenCookie.click(); | |
| }) | |
| } | |
| }, | |
| 'spawnGoldenCookie': { | |
| label: 'Spawn golden cookie', | |
| action: function(){ | |
| Game.goldenCookie.spawn(); | |
| } | |
| }, | |
| 'autoSpawnGoldenCookie': { | |
| label: 'Auto-spawn golden cookie', | |
| action: function(){ | |
| toggleAutoAction('autoSpawnGoldenCookie', function(){ | |
| options.buttons['spawnGoldenCookie'].action(); | |
| }) | |
| } | |
| }, | |
| 'buyProducts': { | |
| label: 'Buy products', | |
| action: function(){ | |
| var products = document.getElementsByClassName('product'); | |
| for(i=0;i<products.length;i++){ | |
| products[i].click(); | |
| } | |
| } | |
| }, | |
| 'autoBuyProducts': { | |
| label: 'Auto-buy products', | |
| action: function(){ | |
| toggleAutoAction('autoBuyProducts', function(){ | |
| options.buttons['buyProducts'].action(); | |
| }) | |
| } | |
| }, | |
| 'buyUpgrades': { | |
| label: 'Buy upgrades', | |
| action: function(){ | |
| if (Game.UpgradesInStore.length > 0){ | |
| Game.UpgradesInStore[0].buy(); | |
| } | |
| } | |
| }, | |
| 'autoBuyUpgrades': { | |
| label: 'Auto-buy upgrades', | |
| action: function(){ | |
| toggleAutoAction('autoBuyUpgrades', function(){ | |
| options.buttons['buyUpgrades'].action(); | |
| }) | |
| } | |
| }, | |
| 'showGoldenCookieDelay': { | |
| label: 'Show golden cookie delay in title', | |
| action: function(){ | |
| toggleAutoAction('showGoldenCookieDelay', function(){ | |
| document.title='(' + Math.floor(Game.goldenCookie.delay / Game.fps) + ' s) '+Beautify(Game.cookies)+' '+(Game.cookies==1?'cookie':'cookies'); | |
| }) | |
| } | |
| }, | |
| 'optimalWin': { | |
| label: 'Auto-win', | |
| action: function(){ | |
| toggleAutoAction('optimalWin', function(){ | |
| /* auto-click big cookie and spawn/auto-click golden cookie */ | |
| Game.ClickCookie(); | |
| Game.goldenCookie.spawn(); | |
| Game.goldenCookie.click(); | |
| /* vars */ | |
| var cursorProduct = Game.Objects.Cursor; | |
| var timeMachine = Game.ObjectsById[Game.ObjectsById.length-1]; | |
| var cursUpgrade; | |
| /* buy 10 cursors */ | |
| if (cursorProduct.amount < 10){ | |
| cursorProduct.buy(); | |
| return; | |
| } | |
| /* buy a bunch of cursor upgrades */ | |
| cursUpgrade = Game.UpgradesById[0]; | |
| if (!cursUpgrade.bought && cursUpgrade.unlocked){ | |
| cursUpgrade.buy(); | |
| return; | |
| } | |
| cursUpgrade = Game.UpgradesById[1]; | |
| if (!cursUpgrade.bought && cursUpgrade.unlocked){ | |
| cursUpgrade.buy(); | |
| return; | |
| } | |
| cursUpgrade = Game.UpgradesById[2]; | |
| if (!cursUpgrade.bought && cursUpgrade.unlocked){ | |
| cursUpgrade.buy(); | |
| return; | |
| } | |
| cursUpgrade = Game.UpgradesById[75]; | |
| if (!cursUpgrade.bought && cursUpgrade.unlocked){ | |
| cursUpgrade.buy(); | |
| return; | |
| } | |
| cursUpgrade = Game.UpgradesById[76]; | |
| if (!cursUpgrade.bought && cursUpgrade.unlocked){ | |
| cursUpgrade.buy(); | |
| return; | |
| } | |
| /* buy upgrades if they are available in store and < 1/4 time machine price */ | |
| if (Game.UpgradesInStore.length > 0 && Game.UpgradesInStore[0].basePrice < timeMachine.price / 4){ | |
| Game.UpgradesInStore[0].buy(); | |
| } | |
| /* prioritize time machines over everything */ | |
| timeMachine.buy(); | |
| }) | |
| } | |
| }, | |
| } | |
| }; | |
| addStyleSheet(); | |
| addPanel(); | |
| for(var name in options.buttons){ | |
| if (!options.buttons[name]) { | |
| return; | |
| } | |
| addButton(name, options.buttons[name].label, options.buttons[name].action); | |
| } | |
| function autoAction(name, action){ | |
| if (!options.buttons[name]){ | |
| return; | |
| } | |
| options.buttons[name].interval = setInterval(action, options.intervalDelay); | |
| } | |
| function stopAutoAction(name){ | |
| clearInterval(options.buttons[name].interval); | |
| } | |
| function toggleAutoAction(name, action){ | |
| if(!options.buttons[name].on){ | |
| autoAction(name, action); | |
| options.buttons[name].on = true; | |
| options.buttons[name].element.className = 'active'; | |
| } else { | |
| stopAutoAction(name); | |
| options.buttons[name].on = false; | |
| options.buttons[name].element.className = ''; | |
| } | |
| } | |
| function addPanel(){ | |
| if (document.getElementById(options.panelId)){ | |
| document.getElementById(options.panelId).remove(); | |
| } | |
| options.panel = document.createElement("div"); | |
| options.panel.id = options.panelId; | |
| document.body.appendChild(options.panel); | |
| } | |
| function addButton(name, label, action){ | |
| if (!options.buttons[name]){ | |
| return; | |
| } | |
| options.buttons[name].element = document.createElement('button'); | |
| options.buttons[name].element[(typeof document.body.style.WebkitAppearance=="string")?"innerText":"innerHTML"] = label; | |
| options.buttons[name].element.addEventListener('click', action); | |
| options.panel.appendChild(options.buttons[name].element); | |
| } | |
| function addStyleSheet(){ | |
| var stylesClassName = options.panelId + '-styles'; | |
| var styles = document.getElementsByClassName(stylesClassName); | |
| if (styles.length <= 0){ | |
| styles = document.createElement('style'); | |
| styles.type = 'text/css'; | |
| styles.className += ' ' + stylesClassName; | |
| document.body.appendChild(styles); | |
| } | |
| var css = '#'+options.panelId+'{position:fixed;top:0;right:0;background:#fff;color:#000;padding:5px;z-index:9999;}#'+options.panelId+' button{margin-left: 5px;}#'+options.panelId+' button.active:after{content:"*";color:red;}'; | |
| styles[(typeof document.body.style.WebkitAppearance=="string")?"innerText":"innerHTML"] = css; | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment