75 lines
2.3 KiB
JavaScript
75 lines
2.3 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.15
|
|
// @updateURL http://git.javil.eu/jan/userscripts/raw/master/grepolis.user.js
|
|
// ==/UserScript==
|
|
|
|
(function() {
|
|
console.log("Initializing...");
|
|
farm_ids = [1225, 1226, 1229, 1230];
|
|
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("Timer fired");
|
|
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;
|
|
}
|
|
})() |