Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
// ==UserScript==
// @name Kittens Game Auto Clicker
// @namespace http://meslon.jp/
// @version 1.8
// @description auto craft :)
// @author Meslon
// @match http://www.bloodrizer.ru/games/kittens/*
// @grant none
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js
// @require http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js
// ==/UserScript==
(function() {
// for jQueryUI
$("head").append (
'<link'
+ ' href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css"'
+ ' rel="stylesheet" type="text/css">'
);
// create a dialog's html
var buildings = [
"Catnip field", "Pasture",
"Aqueduct", "Hut",
"Log House", "Mansion",
"Library", "Academy",
"Observatory", "Bio Lab",
"Barn", "Warehouse",
"Harbour", "Mine",
"Quarry", "Lumber Mill",
"Oil Well", "Accelerator",
"Steamworks", "Magneto",
"Smelter", "Calciner",
"Factory", "Reactor",
"Amphitheatre", "Chapel",
"Temple", "Workshop",
"Tradepost", "Mint",
"Unic", "Ziggurat",
"Solar Farm", "Hydro Plant",
"Broadcast Tower", "Chronosphere"
];
var dialogHtml = '<div id="dialogSelectBuild" title="select build">';
for (var i = 0; i < buildings.length; i++) {
var id = 'autoBuild' + (buildings[i]).replace(/\s+/g, "");
dialogHtml += '<input id="' + id + '" type="checkbox" /><label for="' + id + '">' + buildings[i] + '</label>,';
if (i % 2 == 1) {
dialogHtml += '<br>';
}
}
dialogHtml += '</div>';
var resources = [
["catnip", "wood"],
["wood", "beam"],
["minerals", "slab"],
["coal", "steel"],
["iron", "plate"],
["titanium", "alloy"],
["culture", "manuscript"],
["science", "blueprint"],
["science", "compedium"],
["oil", "kerosene"],
["uranium", "thorium"],
["unobtainium", "eludium"]
];
dialogHtml += '<div id="dialogSelectCraft" title="select craft">';
for (i = 0; i < resources.length; i++) {
var id = 'autoCraft' + resources[i][1];
dialogHtml += '<input id="'+ id +'" type="checkbox" /><label for="'+ id +'">'+ resources[i][0] +'&gt;'+ resources[i][1] +'</label><br>';
}
dialogHtml += '</div>';
var trades = [
["wood", "lizards", "minerals", 1000],
["catnip", "sharks", "iron", 100],
["iron", "griffins", "wood", 500],
["minerals", "nagas", "ivory", 500],
["titanium", "zebras", "slab", 50],
["coal", "spiders", "scaffold", 50],
["uranium", "dragons", "titanium", 250],
["time crystal", "leviathans", "unobtainium", 5000]
];
dialogHtml += '<div id="dialogSelectTrade" title="select trade">';
for (i = 0; i < trades.length; i++) {
var id = 'autoTrade' + trades[i][1];
dialogHtml += '<input id="'+ id +'" type="checkbox" /><label for="'+ id +'">'+ trades[i][2] +'&gt;'+ trades[i][0] +'</label><br>';
}
dialogHtml += '</div>';
var spaces = [
"Space Elevator", "Satellite",
"Space Station", "Lunar Outpost",
"Moon base", "Planet Cracker",
"Hydraulic Fracturer", "Research Vessel",
"Orbital Array", "Sunlifter",
"Cont. Chamber", "Cryostation",
"Space Beacon", "Terraforming Station",
"Hydroponics", "Tectonic"
];
dialogHtml += '<div id="dialogSelectSpace" title="select space">';
for (i = 0; i < spaces.length; i++) {
var id = 'autoSpace' + (spaces[i]).replace(/\s+/g, "");
dialogHtml += '<input id="' + id + '" type="checkbox" /><label for="' + id + '">' + spaces[i] + '</label>,';
dialogHtml += '<br>';
}
dialogHtml += '</div>';
// UI
// $("#topBar div#devPanel").html(
$("#rightColumn div.right-tab-header").append(
'<div style="font-size: small;">'
+ '<span style="display: inline-block;"><input id="autoBuild" type="checkbox" /><label for="autoBuild">:</label><a href="#" id="openSelectBuild" title="Build">Build</a>,</span>'
+ ' <span style="display: inline-block;"><input id="autoCraft" type="checkbox" /><label for="autoCraft">:</label><a href="#" id="openSelectCraft" title="Craft">Craft</a>,</span>'
+ ' <span style="display: inline-block;"><input id="autoHunt" type="checkbox" checked="checked" /><label for="autoHunt" title="Hunt">Hunt</label>,</span>'
+ ' <span style="display: inline-block;"><input id="autoPray" type="checkbox" checked="checked" /><label for="autoPray" title="Pray">Pray</label>,</span>'
+ ' <span style="display: inline-block;"><input id="autoObserve" type="checkbox" /><label for="autoObserve" title="Observe">Observe</label>,</span>'
+ ' <span style="display: inline-block;"><input id="autoTrade" type="checkbox" /><label for="autoTrade">:</label><a href="#" id="openSelectTrade" title="Trade">Trade</a></span>'
+ ' <span style="display: inline-block;"><input id="autoSpace" type="checkbox" /><label for="autoSpace">:</label><a href="#" id="openSelectSpace" title="Space">Space</a></span>'
+ '<div>'
+ dialogHtml
);
$("#dialogSelectBuild").dialog({autoOpen: false});
$("#openSelectBuild").click(function() {
$("#dialogSelectBuild").dialog("open");
return false;
});
$("#dialogSelectCraft").dialog({autoOpen: false});
$("#openSelectCraft").click(function() {
$("#dialogSelectCraft").dialog("open");
return false;
});
$("#dialogSelectTrade").dialog({autoOpen: false});
$("#openSelectTrade").click(function() {
$("#dialogSelectTrade").dialog("open");
return false;
});
$("#dialogSelectSpace").dialog({autoOpen: false});
$("#openSelectSpace").click(function() {
$("#dialogSelectSpace").dialog("open");
return false;
});
var autoPray = function() {
var nowTab = getNowTab();
var faith = gamePage.resPool.get('faith');
if (faith.value / faith.maxValue > 0.30) {
changeTab('Religion');
$(".btnContent:contains('Praise the sun!')").click();
changeTab(nowTab);
}
};
var getNowTab = function() {
return gamePage.ui.activeTabId;
};
var changeTab = function(tabName) {
if (gamePage.ui.activeTabId != tabName) {
gamePage.ui.activeTabId = tabName;
gamePage.render();
}
};
var autoBuild = function(onlyActiveBonfire) {
// default
if (onlyActiveBonfire !== true) {
onlyActiveBonfire = false;
}
var nowTab = getNowTab();
if (onlyActiveBonfire && nowTab != 'Bonfire') {
return;
}
changeTab('Bonfire');
for (var i = 0; i < buildings.length; i++) {
if ($('input#autoBuild' + (buildings[i]).replace(/\s+/g, "")).prop("checked")) {
$("div:not('.disabled') > div.btnContent:contains('" + buildings[i] + "')").click();
}
}
changeTab(nowTab);
};
var autoSpace = function(onlyActiveSpace) {
// default
if (onlyActiveSpace !== true) {
onlyActiveSpace = false;
}
var nowTab = getNowTab();
if (onlyActiveSpace && nowTab != 'Space') {
return;
}
changeTab('Space');
for (var i = 0; i < spaces.length; i++) {
if ($('input#autoSpace' + (spaces[i]).replace(/\s+/g, "")).prop("checked")) {
$("div:not('.disabled') > div.btnContent:contains('" + spaces[i] + "')").click();
}
}
changeTab(nowTab);
};
var autoObserve = function() {
var $observe = $("#observeButton").find("input");
if ($observe[0]) {
$observe.click();
}
};
var autoCraft = function() {
for (var i = 0; i < resources.length; i++) {
if ($('input#autoCraft' + resources[i][1]).prop("checked")) {
craftAll(resources[i][1], resources[i][0], 0.99);
}
}
};
var autoHunt = function() {
var catpower = gamePage.resPool.get('manpower');
if (catpower.value / catpower.maxValue > 0.80) {
$("a:contains('Send hunters (')").click();
if (gamePage.workshop.getCraft('parchment').unlocked) { gamePage.craftAll('parchment'); }
}
};
var autoTrade = function() {
for (var i = trades.length - 1; i >= 0; i--) {
if ($('input#autoTrade' + trades[i][1]).prop("checked")) {
trade(trades[i][0], trades[i][1], trades[i][2], trades[i][3]);
}
}
};
var isFirstTrade = true;
var trade = function(target, from, sell, sellNum) {
var resource = gamePage.resPool.get(target);
if (resource.value / resource.maxValue > 0.95) {
return;
}
var gold = gamePage.resPool.get('gold');
var catpower = gamePage.resPool.get('manpower');
var sellResource = gamePage.resPool.get(sell);
if (gold.value < 15 * 25 || catpower < 50 * 25 || sellResource < sellNum) {
return;
}
if (isFirstTrade) {
var nowTab = getNowTab();
changeTab('Trade');
changeTab(nowTab);
isFirstTrade = false;
}
for (var i = 0; i < gamePage.diplomacyTab.racePanels.length; i++) {
if (gamePage.diplomacyTab.racePanels[i].race.name == from) {
gamePage.diplomacyTab.racePanels[i].tradeBtn.tradeAll();
break;
}
}
};
var craftAll = function(target, resource, raito) {
if (!gamePage.workshop.getCraft(target).unlocked) {
return;
}
var quantity = gamePage.resPool.get(resource);
if (quantity.value / quantity.maxValue >= raito) {
gamePage.craftAll(target);
}
};
var auto = function() {
if ($("input#autoPray").prop("checked")) {
autoPray();
}
if ($("input#autoObserve").prop("checked")) {
autoObserve();
}
if ($("input#autoBuild").prop("checked")) {
autoBuild(true);
}
if ($("input#autoCraft").prop("checked")) {
autoCraft();
}
if ($("input#autoHunt").prop("checked")) {
autoHunt();
}
if ($("input#autoTrade").prop("checked")) {
autoTrade();
}
if ($("input#autoSpace").prop("checked")) {
autoSpace(true);
}
};
var auto2 = function() {
if ($("input#autoBuild").prop("checked")) {
autoBuild(false);
}
if ($("input#autoSpace").prop("checked")) {
autoSpace(false);
}
};
setInterval(auto, 0.3 * 1000);
setInterval(auto2, 60 * 1000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment