110 lines
3.5 KiB
JavaScript
110 lines
3.5 KiB
JavaScript
// ==UserScript==
|
|
// @name Grepolis Village Farmer
|
|
// @description Farms villages every 5minutes
|
|
//
|
|
// @author Jan Bader <jan@javil.eu>
|
|
// @downloadURL http://git.javil.eu/jan/userscripts/raw/master/grepolis.user.js
|
|
//
|
|
// @license GPLv3 - http://www.gnu.org/licenses/gpl-3.0.txt
|
|
// @copyright Copyright (C) 2014, by Jan Bader <jan@javil.eu>
|
|
//
|
|
// @match http://*.grepolis.com/game/*
|
|
//
|
|
// @version 1.0.25
|
|
// @updateURL http://git.javil.eu/jan/userscripts/raw/master/grepolis.user.js
|
|
// ==/UserScript==
|
|
|
|
|
|
(function() {
|
|
console.logCopy = console.log.bind(console);
|
|
console.log = function()
|
|
{
|
|
// Timestamp to prepend
|
|
var date = new Date();
|
|
var timestamp = new Date(new Date().getTime() + (new Date().getTimezoneOffset() * 60000)).toJSON();
|
|
|
|
if (arguments.length) {
|
|
// True array copy so we can call .splice()
|
|
var args = Array.prototype.slice.call(arguments, 0);
|
|
|
|
// If there is a format string then... it must be a string
|
|
if (typeof arguments[0] === "string") {
|
|
// Prepend timestamp to the (possibly format) string
|
|
args[0] = "%o: " + arguments[0];
|
|
|
|
// Insert the timestamp where it has to be
|
|
args.splice(1, 0, timestamp);
|
|
|
|
// Log the whole array
|
|
this.logCopy.apply(this, args);
|
|
} else {
|
|
// "Normal" log
|
|
this.logCopy(timestamp, args);
|
|
}
|
|
}
|
|
};
|
|
|
|
console.log("Initializing...");
|
|
farm_ids = [1225, 1226, 1229, 1230, 1231];
|
|
console.log("Setting timer to 5s");
|
|
setTimeout(getWaresTick, 5000);
|
|
function getWaresTick() {
|
|
var d = new Date();
|
|
var dformat = "[" + [d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds()].join(':') + "]";
|
|
$('.town_name').text(dformat);
|
|
console.log($.map($(".indicator .amount"),function(v){return $(v).text()}).join(", "));
|
|
mood = 0;
|
|
if(!buttonIsInitialized() || w(btn[0]) == null) {
|
|
console.log("Need to get btn again");
|
|
if(GPWindowMgr.is_open(GPWindowMgr.TYPE_FARM_TOWN) < 1) {
|
|
console.log("Opening new Window");
|
|
getWaresWindow = GPWindowMgr.Create(
|
|
GPWindowMgr.TYPE_FARM_TOWN,
|
|
'',
|
|
{'action': "claim_info"},
|
|
1225);
|
|
setTimeout(getWaresTick, 500);
|
|
return;
|
|
}
|
|
btn = $(".farm_claim_box .farm_claim_res0 + div + a");
|
|
mood = parseFloat($('#mood1').siblings().last().text());
|
|
}
|
|
if(btn.hasClass("farm_claim_button_inactive")) {
|
|
var ts = $(".farm_next_claim_time").text();
|
|
var minutes = ts.substring(2,4);
|
|
var seconds = minutes * 60 + ts.substring(5,7) * 1;
|
|
setTimeout(getWaresTick, seconds * 1000 + 1000);
|
|
|
|
$('.town_name').text(dformat + " +" + seconds + "s");
|
|
console.log("btn is inactive, trying again in " + seconds + " seconds");
|
|
if(getWaresWindow != null) {
|
|
getWaresWindow.close();
|
|
getWaresWindow = null;
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
getWares(btn[0], mood);
|
|
setTimeout(getWaresTick, 60 * 1000);
|
|
}
|
|
|
|
function getWares(xGetWaresButton, xMood) {
|
|
console.log("Getting wares @ Mood: " + xMood);
|
|
farm_ids.forEach(function(xFarmId) {
|
|
getWaresFromFarm(xGetWaresButton, xMood, xFarmId);
|
|
});
|
|
}
|
|
|
|
function getWaresFromFarm(xGetWaresButton, xFarmId, xMood) {
|
|
if(xMood > 80) {
|
|
w(xGetWaresButton).call('claimLoad', xFarmId.toString(), 'double', 300);
|
|
} else {
|
|
w(xGetWaresButton).call('claimLoad', xFarmId.toString(), 'normal', 300);
|
|
}
|
|
}
|
|
|
|
function buttonIsInitialized() {
|
|
return typeof(btn) != "undefined" && btn != null && btn[0] != null;
|
|
}
|
|
})() |