From 4de087373ac7e11c7a41264422818186a0cfcd29 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Wed, 11 Apr 2018 22:23:26 +0200 Subject: [PATCH] Use a dynamic maximum Signed-off-by: Knut Ahlers --- autocookieclicker.user.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/autocookieclicker.user.js b/autocookieclicker.user.js index c2b1f7e..9c716ad 100644 --- a/autocookieclicker.user.js +++ b/autocookieclicker.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name Automate CookieClicker // @namespace https://luzifer.io/ -// @version 0.5.2 +// @version 0.6.0 // @description Automate everything! // @author Knut Ahlers // @match http://orteil.dashnet.org/cookieclicker/ @@ -34,7 +34,7 @@ function autoPurchaseUpgrades() { if (topPurchase.find('.owned').text() != "") { topPurchaseCount = parseInt(topPurchase.find('.owned').text()); } - if (topPurchaseCount < 50) { + if (topPurchaseCount < getMaxBuy()) { debug("Auto-Buying: " + topPurchase.find('.title:first').text()); topPurchase.click(); toastr.info('Purchased ' + topPurchase.find('.title:first').text() + ' for you.'); @@ -60,6 +60,22 @@ function debug(msg) { console.log("[AutoCookieClicker] " + msg); } +function getMaxBuy() { + var topPurchaseCount = 0; + var topPurchaseTextCount = $('#product14').find('.owned').text(); + if (topPurchaseTextCount != "") { + topPurchaseCount = parseInt(topPurchaseTextCount); + } + + var max = Math.max(Math.ceil(topPurchaseCount / 50), 1) * 50; + if (topPurchaseCount == max) { + // Special case: Cap was already bought + max += 50; + } + + return max; +} + (function() { 'use strict';