2018-02-11 22:43:56 +00:00
|
|
|
// ==UserScript==
|
2018-02-11 23:07:39 +00:00
|
|
|
// @name Automate CookieClicker
|
|
|
|
// @namespace https://luzifer.io/
|
2018-04-14 11:08:56 +00:00
|
|
|
// @version 0.7.3
|
2018-02-11 23:07:39 +00:00
|
|
|
// @description Automate everything!
|
|
|
|
// @author Knut Ahlers <knut@ahlers.me>
|
2018-04-11 21:01:30 +00:00
|
|
|
// @source https://github.com/Luzifer/automate-cookie-clicker
|
2018-02-11 23:07:39 +00:00
|
|
|
// @match http://orteil.dashnet.org/cookieclicker/
|
|
|
|
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js
|
|
|
|
// @require https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js
|
2018-04-11 21:06:03 +00:00
|
|
|
// @updateURL https://raw.githubusercontent.com/Luzifer/automate-cookie-clicker/master/autocookieclicker.user.js
|
2018-02-11 23:07:39 +00:00
|
|
|
// @grant GM_info
|
|
|
|
// @grant GM_addStyle
|
2018-02-11 22:43:56 +00:00
|
|
|
// ==/UserScript==
|
|
|
|
|
2018-02-11 23:07:39 +00:00
|
|
|
GM_addStyle('@import url("https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.min.css");');
|
|
|
|
|
2018-04-14 10:58:33 +00:00
|
|
|
var blockingUpgrades = [
|
|
|
|
333, // Milk selector
|
|
|
|
];
|
2018-04-11 20:41:32 +00:00
|
|
|
var purchaseSteps = 50;
|
|
|
|
|
2018-02-11 23:07:39 +00:00
|
|
|
function autoClick() {
|
|
|
|
$('#bigCookie').click();
|
|
|
|
}
|
2018-02-11 22:43:56 +00:00
|
|
|
|
|
|
|
function autoPurchaseUpgrades() {
|
2018-02-11 23:07:39 +00:00
|
|
|
// Look for upgrades being available
|
2018-04-14 10:56:05 +00:00
|
|
|
let availableUpgrades = $('.upgrade.enabled').filter(upgradeFilter);
|
2018-02-11 23:07:39 +00:00
|
|
|
if (availableUpgrades.length > 0) {
|
|
|
|
debug(availableUpgrades.length + " upgrades available, buying now...");
|
|
|
|
availableUpgrades.click();
|
|
|
|
toastr.info('Purchased ' + availableUpgrades.length + ' upgrades for you.');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the top enabled purchase to be made
|
2018-03-02 21:50:07 +00:00
|
|
|
if ($('.product.unlocked.enabled').length > 0) {
|
|
|
|
let topPurchase = $('.product.unlocked.enabled').last();
|
|
|
|
let topPurchaseCount = 0;
|
|
|
|
if (topPurchase.find('.owned').text() != "") {
|
|
|
|
topPurchaseCount = parseInt(topPurchase.find('.owned').text());
|
|
|
|
}
|
2018-04-11 20:23:26 +00:00
|
|
|
if (topPurchaseCount < getMaxBuy()) {
|
2018-03-02 21:50:07 +00:00
|
|
|
debug("Auto-Buying: " + topPurchase.find('.title:first').text());
|
|
|
|
topPurchase.click();
|
|
|
|
toastr.info('Purchased ' + topPurchase.find('.title:first').text() + ' for you.');
|
|
|
|
}
|
2018-02-11 23:07:39 +00:00
|
|
|
}
|
2018-02-11 22:43:56 +00:00
|
|
|
}
|
|
|
|
|
2018-02-12 19:22:54 +00:00
|
|
|
function checkCPS() {
|
|
|
|
let cps = parseInt($('#cookies').children('div').text().split(': ')[1]);
|
2018-02-12 19:27:32 +00:00
|
|
|
if (cps == 0) {
|
|
|
|
if (window.autoClicker == undefined) {
|
|
|
|
window.autoClicker = window.setInterval(autoClick, 1);
|
|
|
|
}
|
|
|
|
} else if (cps > 3000) {
|
2018-02-12 19:22:54 +00:00
|
|
|
if (window.autoClicker != undefined) {
|
|
|
|
window.clearInterval(window.autoClicker);
|
|
|
|
window.autoClicker = undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-11 22:43:56 +00:00
|
|
|
function debug(msg) {
|
2018-02-11 23:07:39 +00:00
|
|
|
console.log("[AutoCookieClicker] " + msg);
|
2018-02-11 22:43:56 +00:00
|
|
|
}
|
|
|
|
|
2018-04-11 20:23:26 +00:00
|
|
|
function getMaxBuy() {
|
|
|
|
var topPurchaseCount = 0;
|
|
|
|
var topPurchaseTextCount = $('#product14').find('.owned').text();
|
|
|
|
if (topPurchaseTextCount != "") {
|
|
|
|
topPurchaseCount = parseInt(topPurchaseTextCount);
|
|
|
|
}
|
|
|
|
|
2018-04-11 20:41:32 +00:00
|
|
|
return Math.max(Math.ceil((topPurchaseCount + 1) / purchaseSteps), 1) * purchaseSteps;
|
2018-04-11 20:23:26 +00:00
|
|
|
}
|
|
|
|
|
2018-02-11 22:43:56 +00:00
|
|
|
(function() {
|
2018-02-11 23:07:39 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// Set options for toastr
|
|
|
|
toastr.options = {
|
|
|
|
"closeButton": false,
|
|
|
|
"debug": false,
|
|
|
|
"newestOnTop": false,
|
|
|
|
"progressBar": false,
|
|
|
|
"positionClass": "toast-bottom-right",
|
|
|
|
"preventDuplicates": false,
|
|
|
|
"onclick": null,
|
|
|
|
"showDuration": "300",
|
|
|
|
"hideDuration": "1000",
|
|
|
|
"timeOut": "2000",
|
|
|
|
"extendedTimeOut": "1000",
|
|
|
|
"showEasing": "swing",
|
|
|
|
"hideEasing": "linear",
|
|
|
|
"showMethod": "fadeIn",
|
|
|
|
"hideMethod": "fadeOut"
|
|
|
|
};
|
|
|
|
|
2018-02-12 19:22:54 +00:00
|
|
|
window.checkCPS = window.setInterval(checkCPS, 1000);
|
2018-02-11 22:43:56 +00:00
|
|
|
|
2018-02-11 23:07:39 +00:00
|
|
|
// Enable automatic purchasing of upgrades / elements
|
2018-02-12 18:57:57 +00:00
|
|
|
window.autoPurchase = window.setInterval(autoPurchaseUpgrades, 500);
|
2018-02-11 22:43:56 +00:00
|
|
|
|
2018-02-11 23:07:39 +00:00
|
|
|
// Startup notification
|
|
|
|
let version = GM_info.script.version;
|
|
|
|
toastr.info('Auto-CookieClicker ' + version + ' loaded.');
|
|
|
|
})();
|
2018-04-14 10:56:05 +00:00
|
|
|
|
|
|
|
function upgradeFilter(idx) {
|
2018-04-14 11:07:28 +00:00
|
|
|
var onClickHandler = $(this).attr('onclick');
|
2018-04-14 11:08:56 +00:00
|
|
|
if (onClickHandler == null) {
|
2018-04-14 11:07:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-04-14 11:08:56 +00:00
|
|
|
var upgradeID = parseInt(onClickHandler.replace(/^.*\[([0-9]+)\].*$/, "$1"));
|
2018-04-14 10:56:05 +00:00
|
|
|
return !blockingUpgrades.includes(upgradeID);
|
|
|
|
}
|