1
0
Fork 0
mirror of https://github.com/Luzifer/automate-cookie-clicker.git synced 2024-12-22 18:21:18 +00:00

Follow ESLint suggestions

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2018-04-20 08:18:51 +02:00
parent 1ad612c413
commit db19e2bec3
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
2 changed files with 218 additions and 25 deletions

198
.eslintrc.json Normal file
View file

@ -0,0 +1,198 @@
{
"parserOptions": {
"ecmaVersion": 8,
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
"jsx": true
},
"sourceType": "module"
},
"env": {
"es6": true,
"node": false
},
"plugins": [
"import",
"node",
"promise",
"standard"
],
"globals": {
"document": false,
"navigator": false,
"window": false
},
"rules": {
"accessor-pairs": "error",
"arrow-spacing": ["error", { "before": true, "after": true }],
"block-spacing": ["error", "always"],
"brace-style": ["error", "1tbs", { "allowSingleLine": true }],
"camelcase": ["error", { "properties": "never" }],
"comma-dangle": ["error", "always-multiline"],
"comma-spacing": ["error", { "before": false, "after": true }],
"comma-style": ["error", "last"],
"constructor-super": "error",
"curly": ["error", "multi-line"],
"dot-location": ["error", "property"],
"eol-last": "error",
"eqeqeq": ["error", "always", { "null": "ignore" }],
"func-call-spacing": ["error", "never"],
"generator-star-spacing": ["error", { "before": true, "after": true }],
"handle-callback-err": ["error", "^(err|error)$" ],
"indent": ["error", 2, {
"SwitchCase": 1,
"VariableDeclarator": 1,
"outerIIFEBody": 1,
"MemberExpression": 1,
"FunctionDeclaration": { "parameters": 1, "body": 1 },
"FunctionExpression": { "parameters": 1, "body": 1 },
"CallExpression": { "arguments": 1 },
"ArrayExpression": 1,
"ObjectExpression": 1,
"ImportDeclaration": 1,
"flatTernaryExpressions": false,
"ignoreComments": false
}],
"key-spacing": ["error", { "beforeColon": false, "afterColon": true }],
"keyword-spacing": ["error", { "before": true, "after": true }],
"new-cap": ["error", { "newIsCap": true, "capIsNew": false }],
"new-parens": "error",
"no-array-constructor": "error",
"no-caller": "error",
"no-class-assign": "error",
"no-compare-neg-zero": "error",
"no-cond-assign": "error",
"no-const-assign": "error",
"no-constant-condition": ["error", { "checkLoops": false }],
"no-control-regex": "error",
"no-debugger": "error",
"no-delete-var": "error",
"no-dupe-args": "error",
"no-dupe-class-members": "error",
"no-dupe-keys": "error",
"no-duplicate-case": "error",
"no-empty-character-class": "error",
"no-empty-pattern": "error",
"no-eval": "error",
"no-ex-assign": "error",
"no-extend-native": "error",
"no-extra-bind": "error",
"no-extra-boolean-cast": "error",
"no-extra-parens": ["error", "functions"],
"no-fallthrough": "error",
"no-floating-decimal": "error",
"no-func-assign": "error",
"no-global-assign": "error",
"no-implied-eval": "error",
"no-inner-declarations": ["error", "functions"],
"no-invalid-regexp": "error",
"no-irregular-whitespace": "error",
"no-iterator": "error",
"no-label-var": "error",
"no-labels": ["error", { "allowLoop": false, "allowSwitch": false }],
"no-lone-blocks": "error",
"no-mixed-operators": ["error", {
"groups": [
["==", "!=", "===", "!==", ">", ">=", "<", "<="],
["&&", "||"],
["in", "instanceof"]
],
"allowSamePrecedence": true
}],
"no-mixed-spaces-and-tabs": "error",
"no-multi-spaces": "error",
"no-multi-str": "error",
"no-multiple-empty-lines": ["error", { "max": 1, "maxEOF": 0 }],
"no-negated-in-lhs": "error",
"no-new": "error",
"no-new-func": "error",
"no-new-object": "error",
"no-new-require": "error",
"no-new-symbol": "error",
"no-new-wrappers": "error",
"no-obj-calls": "error",
"no-octal": "error",
"no-octal-escape": "error",
"no-path-concat": "error",
"no-proto": "error",
"no-redeclare": "error",
"no-regex-spaces": "error",
"no-return-assign": ["error", "except-parens"],
"no-return-await": "error",
"no-self-assign": "error",
"no-self-compare": "error",
"no-sequences": "error",
"no-shadow-restricted-names": "error",
"no-sparse-arrays": "error",
"no-tabs": "error",
"no-template-curly-in-string": "error",
"no-this-before-super": "error",
"no-throw-literal": "error",
"no-trailing-spaces": "error",
"no-undef": "error",
"no-undef-init": "error",
"no-unexpected-multiline": "error",
"no-unmodified-loop-condition": "error",
"no-unneeded-ternary": ["error", { "defaultAssignment": false }],
"no-unreachable": "error",
"no-unsafe-finally": "error",
"no-unsafe-negation": "error",
"no-unused-expressions": ["error", { "allowShortCircuit": true, "allowTernary": true, "allowTaggedTemplates": true }],
"no-unused-vars": ["error", { "vars": "all", "args": "none", "ignoreRestSiblings": true }],
"no-use-before-define": ["error", { "functions": false, "classes": false, "variables": false }],
"no-useless-call": "error",
"no-useless-computed-key": "error",
"no-useless-constructor": "error",
"no-useless-escape": "error",
"no-useless-rename": "error",
"no-useless-return": "error",
"no-whitespace-before-property": "error",
"no-with": "error",
"object-property-newline": ["error", { "allowMultiplePropertiesPerLine": true }],
"one-var": ["error", { "initialized": "never" }],
"operator-linebreak": ["error", "after", { "overrides": { "?": "before", ":": "before" } }],
"padded-blocks": ["error", { "blocks": "never", "switches": "never", "classes": "never" }],
"prefer-promise-reject-errors": "error",
"quotes": ["error", "single", { "avoidEscape": true, "allowTemplateLiterals": true }],
"rest-spread-spacing": ["error", "never"],
"semi": ["error", "always"],
"semi-spacing": ["error", { "before": false, "after": true }],
"space-before-blocks": ["error", "always"],
"space-before-function-paren": ["error", "never"],
"space-in-parens": ["error", "never"],
"space-infix-ops": "error",
"space-unary-ops": ["error", { "words": true, "nonwords": false }],
"spaced-comment": ["error", "always", {
"line": { "markers": ["*package", "!", "/", ",", "="] },
"block": { "balanced": true, "markers": ["*package", "!", ",", ":", "::", "flow-include"], "exceptions": ["*"] }
}],
"symbol-description": "error",
"template-curly-spacing": ["error", "never"],
"template-tag-spacing": ["error", "never"],
"unicode-bom": ["error", "never"],
"use-isnan": "error",
"valid-typeof": ["error", { "requireStringLiterals": true }],
"wrap-iife": ["error", "any", { "functionPrototypeMethods": true }],
"yield-star-spacing": ["error", "both"],
"yoda": ["error", "never"],
"import/export": "error",
"import/first": "error",
"import/no-duplicates": "error",
"import/no-webpack-loader-syntax": "error",
"node/no-deprecated-api": "error",
"node/process-exit-as-throw": "error",
"promise/param-names": "error",
"standard/array-bracket-even-spacing": ["error", "either"],
"standard/computed-property-even-spacing": ["error", "even"],
"standard/no-callback-literal": "error",
"standard/object-curly-even-spacing": ["error", "either"]
}
}

