// ==UserScript== // @name Grepolis Village Farmer // @description Farms villages every 5minutes // // @author Jan Bader // @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 // // @match http://*.grepolis.com/game/* // // @version 1.0.20 // @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(date.getTime() + (date.getTimezoneOffset() * 3600)).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(", ")); 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"); } 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]); setTimeout(getWaresTick, 60 * 1000); } function getWares(xGetWaresButton) { console.log("getting wares"); farm_ids.forEach(function(xFarmId) { getWaresFromFarm(xGetWaresButton, xFarmId); }); } function getWaresFromFarm(xGetWaresButton, xFarmId) { w(xGetWaresButton).call('claimLoad', xFarmId.toString(), 'normal', 300); } function buttonIsInitialized() { return typeof(btn) != "undefined" && btn != null && btn[0] != null; } })()