// ==UserScript==
// @name IdleHelper
// @namespace http://tampermonkey.net/
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js
// @description Some QoL and automation features for Idle Lands.
// @author Farflier
// @match http://idle.land/*
// @version 0.21
// @grant none
// ==/UserScript==
(function() {
'use strict';
$ = jQuery = jQuery.noConflict(true);
function ComponentProvider(){
this.find = function (search){
var n = ng.probe($(search)[0]);
if (n){
return n.componentInstance;
}
return null;
};
this.init = function(){
Object.defineProperties(ComponentProvider.prototype, {
app : {
get: function () {
return this.find("ng-component");
}},
overviewPage: {
get: function () {
return this.find("page-overview");
}},
petsPage: {
get: function () {
return this.find("page-pets");
}},
settingsPage : {
get: function () {
return this.find("page-settings");
}}
});
};
}
var cp = new ComponentProvider();
cp.init();
// window.ts1 = cp.app;
function IdleHelper(){
var k = "IdleHelper";
var properties = ["str", "con", "dex", "agi", "int", "luk", "aegis", "crit", "dance", "defense", "gold", "hp", "hpregen", "mp", "mpregen", "offense", "poison", "prone", "power", "salvage", "sentimentality", "silver", "vorpal", "xp"];
this.attachListener = function(){
if (typeof window.socket !== 'undefined'){
window.socket.on("data", function(data){
if (data.update == "player"){
if (idleHelper.settings.autoGold){
// Take gold if nearing full
if (cp.app.state.petactive._value.gold.__current > cp.app.state.petactive._value.gold.maximum / 2){
cp.app.primus.takePetGold();
}
}
if (idleHelper.settings.autoChoice){
idleHelper.handleChoices();
}
if (idleHelper.settings.autoInventory && typeof cp.app.state.petactive._value.inventory !== 'undefined'){
// Process inventory if nearing full
if (cp.app.state.petactive._value.inventory.length >= cp.app.state.petactive._value.$scale.inventory[cp.app.state.petactive._value.scaleLevel.inventory] -1){
idleHelper.processInventory();
}
}
}
idleHelper.renderUI();
});
console.log("Idle Helper observing data");
}else{
setTimeout(this.attachListener, 500);
}
}
this.getStatOptions = function(selected){
var statOptions = '<option value="_calcScore">Item Score</option>';
properties.forEach(function(prop){
if (prop == selected){
statOptions += '<option value="'+prop+'" selected>'+prop+'</option>';
}else{
statOptions += '<option value="'+prop+'">'+prop+'</option>';
}
});
return statOptions;
}
this.getPetOptions = function(selected){
selected = selected || '';
var petOptions = '<option value="">-- Select a pet --</option>';
cp.app.state.petbasic._value.forEach(function(pet){
if (pet.bought){
if (pet.name == selected){
petOptions += '<option value="'+pet.name+'" selected>'+pet.name+'</option>';
}else{
petOptions += '<option value="'+pet.name+'">'+pet.name+'</option>';
}
}
});
return petOptions;
}
this.loadSettings = function(reset){
reset = reset || false;
// load default settings
this.settings = {
autoChoice: false,
autoEnchant: false,
autoGold: false,
autoInventory: false,
autoSalvage: false,
salvagePet: '',
activePet: '',
changeProfession: {
archer: false,
barbarian: false,
bard: false,
beatomancer: false,
bitomancer: false,
cleric: false,
clockborg: false,
druid: false,
fencer: false,
fighter: false,
generalist: false,
jester: false,
mage: false,
magicalMonster: false,
monster: false,
necromancer: false,
pirate: false,
rogue: false,
sandwichArtist: false,
trickster: false
},
itemFilters: []
};
if (!reset){
var str = localStorage.getItem(k);
if (str){
// Overwrite defaults with user settings that exist
this.settings = Object.assign(this.settings, JSON.parse(str));
}
}
console.log(this.settings);
}
this.saveSettings = function(){
$('.idle-helper-checkbox').each(function(idx, input){
idleHelper.settings[$(input).attr('name')] = $(input).is(':checked');
});
$('.idle-helper-select').each(function(idx, input){
idleHelper.settings[$(input).attr('name')] = $(input).val();
});
$('.idle-helper-profession').each(function(idx, input){
idleHelper.settings.changeProfession[$(input).attr('name')] = $(input).is(':checked');
});
var filters = [];
$('.idle-helper-filter').each(function(idx, filter){
var obj = {type: $(this).find('select[name="type"]').val(), value: $(this).find('input[name="value"]').val(), pet: $(this).find('select[name="pet"]').val()};
filters.push(obj);
});
this.settings.itemFilters = filters;
localStorage.setItem(k, JSON.stringify(this.settings));
console.log(this.settings);
}
this.reloadUI = function(){
$('.idle-helper-ui').remove();
this.renderUI();
}
this.renderUI = function(){
/*
_wasEquipped
_calcScore
*/
if (!$('.idle-helper-ui').length){
if ($('page-overview > .content').length){
/* var stats = '<ion-row class="row idle-helper-ui">' +
' <ion-col class="col">' +
' <ion-card class="card card-md">' +
' <ion-card-header class="card-header card-header-md">Idle Helper Metrics</ion-card-header>' +
' <ion-card-content class="card-content card-content-md">' +
' <ion-row class="row">' +
' <ion-col class="size-150 col">' +
' <span><game-icon><i class="game-icon game-icon-stat-gold"></i></game-icon></span>gold here' +
' </ion-col>' +
' </ion-row>' +
' </ion-card-content>' +
' </ion-card>' +
' </ion-col>' +
'</ion-row>';
$('.adventure-log').closest('.row').before(stats);*/
var choiceButton = ' <button class="idle-helper-ui button button-md button-default button-default-md button-small button-small-md button-md-primary" onClick="idleHelper.handleChoices()">' +
' <span class="button-inner"><div>Handle Choices</div></span>' +
' </button>';
$('span:contains("Choice Log")').parent().after(choiceButton);
}else if($('page-pets > .content').length){
var ui = ' <button class="idle-helper-ui button button-md button-default button-default-md button-small button-small-md button-md-primary" onClick="idleHelper.helperSalvage()">' +
' <span class="button-inner"><div>Helper Salvage</div></span>' +
' </button>';
$('span:contains("Pet Inventory")').parent().after(ui);
}else if($('page-settings > .content').length){
var ui = ' <ion-card class="idle-helper-ui card card-md">' +
' <ion-card-header class="card-header card-header-md">Idle Helper Settings' +
' <button class="button button-md button-default button-default-md button-small button-small-md button-md-primary" onClick="idleHelper.saveSettings()">' +
' <span class="button-inner"><div>Save Settings</div></span>' +
' </button>' +
' <button class="button button-md button-default button-default-md button-small button-small-md button-md-primary" onClick="idleHelper.loadSettings(true)">' +
' <span class="button-inner"><div>Load Defaults</div></span>' +
' </button>' +
' <button class="button button-md button-default button-default-md button-small button-small-md button-md-primary" onClick="idleHelper.reloadUI()">' +
' <span class="button-inner"><div>Reload UI</div></span>' +
' </button>' +
' </ion-card-header>' +
' <ion-card-content class="card-content card-content-md">' +
' <ion-list class="list list-md">' +
' <ion-item class="item item-md">' +
' <div class="item-inner">' +
' <div class="input-wrapper">' +
' <span><input id="autoChoice" class="idle-helper-checkbox" name="autoChoice" type="checkbox" style="width:10%;">Automate Choices - respond to choices according to your settings and item filters. You may also manually execute this with the button on your choice log. Choices matching no setting will remain unchosen.</span>' +
' </div>' +
' </div>' +
' </ion-item>' +
' <ion-item class="item item-md">' +
' <div class="item-inner">' +
' <div class="input-wrapper">' +
' <span><input id="autoEnchant" class="idle-helper-checkbox" name="autoEnchant" type="checkbox" style="width:10%;">Accept Enchantments - Accept enchantments, or decline if unchecked.</span>' +
' </div>' +
' </div>' +
' </ion-item>' +
' <ion-item class="item item-md">' +
' <div class="item-inner">' +
' <div class="input-wrapper">' +
' <span><input id="autoGold" class="idle-helper-checkbox" name="autoGold" type="checkbox" style="width:10%;">Take Pet Gold - whenever it is more than half full.</span>' +
' </div>' +
' </div>' +
' </ion-item>' +
' <ion-item class="item item-md">' +
' <div class="item-inner">' +
' <div class="input-wrapper">' +
' <span><input id="autoInventory" class="idle-helper-checkbox" name="autoInventory" type="checkbox" style="width:10%;">Handle Inventory - automatically apply settings to inventory items (except previously equipped) whenever your pet nears a full inventory (one less than max).</span>' +
' </div>' +
' </div>' +
' </ion-item>' +
' <ion-item class="item item-md">' +
' <div class="item-inner">' +
' <div class="input-wrapper">' +
' <span><input id="autoSalvage" class="idle-helper-checkbox" name="autoSalvage" type="checkbox" style="width:10%;">Autosalvage Junk - use your salvage pet to salvage all items that do not pass item filters and other settings (except items you have previously equipped) whenever Idle Helper processes your inventory. If left unchecked, merchant and item events will be declined, and free items will be taken and salvaged if you set a salvage pet, or sold.</span>' +
' </div>' +
' </div>' +
' </ion-item>' +
' <ion-item class="item item-md item-label-stacked">' +
' <div class="item-inner">' +
' <div class="input-wrapper">' +
' <ion-label class="label label-md" stacked="">Active Pet</ion-label>' +
' <select id="activePet" class="idle-helper-select" name="activePet" style="color:black;">' + this.getPetOptions(this.settings.activePet) + '</select>' +
' </div>' +
' <div class="input-wrapper" style="margin-left:10px;">' +
' <ion-label class="label label-md" stacked="">Salvage Pet</ion-label>' +
' <select id="salvagePet" class="idle-helper-select" name="salvagePet" style="color:black;">' + this.getPetOptions(this.settings.salvagePet) + '</select>' +
' </div>' +
' </div>' +
' </ion-item>' +
' <ion-item-divider class="item item-divider item-md item-divider-md"><div class="item-inner"><div class="input-wrapper"><ion-label class="label label-md">Accept Trainer Offers</ion-label></div></div></ion-item-divider>' +
' <ion-item class="item item-md">' +
' <div class="item-inner">' +
' <div class="input-wrapper">' +
' <span><input id="auto-archer" class="idle-helper-profession" name="archer" type="checkbox"> Archer</span>' +
' </div>' +
' <div class="input-wrapper">' +
' <span><input id="auto-barbarian" class="idle-helper-profession" name="barbarian" type="checkbox"> Barbarian</span>' +
' </div>' +
' <div class="input-wrapper">' +
' <span><input id="auto-bard" class="idle-helper-profession" name="bard" type="checkbox"> Bard</span>' +
' </div>' +
' <div class="input-wrapper">' +
' <span><input id="auto-beatomancer" class="idle-helper-profession" name="beatomancer" type="checkbox"> Beatomancer</span>' +
' </div>' +
' </div>' +
' </ion-item>' +
' <ion-item class="item item-md">' +
' <div class="item-inner">' +
' <div class="input-wrapper">' +
' <span><input id="auto-bitomancer" class="idle-helper-profession" name="bitomancer" type="checkbox"> Bitomancer</span>' +
' </div>' +
' <div class="input-wrapper">' +
' <span><input id="auto-cleric" class="idle-helper-profession" name="cleric" type="checkbox"> Cleric</span>' +
' </div>' +
' <div class="input-wrapper">' +
' <span><input id="auto-clockborg" class="idle-helper-profession" name="clockborg" type="checkbox"> Clockborg</span>' +
' </div>' +
' <div class="input-wrapper">' +
' <span><input id="auto-druid" class="idle-helper-profession" name="druid" type="checkbox"> Druid</span>' +
' </div>' +
' </div>' +
' </ion-item>' +
' <ion-item class="item item-md">' +
' <div class="item-inner">' +
' <div class="input-wrapper">' +
' <span><input id="auto-fencer" class="idle-helper-profession" name="fencer" type="checkbox"> Fencer</span>' +
' </div>' +
' <div class="input-wrapper">' +
' <span><input id="auto-fighter" class="idle-helper-profession" name="fighter" type="checkbox"> Fighter</span>' +
' </div>' +
' <div class="input-wrapper">' +
' <span><input id="auto-generalist" class="idle-helper-profession" name="generalist" type="checkbox"> Generalist</span>' +
' </div>' +
' <div class="input-wrapper">' +
' <span><input id="auto-jester" class="idle-helper-profession" name="jester" type="checkbox"> Jester</span>' +
' </div>' +
' </div>' +
' </ion-item>' +
' <ion-item class="item item-md">' +
' <div class="item-inner">' +
' <div class="input-wrapper">' +
' <span><input id="auto-mage" class="idle-helper-profession" name="mage" type="checkbox"> Mage</span>' +
' </div>' +
' <div class="input-wrapper">' +
' <span><input id="auto-magicalmonster" class="idle-helper-profession" name="magicalMonster" type="checkbox"> MagicalMonster</span>' +
' </div>' +
' <div class="input-wrapper">' +
' <span><input id="auto-monster" class="idle-helper-profession" name="monster" type="checkbox"> Monster</span>' +
' </div>' +
' <div class="input-wrapper">' +
' <span><input id="auto-necromancer" class="idle-helper-profession" name="necromancer" type="checkbox"> Necromancer</span>' +
' </div>' +
' </div>' +
' </ion-item>' +
' <ion-item class="item item-md">' +
' <div class="item-inner">' +
' <div class="input-wrapper">' +
' <span><input id="auto-pirate" class="idle-helper-profession" name="pirate" type="checkbox"> Pirate</span>' +
' </div>' +
' <div class="input-wrapper">' +
' <span><input id="auto-rogue" class="idle-helper-profession" name="rogue" type="checkbox"> Rogue</span>' +
' </div>' +
' <div class="input-wrapper">' +
' <span><input id="auto-sandwichartist" class="idle-helper-profession" name="sandwichArtist" type="checkbox"> SandwichArtist</span>' +
' </div>' +
' <div class="input-wrapper">' +
' <span><input id="auto-trickster" class="idle-helper-profession" name="trickster" type="checkbox"> Trickster</span>' +
' </div>' +
' </div>' +
' </ion-item>' +
' <ion-item-divider class="item item-divider item-md item-divider-md"><div class="item-inner"><div class="input-wrapper"><ion-label class="label label-md">Item Filters - store items for later (applies in order)</ion-label></div></div></ion-item-divider>' +
' <ion-item id="item-filter-controls" class="item item-md item-label-stacked">' +
' <div class="item-inner">' +
' <div class="input-wrapper">' +
' <button class="button button-md button-default button-default-md button-small button-small-md button-md-primary" onClick="idleHelper.addFilter()">' +
' <span class="button-inner"><div>Add Filter</div></span>' +
' </button>' +
' </div>' +
' </div>' +
' </ion-item>' +
' <ion-item class="item item-md item-label-stacked">' +
' <div class="item-inner">' +
' <div class="input-wrapper">' +
' <button class="button button-md button-default button-default-md button-small button-small-md button-md-primary" onClick="idleHelper.saveSettings()">' +
' <span class="button-inner"><div>Save Settings</div></span>' +
' </button>' +
' </div>' +
' <div class="input-wrapper">' +
' <button class="button button-md button-default button-default-md button-small button-small-md button-md-primary" onClick="idleHelper.loadSettings(true)">' +
' <span class="button-inner"><div>Load Defaults</div></span>' +
' </button>' +
' </div>' +
' <div class="input-wrapper">' +
' <button class="button button-md button-default button-default-md button-small button-small-md button-md-primary" onClick="idleHelper.reloadUI()">' +
' <span class="button-inner"><div>Reload UI</div></span>' +
' </button>' +
' </div>' +
' </div>' +
' </ion-item>' +
' </ion-list>' +
' </ion-card-content>' +
' </ion-card>';
$('page-settings > .content > .scroll-content ion-col').first().append(ui);
$('.idle-helper-checkbox').each(function(idx,input){
$(input).prop('checked', idleHelper.settings[$(input).attr('name')]);
});
$('.idle-helper-profession').each(function(idx,input){
$(input).prop('checked', idleHelper.settings.changeProfession[$(input).attr('name')]);
});
this.renderFilters();
}
}
}
this.renderFilters = function(){
this.settings.itemFilters.forEach(function(filter){
idleHelper.addFilter(filter.type, filter.value, filter.pet);
});
}
this.addFilter = function(type, value, pet){
var type = type || '';
var value = value || '';
var pet = pet || '';
var html = '<ion-item class="item item-md item-label-stacked idle-helper-filter">' +
' <div class="item-inner">' +
' <div class="input-wrapper">' +
' <ion-label class="label label-md" stacked="">Property</ion-label>' +
' <select name="type" style="color:black;">' + this.getStatOptions(type) + '</select>' +
' </div>' +
' <div class="input-wrapper" style="margin-left:10px;">' +
' <ion-label class="label label-md" stacked="">Greater Than</ion-label>' +
' <input name="value" value="' + value + '" type="text" style="height:24px;color:black;">' +
' </div>' +
' <div class="input-wrapper" style="margin-left:10px;">' +
' <ion-label class="label label-md" stacked="">Give To</ion-label>' +
' <select name="pet" style="color:black;">' + this.getPetOptions(pet) + '</select>' +
' </div>' +
' <div class="input-wrapper" style="margin-left:10px;">' +
' <ion-label class="label label-md" stacked=""> </ion-label>' +
' <button class="button button-md button-default button-default-md button-small button-small-md button-md-primary" onClick="idleHelper.removeFilter(this)" style="margin:0;padding:0;">' +
' <span class="button-inner"><div>Remove</div></span>' +
' </button>' +
' </div>' +
' </div>' +
'</ion-item>';
$('#item-filter-controls').before(html);
}
this.removeFilter = function(filter){
$(filter).parents('.idle-helper-filter').remove();
}
this.clearFilters = function(){
$('.idle-helper-filter').remove();
}
this.handleChoices = function(){
if (!cp.app.state.player._value.choices.length){
return;
}
cp.app.state.player._value.choices.forEach(function(choice){
if (choice.event == "FindItem" || choice.event == "Merchant"){
if (choice.event == "Merchant" && !idleHelper.settings.autoSalvage){
// Decline merchants if we're not salvaging
cp.app.primus.makeChoice(choice.id, choice.choices[1]);
}else{
// Send all items to pet inventory, process from there
cp.app.primus.makeChoice(choice.id, choice.choices[2]);
}
}else if(choice.event == "ProfessionChange"){
if (idleHelper.settings.changeProfession[choice.extraData.professionName.charAt(0).toLowerCase() + choice.extraData.professionName.slice(1)]){
cp.app.primus.makeChoice(choice.id, choice.choices[0]);
}else{
cp.app.primus.makeChoice(choice.id, choice.choices[1]);
}
}else if (choice.event == "MerchantEnchant"){
// extraData.cost, choices = [yes, no]
if (idleHelper.settings.autoEnchant){
cp.app.primus.makeChoice(choice.id, choice.choices[0]);
}else{
cp.app.primus.makeChoice(choice.id, choice.choices[1]);
}
}
});
}
this.processInventory = function(){
cp.app.state.petactive._value.inventory.forEach(function(item){
// Ignore items that were previously equipped
if (item.hasOwnProperty('_wasEquipped') && item._wasEquipped){
return;
}
var done = false;
// Filter items to their respective pets
idleHelper.settings.itemFilters.forEach(function(filter){
if (item.hasOwnProperty(filter.type) && item[filter.type] >= filter.value){
cp.app.primus.giveItemToOtherPet(item.id, filter.pet);
done = true;
}
});
// Stash junk on salvage pet, or sell
if (!done){
if (idleHelper.settings.autoSalvage && idleHelper.settings.salvagePet && idleHelper.settings.salvagePet != cp.app.state.petactive._value.$petId){
cp.app.primus.giveItemToOtherPet(item.id, idleHelper.settings.salvagePet);
}else{
cp.app.primus.sellItemFromPet(item.id);
}
}
});
// Auto salvage
if (idleHelper.settings.autoSalvage){
if (idleHelper.settings.salvagePet && idleHelper.settings.salvagePet != cp.app.state.petactive._value.$petId){
cp.app.primus.makePetActive(idleHelper.settings.salvagePet);
}
cp.app.state.petactive._value.inventory.forEach(function(item){
// Ignore items that were previously equipped
if (item.hasOwnProperty('_wasEquipped') && item._wasEquipped){
return;
}
cp.app.primus.salvageItemFromPet(item.id);
});
if (cp.app.state.petactive._value.gold.__current){
cp.app.primus.takePetGold();
}
if (idleHelper.settings.activePet && idleHelper.settings.activePet != cp.app.state.petactive._value.$petId){
cp.app.primus.makePetActive(idleHelper.settings.activePet);
}
}
}
this.helperSalvage = function(){
if (idleHelper.settings.salvagePet){
cp.app.state.petactive._value.inventory.forEach(function(item){
// Ignore items that were previously equipped
if (item.hasOwnProperty('_wasEquipped') && item._wasEquipped){
return;
}
cp.app.primus.giveItemToOtherPet(item.id, idleHelper.settings.salvagePet);
});
var currPet = cp.app.state.petactive._value.$petId;
if (idleHelper.settings.salvagePet && idleHelper.settings.salvagePet != cp.app.state.petactive._value.$petId){
cp.app.primus.makePetActive(idleHelper.settings.salvagePet);
}
cp.app.state.petactive._value.inventory.forEach(function(item){
// Ignore items that were previously equipped
if (item.hasOwnProperty('_wasEquipped') && item._wasEquipped){
return;
}
cp.app.primus.salvageItemFromPet(item.id);
});
if (cp.app.state.petactive._value.$petId != currPet){
cp.app.primus.makePetActive(currPet);
}
}else{
alert("No salvage pet set!");
}
}
}
function initHelper(){
console.log("Idle Helper Init");
cp.app.primus.requestEquipment();
cp.app.primus.requestGuild();
cp.app.primus.requestGuildBuildings();
cp.app.primus.requestPets();
window.idleHelper = new IdleHelper();
idleHelper.loadSettings();
idleHelper.attachListener();
}
setTimeout(initHelper, 3000);
})();