LordPankake

CookieClicker Auto

Feb 20th, 2016 (edited)
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/                                                                          
  2. /*   _____            _    _       _____ _ _      _                         _         */
  3. /*  / ____|          | |  (_)     / ____| (_)    | |             /\        | |        */
  4. /* | |     ___   ___ | | ___  ___| |    | |_  ___| | _____ _ __ /  \  _   _| |_ ___   */
  5. /* | |    / _ \ / _ \| |/ / |/ _ \ |    | | |/ __| |/ / _ \ '__/ /\ \| | | | __/ _ \  */
  6. /* | |___| (_) | (_) |   <| |  __/ |____| | | (__|   <  __/ | / ____ \ |_| | || (_) | */
  7. /*  \_____\___/ \___/|_|\_\_|\___|\_____|_|_|\___|_|\_\___|_|/_/    \_\__,_|\__\___/  */
  8. /*                                                                                    */
  9. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
  10. /*
  11.  * Cookie Clicker Auto - Version 1.0 by LordPankake
  12.  */                                                            
  13. var setup = false;
  14. var upgrades_blackList = ["One Mind", "Revoke Elder Covenaunt"];
  15. var autoMap = [];
  16.  
  17. // TODO: Doesn't prevent user clicking bookmark multiple times (Duplicates the menu)
  18. if (!setup) {
  19.     // Setup data
  20.     init();
  21.    
  22.     // Create gui based on data
  23.     createGUI();
  24.     setup = true;
  25.    
  26.     // Start the main loop
  27.     requestAnimationFrame(mainLoop);
  28. }
  29.  
  30. /**
  31.  * Creates the automation tasks.
  32.  */
  33. function init() {
  34.     var auto_ClickCookie = new Automation(false, "Click Cookie", function() {
  35.         // The game has a sort of anti-autoclick but we can break it by changing the lastClick time.
  36.         Game.lastClick = Date.now() - 10000;
  37.        
  38.         // Send a click to the big cookie
  39.         var elemCookie = document.getElementById("bigCookie");
  40.         clickElement(elemCookie);
  41.     });
  42.     var auto_ClickGolden = new Automation(false, "Click Goldens", function() {
  43.         var goldenCookies = document.getElementsByClassName("shimmer");
  44.         var index;
  45.         for (index = goldenCookies.length - 1; index >= 0; --index) {
  46.             var goldenCookie = goldenCookies[index];
  47.             if (goldenCookie.style.backgroundImage.indexOf("wrath") > -1){
  48.                 // Wrath cookie
  49.             }
  50.             else if (goldenCookie.style.backgroundImage.indexOf("spooky") > -1){
  51.                 // Wrath (spooky) cookie
  52.             }
  53.             else {
  54.                 //Gold cookie
  55.                 clickElement(goldenCookie);
  56.             }
  57.         }
  58.     });
  59.     var auto_ClickSeasonal = new Automation(false, "Click Season Popups", function() {
  60.         var elemGolden = document.getElementById("seasonPopup");
  61.         if (checkExists(elemGolden)) {
  62.             clickElement(elemGolden);
  63.         }
  64.     });
  65.     var auto_PopWrinklers = new Automation(false, "Pop Wrinklers", function() {
  66.         var i = 0;
  67.         var len = Game.wrinklers.length;
  68.         for (i = 0; i < len; i++) {
  69.             var wrink = Game.wrinklers[i];
  70.             if (wrink.sucked > 100) { // we only pop if they eat so we get halloween drops
  71.                 wrink.hp = 0;
  72.             }
  73.         }
  74.     });
  75.     var auto_BuyBuildings = new Automation(false, "Buy Buildings", function() {
  76.         var index;
  77.         var elemBuilds = document.getElementsByClassName("product unlocked enabled");
  78.         for (index = elemBuilds.length - 1; index >= 0; --index) {
  79.             var elemBuild = elemBuilds[index];
  80.             clickElement(elemBuild);
  81.         }
  82.     });
  83.     var auto_BuyUpgrades = new Automation(false, "Buy Upgrades", function() {
  84.         var upgradePanel = document.getElementById("upgrades");
  85.         var index;
  86.         var upgradePanelChildren = upgradePanel.childNodes;
  87.         for (index = upgradePanelChildren.length - 1; index >= 0; --index) {
  88.             var elemUpgrade = upgradePanelChildren[index];
  89.             if (elemUpgrade.className.indexOf("enabled") > -1) {
  90.                 clickElement(elemUpgrade);
  91.             }
  92.         }
  93.     });
  94.     var auto_RespawnCookie = new Automation(false, "Respawn Golden", function() {
  95.         Game.shimmerTypes.golden.time += 1000;
  96.     });
  97.     autoMap.push(auto_ClickCookie);
  98.     autoMap.push(auto_ClickGolden);
  99.     autoMap.push(auto_ClickSeasonal);
  100.     autoMap.push(auto_PopWrinklers);
  101.     autoMap.push(auto_BuyBuildings);
  102.     autoMap.push(auto_BuyUpgrades);
  103.     autoMap.push(auto_RespawnCookie);
  104. }
  105.  
  106. /**
  107.  * Creates the GUI based on automation tasks created in the init method.
  108.  */
  109. function createGUI() {
  110.     // Misc variables
  111.     var colDisabled = "#4f3030";
  112.     var colEnabled = "#374f30";
  113.    
  114.     // Buttons
  115.     var btnArray = [];
  116.     var index;
  117.     for (index = 0; index < autoMap.length; index++) {
  118.         var btnAuto = document.createElement("DIV");
  119.         btnAuto.setAttribute('id', index);
  120.         btnAuto.onclick = function() {
  121.             var auto = autoMap[parseInt(this.getAttribute('id'))];
  122.             auto.active = !auto.active;
  123.             this.style.backgroundColor = auto.active ? colEnabled : colDisabled;
  124.             this.innerHTML = auto.titleText;
  125.         };
  126.         btnArray.push(btnAuto);
  127.     }
  128.    
  129.     // Style tweaking & appending
  130.     var elemMenu = document.createElement("DIV");
  131.     elemMenu.style.position = "relative";
  132.     elemMenu.style.zIndex = "99999";
  133.     elemMenu.style.backgroundColor = "#000";
  134.     elemMenu.style.padding = "5px";
  135.     elemMenu.style.margins = "2px 2px 2px 2px";
  136.     for (index = 0; index <  btnArray.length; index++) {
  137.         var elemButton = btnArray[index];
  138.         elemButton.innerHTML = autoMap[index].titleText;
  139.         elemButton.style.padding = "5px";
  140.         elemButton.style.border = "1px solid #FFF";
  141.         elemButton.style.backgroundColor = autoMap[index].active ? colEnabled : colDisabled;
  142.         elemButton.style.display = "inline-block";
  143.         elemMenu.appendChild(elemButton);
  144.     }
  145.     varTopBar = document.getElementById("topBar");
  146.     topBar.innerHTML = '';
  147.     topBar.appendChild(elemMenu);
  148. }
  149.  
  150. /**
  151.  * The main loop. Requires the window to be open.
  152.  */
  153. function mainLoop() {
  154.     var index;
  155.     for (index = 0; index <  autoMap.length; index++) {
  156.         var auto = autoMap[index];
  157.         // Skip if not active
  158.         if (!auto.active) {
  159.             continue;
  160.         }
  161.         // Run task
  162.         auto.autoTask();
  163.     }
  164.     requestAnimationFrame(mainLoop);
  165. }
  166.  
  167. /**
  168.  * Clicks a given element.
  169.  */
  170. function clickElement(elem) {
  171.     var clickEvent = new MouseEvent("click", {
  172.         "view": window,
  173.         "bubbles": true,
  174.         "cancelable": false
  175.     });
  176.     elem.dispatchEvent(clickEvent);
  177. }
  178.  
  179. /**
  180.  * Checks if a given item exists.
  181.  */
  182. function checkExists(item) {
  183.     return (typeof(item) != 'undefined' && item != null);
  184. }
  185.  
  186. /**
  187.  * Class (Or whatever. Javascript is fucking weird) containing data about the task.
  188.  */
  189. function Automation(param_active, param_titleText, param_autoTask) {
  190.     this.titleText = param_titleText;
  191.     this.autoTask = param_autoTask;
  192.     this.active = param_active;
  193. }
Add Comment
Please, Sign In to add comment