Set Arrival Time

Set the desired arrival time in Tribal Wars and the script will automatically send the attack

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name Set Arrival Time
// @description Set the desired arrival time in Tribal Wars and the script will automatically send the attack
// @author FunnyPocketBook
// @version 3.1
// @date 2018-05-20
// @namespace FunnyPocketBook
// @include https://*/game.php?village=*&screen=place&try=confirm
// ==/UserScript==

let inputMs;
let input;
let delay;
const showArrTimeTr = document.createElement("tr"); // Create button called btn as a link because any button causes the attack to launch
const showArrTimeTd = document.createElement("td");
const pEle = document.getElementById("troop_confirm_go"); // Button comes after this element
const btn = document.createElement("a"); // Create button called btn as a link because any button causes the attack to launch
btn.setAttribute("id", "arrTime"); // Set ID of btn
btn.setAttribute("class", "btn"); // Set ID of btn
btn.setAttribute("style", "cursor:pointer;"); // Set cursor to pointer
pEle.parentNode.insertBefore(btn, pEle.nextElementSibling); // Place btn after pEle
const t = document.createTextNode("Set arrival time"); // btn has this text
btn.appendChild(t); // Append text to btn

btn.onclick = function() {
	"use strict";
	let time = document.getElementsByClassName("relative_time")[0].textContent.slice(-8);
	let lalau = document.getElementById("date_arrival");
	input = prompt("Please enter desired arrival time", time);
	inputMs = parseInt(prompt("Please enter approximate milliseconds", "000"));
    delay = parseInt(delayTime) + parseInt(inputMs);
	showArrTimeTr.appendChild(showArrTimeTd);
	lalau.parentNode.parentNode.insertBefore(showArrTimeTr, lalau.parentNode[1]);
	showArrTimeTd.innerHTML = "Set arrival: ~" + input + ":" + inputMs;
	showArrTimeTd.setAttribute("colspan", "2");
	showArrTimeTd.setAttribute("id", "showArrTime");
};

let delayTime = parseInt(localStorage.delayTime);
if(delayTime == null) {
    delayTime = 0;
    localStorage.delayTime = JSON.stringify(delayTime);
}

// Create okay button to save delay
const delayTr = document.createElement("tr");
const delayTd1 = document.createElement("td");
const delayTd2 = document.createElement("td");
const parent1 = document.querySelector("#date_arrival"); // Cell of relative_time
delayTr.appendChild(delayTd1);
delayTr.appendChild(delayTd2);
parent1.parentNode.parentNode.insertBefore(delayTr, parent1.parentNode[1]); // Insert tablerow as last cell
delayTd1.innerHTML = "Offset";
delayTd2.innerHTML = "<input id = 'delayInput' value = " + delayTime + " style = 'width: 50%'></input> <a id = 'delayButton' class = 'btn'>OK</a>";

//debugger;
$("#delayButton").click(function() {
    delayTime = parseInt($("#delayInput").val());
    localStorage.delayTime =  JSON.stringify(delayTime);
    delay = parseInt(delayTime) + parseInt(inputMs); // setTimeout time
    if(delay < 0) {
        delay = 0;
    }
})

let arrival;
setInterval(function retime() {
	"use strict";
	arrival = document.getElementsByClassName("relative_time")[0].textContent;
	if(arrival.slice(-8) === input) {
		setTimeout(function() {document.getElementById("troop_confirm_go").click();}, delay);
	}
}, 1);