View file

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name Automate CookieClicker // @name Automate CookieClicker
// @namespace https://luzifer.io/ // @namespace https://luzifer.io/
// @version 0.16.1 // @version 0.16.2
// @description Automate everything! // @description Automate everything!
// @author Knut Ahlers <knut@ahlers.me> // @author Knut Ahlers <knut@ahlers.me>
// @source https://github.com/Luzifer/automate-cookie-clicker // @source https://github.com/Luzifer/automate-cookie-clicker
@ -10,28 +10,29 @@
// @updateURL https://raw.githubusercontent.com/Luzifer/automate-cookie-clicker/master/autocookieclicker.user.js // @updateURL https://raw.githubusercontent.com/Luzifer/automate-cookie-clicker/master/autocookieclicker.user.js
// @icon http://orteil.dashnet.org/cookieclicker/img/favicon.ico // @icon http://orteil.dashnet.org/cookieclicker/img/favicon.ico
// @grant GM_info // @grant GM_info
// @grant GM_addStyle
// ==/UserScript== // ==/UserScript==
var blockingUpgrades = [ /* global Game:galse, GM_info:false, $:false */
let blockingUpgrades = [
69, // Destructive upgrade: "One mind" 69, // Destructive upgrade: "One mind"
85, // Revoke elders covenant 85, // Revoke elders covenant
331, // Golden switch 331, // Golden switch
333, // Milk selector 333, // Milk selector
414, // Background selector 414, // Background selector
]; ];
var dragonAuras = [ let dragonAuras = [
10, // Golden cookies may trigger a Dragonflight. 10, // Golden cookies may trigger a Dragonflight.
15, // All cookie production multiplied by 2. 15, // All cookie production multiplied by 2.
]; ];
var purchaseSteps = 50; let purchaseSteps = 50;
function autoClick() { function autoClick() {
$('#bigCookie').click(); $('#bigCookie').click();
} }
function executeAutoActions() { function executeAutoActions() {
if (Game.T % (Game.fps * 0.5) != 0) { if (Game.T % (Game.fps * 0.5) !== 0) {
// Game logic ticks very fast, only trigger every 0.5s // Game logic ticks very fast, only trigger every 0.5s
return; return;
} }
@ -47,17 +48,15 @@ function executeAutoActions() {
// Look for upgrades being available // Look for upgrades being available
let availableUpgrades = $('.upgrade.enabled').filter(upgradeFilter); let availableUpgrades = $('.upgrade.enabled').filter(upgradeFilter);
if (availableUpgrades.length > 0) { if (availableUpgrades.length > 0) {
debug(availableUpgrades.length + " upgrades available, buying now...");
availableUpgrades.click(); availableUpgrades.click();
note('Purchased ' + availableUpgrades.length + ' upgrades for you.'); note('Purchased ' + availableUpgrades.length + ' upgrades for you.');
} }
// Get the top enabled purchase to be made // Get the top enabled purchase to be made
let availableProducts = $('.product.unlocked.enabled').filter(productFilter); let availableProducts = $('.product.unlocked.enabled').filter(productFilter);
if (availableProducts.length > 0 && Game.buyMode == 1) { // buyMode 1 = buy, -1 = sell if (availableProducts.length > 0 && Game.buyMode === 1) { // buyMode 1 = buy, -1 = sell
let product = $(availableProducts[availableProducts.length - 1]); let product = $(availableProducts[availableProducts.length - 1]);
debug("Auto-Buying: " + product.find('.title:first').text());
product.click(); product.click();
note('Purchased ' + product.find('.title:first').text() + ' for you.'); note('Purchased ' + product.find('.title:first').text() + ' for you.');
} }
@ -68,21 +67,17 @@ function executeAutoActions() {
function controlAutoClicker() { function controlAutoClicker() {
let cps = Game.cookiesPs; let cps = Game.cookiesPs;
if (cps < 3000 || hasActiveClickBuff()) { if (cps < 3000 || hasActiveClickBuff()) {
if (window.autoClicker == undefined) { if (window.autoClicker === undefined) {
window.autoClicker = window.setInterval(autoClick, 100); window.autoClicker = window.setInterval(autoClick, 100);
} }
} else { } else {
if (window.autoClicker != undefined) { if (window.autoClicker !== undefined) {
window.clearInterval(window.autoClicker); window.clearInterval(window.autoClicker);
window.autoClicker = undefined; window.autoClicker = undefined;
} }
} }
} }
function debug(msg) {
console.log("[AutoCookieClicker] " + msg);
}
function getMaxBuy() { function getMaxBuy() {
let topPurchaseCount = Game.ObjectsById[Game.ObjectsN - 1].amount; let topPurchaseCount = Game.ObjectsById[Game.ObjectsN - 1].amount;
@ -90,8 +85,8 @@ function getMaxBuy() {
} }
function hasActiveClickBuff() { function hasActiveClickBuff() {
var hasBuff = false; let hasBuff = false;
for (var key in Game.buffs) { for (let key in Game.buffs) {
if (Game.buffs[key].multClick) hasBuff = true; if (Game.buffs[key].multClick) hasBuff = true;
} }
return hasBuff; return hasBuff;
@ -109,36 +104,36 @@ function installHelper() {
function manageDragon() { function manageDragon() {
// Upgrade dragon if possible // Upgrade dragon if possible
if (Game.dragonLevels[Game.dragonLevel].cost() && Game.dragonLevel < Game.dragonLevels.length - 1) { if (Game.dragonLevels[Game.dragonLevel].cost() && Game.dragonLevel < Game.dragonLevels.length - 1) {
Game.UpgradeDragon() Game.UpgradeDragon();
} }
// Select first dragon aura // Select first dragon aura
if (Game.dragonAura != dragonAuras[0] && Game.dragonLevel >= dragonAuras[0] + 4 && Game.SelectingDragonAura != dragonAura[0]) { if (Game.dragonAura !== dragonAuras[0] && Game.dragonLevel >= dragonAuras[0] + 4 && Game.SelectingDragonAura !== dragonAuras[0]) {
Game.SetDragonAura(dragonAuras[0], 0); Game.SetDragonAura(dragonAuras[0], 0);
} }
// Select second dragon aura // Select second dragon aura
if (Game.dragonAura2 != dragonAuras[1] && Game.dragonLevel >= 22 && Game.SelectingDragonAura != dragonAura[1]) { if (Game.dragonAura2 !== dragonAuras[1] && Game.dragonLevel >= 22 && Game.SelectingDragonAura !== dragonAuras[1]) {
Game.SetDragonAura(dragonAuras[1], 1); Game.SetDragonAura(dragonAuras[1], 1);
} }
} }
function note(msg, quick = true) { function note(msg, quick = true) {
// Icon: img/icons.png 0-based indices // Icon: img/icons.png 0-based indices
Game.Notify("Auto-CookieClicker", msg, [12, 0], quick, true); Game.Notify('Auto-CookieClicker', msg, [12, 0], quick, true);
} }
function productFilter(idx) { function productFilter() {
let owned = Game.ObjectsById[parseInt($(this).attr('id').replace(/^product/, ''))].amount; let owned = Game.ObjectsById[parseInt($(this).attr('id').replace(/^product/, ''))].amount;
return owned < getMaxBuy(); return owned < getMaxBuy();
} }
function upgradeFilter(idx) { function upgradeFilter() {
var onClickHandler = $(this).attr('onclick'); let onClickHandler = $(this).attr('onclick');
if (onClickHandler == null) { if (onClickHandler == null) {
return false; return false;
} }
var upgradeID = parseInt(onClickHandler.replace(/^.*\[([0-9]+)\].*$/, "$1")); let upgradeID = parseInt(onClickHandler.replace(/^.*\[([0-9]+)\].*$/, '$1'));
return !blockingUpgrades.includes(upgradeID); return !blockingUpgrades.includes(upgradeID);
} }