There are 1 previous version of this script.
// ==UserScript==
// @name Travian: Penyelamat Askar
// @author Payal
// @description Troop Saver untuk server my
// @namespace n\a
// @include http://*.travian*.com.my/*
// @include http://my*.travian.com/*
// @exclude http://forum.travian.*
// @email fazial@gmail.com
// @version 1.0 BETA
// ==/UserScript==
//Change these to some valid coordinates for your server
var xSave = 0;
var ySave = 0;
var reload = true;
loginCheck();
setTimeout(function(){autoreload()},900000);
checkImg(document)
function getArrivalTime()
{
div = document.getElementById('ltbw0');
if (!div) {div = document.getElementById('ltbw1'); }
rows = div.getElementsByTagName("tr");
for (x=0;x<rows.length;x++)
{
cells = rows[x].getElementsByTagName("td");
if (cells[0].innerHTML.search('att1') > 0)
{
arrival = cells[4].getElementsByTagName("span")[0].innerHTML;
}
}
hours = parseInt(arrival.split(':')[0]);
minutes = parseInt(arrival.split(':')[1]);
seconds = parseInt(arrival.split(':')[2]);
totSeconds = hours*60*60 + minutes*60 + seconds
if (totSeconds < 30)
{
GM_log(">30 seconds");
reload = false;
saveTroops();
}else{
window.setTimeout(function(){getArrivalTime()},1000);
}
}
function checkImg(doc)
{
var ex = "//img[contains(@src,'att1')]";
tag = document.evaluate(
ex,
doc,
null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
null);
if (tag.snapshotLength) { getArrivalTime();}
}
//saveTroops();
function saveTroops(){
GM_log("Preparing to send away");
url = "http://" + document.domain + "/a2b.php?" + getActiveVillage();
GM_xmlhttpRequest({
method: "GET",
url: url,
onload: function(responseDetails)
{
pulled = document.createElement('div');
pulled.innerHTML = responseDetails.responseText;
prepSave(pulled);
}
});
}
function prepSave(pulled)
{
t1 = getTotalUnit(pulled,'t1')
t2 = getTotalUnit(pulled,'t2')
t3 = getTotalUnit(pulled,'t3')
t4 = getTotalUnit(pulled,'t4')
t5 = getTotalUnit(pulled,'t5')
t6 = getTotalUnit(pulled,'t6')
t7 = getTotalUnit(pulled,'t7')
t8 = getTotalUnit(pulled,'t8')
t9 = getTotalUnit(pulled,'t9')
t10 = getTotalUnit(pulled,'t10')
t11 = getTotalUnit(pulled,'t11')
if (t1 < 1 && t2 < 1 && t3 < 1 && t4 < 1 && t5 < 1 && t6 < 1 && t7 < 1 && t8 < 1 && t9 < 1 && t10 < 1 && t11 < 1)
{
return;
}
url = "http://" + document.domain + "/a2b.php?" + getActiveVillage();
data = 'b=1&t1='+t1+'&t4='+t4+'&t7='+t7+'&t9='+t9+'&t2='+t2+'&t5='+t5+'&t8='+t8+'&t10='+t10+'&t11='+t11+'&t3='+t3+'&t6='+t6+'&c=2&dname=&x='+xSave+'&y='+ySave+'&s1=ok';
GM_log(url + data);
GM_xmlhttpRequest({
method: "POST",
url: url,
headers:{'Content-type':'application/x-www-form-urlencoded'},
data:encodeURI(data),
onload: function(responseDetails)
{
pulled = document.createElement('div');
pulled.innerHTML = responseDetails.responseText;
finishSave(pulled);
}
});
}
function finishSave(pulled)
{
idValue = getValue(pulled, 'id');
aValue = getValue(pulled, 'a');
cValue = getValue(pulled, 'c');
kidValue = getValue(pulled, 'kid');
t1Value = getValue(pulled, 't1');
t2Value = getValue(pulled, 't2');
t3Value = getValue(pulled, 't3');
t4Value = getValue(pulled, 't4');
t5Value = getValue(pulled, 't5');
t6Value = getValue(pulled, 't6');
t7Value = getValue(pulled, 't7');
t8Value = getValue(pulled, 't8');
t9Value = getValue(pulled, 't9');
t10Value = getValue(pulled, 't10');
t11Value = getValue(pulled, 't11');
url = "http://" + document.domain + "/a2b.php?" + getActiveVillage();
data = 'id='+idValue+'&a='+aValue+'&c='+cValue+'&kid='+kidValue+'&t1='+t1Value+'&t2='+t2Value+'&t3='+t3Value+'&t4='+t4Value+'&t5='+t5Value+'&t6='+t6Value+'&t7='+t7Value+'&t8='+t8Value+'&t9='+t9Value+'&t10='+t10Value+'&t11='+t11Value+'&s1=ok&attacks=&cords=';
GM_log(url + data);
GM_xmlhttpRequest({
method: "POST",
url: url,
headers:{'Content-type':'application/x-www-form-urlencoded'},
data:encodeURI(data),
onload: function(responseDetails)
{
GM_log("Troops sent away");
pulled = document.createElement('div');
pulled.innerHTML = responseDetails.responseText;
window.setTimeout(function(){retreat()},16000);
GM_log("Troops will be retreated in 16 seconds");
}
});
}
function retreat ()
{
GM_log("Preparing to retreat troops");
url = "http://" + document.domain + "/build.php?id=39&" + getActiveVillage();
GM_xmlhttpRequest({
method: "GET",
url: url,
onload: function(responseDetails)
{
pulled = document.createElement('div');
pulled.innerHTML = responseDetails.responseText;
finishRetreat(pulled);
}
});
}
function finishRetreat(code)
{
var ex = ".//img[contains(@src,'del.gif')]/..";
tag = document.evaluate(
ex,
code,
null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
null);
if(tag.snapshotLength)
{
url = "" + tag.snapshotItem(0)
GM_xmlhttpRequest({
method: "GET",
url: url,
onload: function(responseDetails)
{
GM_log("Troops retreated");
pulled = document.createElement('div');
pulled.innerHTML = responseDetails.responseText;
GM_log("saved");
}
});
}
}
function getTotalUnit(doc,t)
{
var ex = ".//a[contains(@OnClick,'" + t + "')][@href='#']";
result = document.evaluate(
ex,
doc,
null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
null);
if (result.snapshotLength)
{
thisResult = result.snapshotItem(0).innerHTML;
return ((thisResult.substring(1,thisResult.length-1)))
}else{
return 0;
}
}
function getValue(doc, name)
{
var ex = ".//input[@type='hidden'][@name='" + name + "']";
tag = document.evaluate(
ex,
doc,
null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
null);
if (tag.snapshotLength)
{
aTag = tag.snapshotItem(0);
return(aTag.value);
}else{
return 0;
}
}
function getActiveVillage()
{
var ex = "//a[contains(@href,'newdid')][@class='active_vl']";
tag = document.evaluate(
ex,
document,
null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
null);
if (tag.snapshotLength)
{
temp = tag.snapshotItem(0).href.split("?")[1].split('&');
return temp[0];
}else{
return 0;
}
}
function readCookie(name) {
if(!name) {var name = "TROOPSAVER_X";}
var reg = new RegExp(name + "=([^;\n\r]*);?", "i");
var data = reg.exec(document.cookie);
if (data == null || data.length <= 1) {
return '';
}
return data[1];
};
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
return true;
};
loginCheck();
function loginCheck()
{
GM_registerMenuCommand("Troop Saver: Set Koordinat X", setXCoor);
GM_registerMenuCommand("Troop Saver: Set Koordinat Y", setYCoor);
xSave = readCookie("TROOPSAVER_X");
ySave = readCookie("TROOPSAVER_Y");
//alert(data);
if(xSave==''||ySave==''){ //jika cookie tidak wujud, create new one
createCookie("TROOPSAVER_X",0,365);
createCookie("TROOPSAVER_Y",0,365);
xSave = readCookie("TROOPSAVER_X");
ySave = readCookie("TROOPSAVER_Y");
}
GM_registerMenuCommand("Troop Saver Location: ("+ xSave +","+ ySave +")");
if (document.getElementsByName('login'))
{
var ex = ".//input[@value='login']";
tag = document.evaluate(
ex,
document,
null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
null);
var ex = ".//input[@type='password' and contains(@value, '*')]";
tag2 = document.evaluate(
ex,
document,
null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
null);
if(tag.snapshotLength && tag2.snapshotLength)
{
loginButton = tag.snapshotItem(0);
loginButton.click();
}
}
};
function isInt(x) {
var y = parseInt(x);
if (isNaN(y)) {return false;}
return x==y && x.toString()==y.toString();
};
function setXCoor(){
var newX = false;
//newX = prompt("Koordinat X anda? \nSekarang: "+xSave);
while(!isInt(newX)){
newX = prompt("Koordinat X anda? \nSekarang: "+xSave);
if(isInt(newX)){
newX = parseInt(newX);
if(newX < 1000){
createCookie("TROOPSAVER_X",newX,365);
location.reload();
break;
}else{
newX = false;
}
}
}
};
function setYCoor(){
var newY = false;
while(!isInt(newY)){
newY = prompt("Koordinat Y anda? \nSekarang: "+ySave);
if(isInt(newY)){
newY = parseInt(newY);
if(newY < 1000){
createCookie("TROOPSAVER_Y",newY,365);
location.reload();
break;
}else{
newY = false;
}
}
}
};
function autoreload()
{
if (reload)
{
url = "http://google.com";
GM_xmlhttpRequest({
method: "GET",
url: url,
onload: function(responseDetails)
{
pulled = document.createElement('div');
pulled.innerHTML = responseDetails.responseText;
// this reloading method avoids the browser asking whether to submit form again
if (location.href.indexOf('#') > 0) {
location.href = location.href.substring(0, location.href.length - 1); // remove trailing '#' or reload won't work
}
else {
location.href = location.href;
}
}
});
}
}
