/ ‘grepolis.user.js’

This commit is contained in:
Jan Bader 2014-06-04 15:38:28 +02:00
parent 0b459dcdd7
commit 72983e71d0

View File

@ -10,7 +10,7 @@
// //
// @match http://*.grepolis.com/game/* // @match http://*.grepolis.com/game/*
// //
// @version 1.0.37 // @version 1.0.38
// @updateURL http://git.javil.eu/jan/userscripts/raw/master/grepolis.user.js // @updateURL http://git.javil.eu/jan/userscripts/raw/master/grepolis.user.js
// ==/UserScript== // ==/UserScript==
@ -45,6 +45,8 @@
setTimeout(getWaresTick, 5000); setTimeout(getWaresTick, 5000);
function getWaresTick(xFarmId) { function getWaresTick(xFarmId) {
return function() { return function() {
var timeout = 60000;
try {
var d = new Date(); var d = new Date();
var dformat = "[" + [d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds()].join(':') + "]"; var dformat = "[" + [d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds()].join(':') + "]";
$('.town_name').text(dformat); $('.town_name').text(dformat);
@ -59,7 +61,7 @@
{'action': "claim_info"}, {'action': "claim_info"},
xFarmId); xFarmId);
windows[xFarmId] = wnd.getID(); windows[xFarmId] = wnd.getID();
setTimeout(getWaresTick(xFarmId), 500); timeout = 500;
return; return;
} }
@ -67,7 +69,7 @@
if(wnd == undefined){ if(wnd == undefined){
windows[xFarmId] = undefined; windows[xFarmId] = undefined;
console.log("Window not open any more"); console.log("Window not open any more");
setTimeout(getWaresTick(xFarmId), 50); timeout = 50;
return; return;
} }
@ -80,7 +82,7 @@
} catch(e) { } catch(e) {
console.warn("Could not close Window"); console.warn("Could not close Window");
} }
setTimeout(getWaresTick(xFarmId), 50); timeout = 50;
return; return;
} }
var btn = $(wndElement).find(".farm_claim_box .farm_claim_res0 + div + a"); var btn = $(wndElement).find(".farm_claim_box .farm_claim_res0 + div + a");
@ -93,18 +95,19 @@
var minutes = ts.substring(2,4); var minutes = ts.substring(2,4);
var seconds = minutes * 60 + ts.substring(5,7) * 1; var seconds = minutes * 60 + ts.substring(5,7) * 1;
$('.town_name').text(dformat + " +" + ts); $('.town_name').text(dformat + " +" + ts);
console.log("btn is inactive, trying again in " + ts); console.log("btn is inactive, trying again in " + ts);
wnd.close(); wnd.close();
setTimeout(getWaresTick(xFarmId), seconds * 1000 + 1000); timeout = seconds * 1000 + 1000;
return; return;
} }
} }
getWaresFromFarm(btn[0], mood, xFarmId); getWaresFromFarm(btn[0], mood, xFarmId);
setTimeout(getWaresTick(xFarmId), 60 * 1000); } finally {
setTimeout(getWaresTick(xFarmId), timeout);
}
} }
} }