|
|
|
|
@@ -1,7 +1,36 @@
|
|
|
|
|
let tomorrow = new Date(new Date().getTime() + 24*60*60*1000);
|
|
|
|
|
tomorrow.setHours(0, 0, 0, 0);
|
|
|
|
|
let afterTomorrow = new Date(tomorrow.getTime() + 24*60*60*1000);
|
|
|
|
|
let movingDuration = 0;
|
|
|
|
|
const AUTHORIZED_ALLIANCES = {
|
|
|
|
|
"s58": ["NAZGUL"]
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const BUILDINGS = {
|
|
|
|
|
"main": "Château",
|
|
|
|
|
"stone": "Carrière",
|
|
|
|
|
"wood": "Scierie",
|
|
|
|
|
"iron": "Mine de minerai",
|
|
|
|
|
"storage": "Entrepôt",
|
|
|
|
|
"hide": "Cachette",
|
|
|
|
|
"farm": "Moulin",
|
|
|
|
|
"barracks": "Caserne",
|
|
|
|
|
"wall": "Remparts",
|
|
|
|
|
"stable": "Élevage d'ânes",
|
|
|
|
|
"snob": "Résidence",
|
|
|
|
|
"smith": "Orfèvrerie",
|
|
|
|
|
"statue": "Mémorial",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const UNITS = {
|
|
|
|
|
"farmer": "Milice de paysans",
|
|
|
|
|
"sword": "Templier",
|
|
|
|
|
"spear": "Écuyer",
|
|
|
|
|
"axe": "Sauvage",
|
|
|
|
|
"bow": "Grand Arc",
|
|
|
|
|
"spy": "Éclaireur",
|
|
|
|
|
"light": "Croisé",
|
|
|
|
|
"heavy": "Chevalier Noir",
|
|
|
|
|
"ram": "Bélier",
|
|
|
|
|
"kata": "Trébuchet",
|
|
|
|
|
"snob": "Comte",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function num(s) {
|
|
|
|
|
return parseInt(s.replace(".", ""));
|
|
|
|
|
@@ -73,6 +102,144 @@ function searchPoint(text) {
|
|
|
|
|
return {x: point[0], y: point[1]}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function selectVillage(selectRef, inputXRef, inputYRef) {
|
|
|
|
|
let select = document.getElementById(selectRef);
|
|
|
|
|
let inputX = document.getElementById(inputXRef);
|
|
|
|
|
let inputY = document.getElementById(inputYRef);
|
|
|
|
|
if (select.selectedIndex === 0) {
|
|
|
|
|
inputX.value = "";
|
|
|
|
|
inputY.value = "";
|
|
|
|
|
} else {
|
|
|
|
|
let xy = select.value.split("|");
|
|
|
|
|
inputX.value = xy[0];
|
|
|
|
|
inputY.value = xy[1];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function storeOrderToken(ownVillages, targetVillage) {
|
|
|
|
|
let orderToken = sessionStorage.getItem("orderToken");
|
|
|
|
|
if (orderToken !== null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let breakLoop = false;
|
|
|
|
|
for (let villageId in ownVillages) {
|
|
|
|
|
if (breakLoop === true) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let xhrOrder = new XMLHttpRequest();
|
|
|
|
|
xhrOrder.addEventListener("readystatechange", function () {
|
|
|
|
|
if (xhrOrder.readyState === xhrOrder.DONE) {
|
|
|
|
|
let parser = new DOMParser();
|
|
|
|
|
let doc = parser.parseFromString(xhrOrder.responseText, "text/html");
|
|
|
|
|
let quantityDivs = doc.getElementsByClassName("quantity");
|
|
|
|
|
let unit = null;
|
|
|
|
|
for (let i = 0; i < quantityDivs.length; i ++) {
|
|
|
|
|
let quantityInput = quantityDivs[i].getElementsByTagName("input")[0];
|
|
|
|
|
let quantityClick = quantityDivs[i].getElementsByClassName("click")[0];
|
|
|
|
|
if (quantityClick.textContent !== "(0)") {
|
|
|
|
|
unit = quantityInput.getAttribute("name");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (unit === null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let xhrSend = new XMLHttpRequest();
|
|
|
|
|
let formData = new FormData();
|
|
|
|
|
formData.set(unit, "1");
|
|
|
|
|
formData.set("send_x", targetVillage.x);
|
|
|
|
|
formData.set("send_y", targetVillage.y);
|
|
|
|
|
formData.set("support", "Envoyer du renfort");
|
|
|
|
|
let formParams = new URLSearchParams(formData);
|
|
|
|
|
xhrSend.addEventListener("readystatechange", function () {
|
|
|
|
|
if (xhrSend.readyState === xhrSend.DONE) {
|
|
|
|
|
let parser = new DOMParser();
|
|
|
|
|
let doc = parser.parseFromString(xhrSend.responseText, "text/html");
|
|
|
|
|
let form = doc.getElementsByTagName("form")[0];
|
|
|
|
|
let action = form.getAttribute("action");
|
|
|
|
|
let orderToken = action.replace(/^.*p=([a-z0-9]+).*$/, "$1");
|
|
|
|
|
sessionStorage.setItem("orderToken", orderToken);
|
|
|
|
|
breakLoop = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
xhrSend.open("POST", "/?village=" + villageId + "&s=build_barracks&m=command&sub=send");
|
|
|
|
|
xhrSend.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
|
|
|
xhrSend.send(formParams.toString());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
xhrOrder.open("GET", "/?village=" + villageId + "&s=build_barracks");
|
|
|
|
|
xhrOrder.send();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function storeTargetVillage(ownVillages) {
|
|
|
|
|
let targetVillage = sessionStorage.getItem("targetVillage");
|
|
|
|
|
if (targetVillage !== null) {
|
|
|
|
|
storeOrderToken(ownVillages, JSON.parse(targetVillage));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let xhr = new XMLHttpRequest();
|
|
|
|
|
targetVillage = {};
|
|
|
|
|
xhr.addEventListener("readystatechange", function () {
|
|
|
|
|
if (xhr.readyState === xhr.DONE) {
|
|
|
|
|
let parser = new DOMParser();
|
|
|
|
|
let doc = parser.parseFromString(xhr.responseText, "text/html");
|
|
|
|
|
let cells = doc.getElementsByClassName("occupied range");
|
|
|
|
|
for (let i = 0; i < cells.length; i ++) {
|
|
|
|
|
let links = cells[i].getElementsByTagName("a");
|
|
|
|
|
if (links.length === 0) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
let villageId = links[0].getAttribute("href").replace(/^.*id=(\d{4}).*$/, "$1");
|
|
|
|
|
if (villageId in ownVillages) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
let villageXY = links[0].getAttribute("onmouseover").replace(/^.*(\d{3}\|\d{3}).*$/, "$1").split("|");
|
|
|
|
|
targetVillage = {x: parseInt(villageXY[0]), y: parseInt(villageXY[1])};
|
|
|
|
|
sessionStorage.setItem("targetVillage", JSON.stringify(targetVillage));
|
|
|
|
|
storeOrderToken(ownVillages, targetVillage);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
xhr.open("GET", "/?s=map");
|
|
|
|
|
xhr.send();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function storeOwnVillages() {
|
|
|
|
|
let ownVillages = sessionStorage.getItem("ownVillages");
|
|
|
|
|
if (ownVillages !== null) {
|
|
|
|
|
storeTargetVillage(JSON.parse(ownVillages));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let xhr = new XMLHttpRequest();
|
|
|
|
|
xhr.addEventListener("readystatechange", function () {
|
|
|
|
|
if (xhr.readyState === xhr.DONE) {
|
|
|
|
|
let parser = new DOMParser();
|
|
|
|
|
let doc = parser.parseFromString(xhr.responseText, "text/html");
|
|
|
|
|
let mainContentPane = doc.getElementsByClassName("contentpane")[1];
|
|
|
|
|
let table = mainContentPane.getElementsByClassName("borderlist")[1];
|
|
|
|
|
let rows = table.getElementsByTagName("tr");
|
|
|
|
|
let ownVillages = {};
|
|
|
|
|
for (let i = 1; i < rows.length; i ++) {
|
|
|
|
|
let cells = rows[i].getElementsByTagName("td");
|
|
|
|
|
let link = cells[0].getElementsByTagName("a")[0];
|
|
|
|
|
let villageId = link.getAttribute("href").replace(/^.*id=(\d{4}).*$/, "$1");
|
|
|
|
|
let villageXY = cells[1].textContent.split("|");
|
|
|
|
|
ownVillages[villageId] = {x: parseInt(villageXY[0]), y: parseInt(villageXY[1]), name: link.textContent};
|
|
|
|
|
}
|
|
|
|
|
sessionStorage.setItem("ownVillages", JSON.stringify(ownVillages));
|
|
|
|
|
storeTargetVillage(ownVillages);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
xhr.open("GET", "/?s=info_player");
|
|
|
|
|
xhr.send();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function shortcutElementReplace(elt, img, text) {
|
|
|
|
|
// If more than one hyperlink element found,
|
|
|
|
|
// then keep the last one but with href of the first one.
|
|
|
|
|
@@ -119,10 +286,10 @@ function customizeNavbar(layCastleElement) {
|
|
|
|
|
shortcutContainers[2].classList.add("shortcut_container_right");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function countUpMs() {
|
|
|
|
|
function countUpMs(tomorrow, after_tomorrow, movingDuration) {
|
|
|
|
|
let arrivalDate = new Date(new Date().getTime() + movingDuration * 1000);
|
|
|
|
|
let prefix = "";
|
|
|
|
|
if (arrivalDate >= afterTomorrow) {
|
|
|
|
|
if (arrivalDate >= after_tomorrow) {
|
|
|
|
|
prefix = "le " + arrivalDate.getDate() + "." + arrivalDate.getMonth() + " ";
|
|
|
|
|
} else if (arrivalDate > tomorrow) {
|
|
|
|
|
prefix = "demain ";
|
|
|
|
|
@@ -138,6 +305,34 @@ function countUpMs() {
|
|
|
|
|
+ Math.floor(arrivalDate.getMilliseconds() / 100);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function countdownMS(formattedDate) {
|
|
|
|
|
let now = new Date();
|
|
|
|
|
if (formattedDate.startsWith("à")) {
|
|
|
|
|
let start = new Date();
|
|
|
|
|
let hms = formattedDate.replace(/^à (\d\d:\d\d:\d\d) heures$/, "$1").split(":");
|
|
|
|
|
start.setHours(parseInt(hms[0]));
|
|
|
|
|
start.setMinutes(parseInt(hms[1]));
|
|
|
|
|
start.setSeconds(parseInt(hms[2]));
|
|
|
|
|
return start.getTime() - now.getTime();
|
|
|
|
|
}
|
|
|
|
|
if (formattedDate.startsWith("demain")) {
|
|
|
|
|
let start = new Date(now.getTime() + 24*60*60*1000);
|
|
|
|
|
let hms = formattedDate.replace(/^demain à (\d\d:\d\d:\d\d) heures$/, "$1").split(":");
|
|
|
|
|
start.setHours(parseInt(hms[0]));
|
|
|
|
|
start.setMinutes(parseInt(hms[1]));
|
|
|
|
|
start.setSeconds(parseInt(hms[2]));
|
|
|
|
|
return start.getTime() - now.getTime();
|
|
|
|
|
}
|
|
|
|
|
let start = new Date();
|
|
|
|
|
let hms = formattedDate.replace(/^le (\d\d)\.(\d\d) à (\d\d:\d\d:\d\d) heures$/, "$1:$2:$3");
|
|
|
|
|
start.setDate(parseInt(hms[0]));
|
|
|
|
|
start.setMonth(parseInt(hms[1]));
|
|
|
|
|
start.setHours(parseInt(hms[0]));
|
|
|
|
|
start.setMinutes(parseInt(hms[1]));
|
|
|
|
|
start.setSeconds(parseInt(hms[2]));
|
|
|
|
|
return start.getTime() - now.getTime();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function removeAdsBanner() {
|
|
|
|
|
/* Remove iframe banner */
|
|
|
|
|
document.getElementById("banner_skyscraper").remove();
|
|
|
|
|
@@ -207,6 +402,346 @@ function showPlayerUnitPointsAndId() {
|
|
|
|
|
playerPropertiesTbody.insertBefore(createKeyValueRow("Id:", playerId), playerPropertiesRows[2]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showAutoPlanerMenu(village, module) {
|
|
|
|
|
let mainContentPane = document.getElementsByClassName("contentpane")[1];
|
|
|
|
|
let navTable = mainContentPane.getElementsByTagName("table")[0];
|
|
|
|
|
let navRow = navTable.getElementsByTagName("tr")[0];
|
|
|
|
|
let navCells = navRow.getElementsByTagName("td");
|
|
|
|
|
let separatorCell = createCustomElement("td");
|
|
|
|
|
let separatorImg = createCustomElement("img");
|
|
|
|
|
separatorCell.appendChild(separatorImg);
|
|
|
|
|
let autonomousCell = createCustomElement("td");
|
|
|
|
|
let autonomousLink = createCustomElement(
|
|
|
|
|
"a", {"href": "/?village=" + village + "&s=tools&m=auto_planer"}, "Planificateur autonome d'attaques"
|
|
|
|
|
);
|
|
|
|
|
let rightImg = navCells[6].getElementsByTagName("img")[0];
|
|
|
|
|
switch (module) {
|
|
|
|
|
case "runtime_calculator":
|
|
|
|
|
separatorImg.setAttribute("src", "/img/tabs/menue_sn_center.png");
|
|
|
|
|
autonomousCell.setAttribute("background", "/img/tabs/menue_n_back.png");
|
|
|
|
|
rightImg.setAttribute("src", "/img/tabs/menue_n_right.png");
|
|
|
|
|
break;
|
|
|
|
|
case "auto_planer":
|
|
|
|
|
separatorImg.setAttribute("src", "/img/tabs/menue_ns_center.png");
|
|
|
|
|
autonomousCell.setAttribute("background", "/img/tabs/menue_s_back.png");
|
|
|
|
|
rightImg.setAttribute("src", "/img/tabs/menue_s_right.png");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
separatorImg.setAttribute("src", "/img/tabs/menue_nn_center.png");
|
|
|
|
|
autonomousCell.setAttribute("background", "/img/tabs/menue_n_back.png");
|
|
|
|
|
rightImg.setAttribute("src", "/img/tabs/menue_n_right.png");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
autonomousCell.appendChild(autonomousLink);
|
|
|
|
|
navRow.insertBefore(autonomousCell, navCells[6]);
|
|
|
|
|
navRow.insertBefore(separatorCell, navCells[6]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showAutoPlanerPage(village) {
|
|
|
|
|
let mainContentPane = document.getElementsByClassName("contentpane")[1];
|
|
|
|
|
for (let i = mainContentPane.childNodes.length - 1; i >= 5; i --) {
|
|
|
|
|
mainContentPane.childNodes[i].remove();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let autoPlanerForm = createCustomElement("form", {"name": "kingsage"});
|
|
|
|
|
let borderList = createCustomElement("table", {"class": "borderlist", "width": "820"});
|
|
|
|
|
let titleRow = createCustomElement("tr");
|
|
|
|
|
let titleCell = createCustomElement("th", {"colspan": "7"}, "Nouvel ordre autonome");
|
|
|
|
|
titleRow.appendChild(titleCell);
|
|
|
|
|
borderList.appendChild(titleRow);
|
|
|
|
|
|
|
|
|
|
let startRow = createCustomElement("tr");
|
|
|
|
|
startRow.appendChild(createCustomElement("td", null, "Village originel:"));
|
|
|
|
|
startRow.appendChild(createCustomElement("td", null, "x:"));
|
|
|
|
|
let startXCell = createCustomElement("td");
|
|
|
|
|
let startXInput = createCustomInput(
|
|
|
|
|
"number",
|
|
|
|
|
"start_x",
|
|
|
|
|
null,
|
|
|
|
|
{"id": "start_x", "required": "required", "min": "1", "max": "999"},
|
|
|
|
|
{"width": "50px"},
|
|
|
|
|
);
|
|
|
|
|
startXCell.appendChild(startXInput);
|
|
|
|
|
startRow.appendChild(startXCell);
|
|
|
|
|
startRow.appendChild(createCustomElement("td", null, "y:"));
|
|
|
|
|
let startYCell = createCustomElement("td");
|
|
|
|
|
let startYInput = createCustomInput(
|
|
|
|
|
"number",
|
|
|
|
|
"start_y",
|
|
|
|
|
null,
|
|
|
|
|
{"id": "start_y", "required": "required", "min": "1", "max": "999"},
|
|
|
|
|
{"width": "50px"},
|
|
|
|
|
);
|
|
|
|
|
startYCell.appendChild(startYInput);
|
|
|
|
|
startRow.appendChild(startYCell);
|
|
|
|
|
let startClickCell = createCustomElement("td");
|
|
|
|
|
let startClickSpan = createCustomElement(
|
|
|
|
|
"span",
|
|
|
|
|
{
|
|
|
|
|
"class": "click",
|
|
|
|
|
"onclick": "popup_mod('popup.php?s=targets&m=own_villages&build=attack_planer', 690, 400);return false;",
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
let startClickImg = createCustomElement("img", {"src": "/img/arrow_right_raquo.png"});
|
|
|
|
|
let startClickText = document.createTextNode(" Propre");
|
|
|
|
|
startClickSpan.appendChild(startClickImg);
|
|
|
|
|
startClickSpan.appendChild(startClickText);
|
|
|
|
|
startClickCell.appendChild(startClickSpan);
|
|
|
|
|
startRow.appendChild(startClickCell);
|
|
|
|
|
let startSelectCell = createCustomElement("td");
|
|
|
|
|
let startSelect = createCustomElement("select", {"id": "ownlist"}, null, {"width": "300px"});
|
|
|
|
|
startSelect.addEventListener("change", function () { selectVillage("ownlist", "start_x", "start_y") });
|
|
|
|
|
startSelect.appendChild(createCustomElement("option", {"value": ""}, "Sélectionner village"));
|
|
|
|
|
startSelectCell.appendChild(startSelect);
|
|
|
|
|
startRow.appendChild(startSelectCell);
|
|
|
|
|
borderList.appendChild(startRow);
|
|
|
|
|
let startIntervalId = setInterval(function () {
|
|
|
|
|
let ownVillages = sessionStorage.getItem("ownVillages");
|
|
|
|
|
if (ownVillages === null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ownVillages = JSON.parse(ownVillages);
|
|
|
|
|
for (let ownVillageId in ownVillages) {
|
|
|
|
|
let ownVillage = ownVillages[ownVillageId];
|
|
|
|
|
let startValue = ownVillage.x.toString() + "|" + ownVillage.y.toString()
|
|
|
|
|
let startOption = createCustomElement(
|
|
|
|
|
"option", {"value": startValue}, ownVillage.name + " (" + startValue + ")",
|
|
|
|
|
);
|
|
|
|
|
startSelect.appendChild(startOption);
|
|
|
|
|
if (ownVillageId === village) {
|
|
|
|
|
startXInput.value = ownVillage.x;
|
|
|
|
|
startYInput.value = ownVillage.y;
|
|
|
|
|
startSelect.value = startValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
clearInterval(startIntervalId);
|
|
|
|
|
}, 500);
|
|
|
|
|
|
|
|
|
|
let targetRow = createCustomElement("tr");
|
|
|
|
|
targetRow.appendChild(createCustomElement("td", null, "Village cible:"));
|
|
|
|
|
targetRow.appendChild(createCustomElement("td", null, "x:"));
|
|
|
|
|
let targetXCell = createCustomElement("td");
|
|
|
|
|
let targetXInput = createCustomInput(
|
|
|
|
|
"number",
|
|
|
|
|
"target_x",
|
|
|
|
|
null,
|
|
|
|
|
{"id": "target_x", "required": "required", "min": "1", "max": "999"},
|
|
|
|
|
{"width": "50px"},
|
|
|
|
|
);
|
|
|
|
|
targetXCell.appendChild(targetXInput);
|
|
|
|
|
targetRow.appendChild(targetXCell);
|
|
|
|
|
targetRow.appendChild(createCustomElement("td", null, "y:"));
|
|
|
|
|
let targetYCell = createCustomElement("td");
|
|
|
|
|
let targetYInput = createCustomInput(
|
|
|
|
|
"number",
|
|
|
|
|
"target_y",
|
|
|
|
|
null,
|
|
|
|
|
{"id": "target_y", "required": "required", "min": "1", "max": "999"},
|
|
|
|
|
{"width": "50px"},
|
|
|
|
|
);
|
|
|
|
|
targetYCell.appendChild(targetYInput);
|
|
|
|
|
targetRow.appendChild(targetYCell);
|
|
|
|
|
let targetClickCell = createCustomElement("td", {"colspan": "2"});
|
|
|
|
|
let targetClickSpan = createCustomElement(
|
|
|
|
|
"span",
|
|
|
|
|
{
|
|
|
|
|
"class": "click",
|
|
|
|
|
"onclick": "popup_mod('popup.php?s=targets&m=favorites&build=attack_planer', 690, 400);return false;",
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
let targetClickImg = createCustomElement("img", {"src": "/img/arrow_right_raquo.png"});
|
|
|
|
|
let targetClickText = document.createTextNode(" Favoris");
|
|
|
|
|
targetClickSpan.appendChild(targetClickImg);
|
|
|
|
|
targetClickSpan.appendChild(targetClickText);
|
|
|
|
|
targetClickCell.appendChild(targetClickSpan);
|
|
|
|
|
targetRow.appendChild(targetClickCell);
|
|
|
|
|
borderList.appendChild(targetRow);
|
|
|
|
|
|
|
|
|
|
let dateRow = createCustomElement("tr");
|
|
|
|
|
dateRow.appendChild(createCustomElement("td", null, "Arrivée:"));
|
|
|
|
|
let dateCell = createCustomElement("td", {"colspan": "6"});
|
|
|
|
|
let now = new Date();
|
|
|
|
|
dateCell.appendChild(createCustomInput(
|
|
|
|
|
"number",
|
|
|
|
|
"day",
|
|
|
|
|
now.getDate().toString(),
|
|
|
|
|
{"required": "required", "min": "1", "max": "31"},
|
|
|
|
|
{"width": "40px"},
|
|
|
|
|
));
|
|
|
|
|
dateCell.appendChild(document.createTextNode(". "))
|
|
|
|
|
dateCell.appendChild(createCustomInput(
|
|
|
|
|
"number",
|
|
|
|
|
"month",
|
|
|
|
|
now.getMonth().toString(),
|
|
|
|
|
{"required": "required", "min": "1", "max": "12"},
|
|
|
|
|
{"width": "40px"},
|
|
|
|
|
));
|
|
|
|
|
dateCell.appendChild(document.createTextNode(". "))
|
|
|
|
|
dateCell.appendChild(createCustomInput(
|
|
|
|
|
"number",
|
|
|
|
|
"year",
|
|
|
|
|
now.getFullYear().toString(),
|
|
|
|
|
{"required": "required", "min": "2025"},
|
|
|
|
|
{"width": "50px"},
|
|
|
|
|
));
|
|
|
|
|
dateCell.appendChild(document.createTextNode(" - "))
|
|
|
|
|
dateCell.appendChild(createCustomInput(
|
|
|
|
|
"number",
|
|
|
|
|
"hour",
|
|
|
|
|
now.getHours().toString(),
|
|
|
|
|
{"required": "required", "min": "0", "max": "23"},
|
|
|
|
|
{"width": "40px"},
|
|
|
|
|
));
|
|
|
|
|
dateCell.appendChild(document.createTextNode(": "))
|
|
|
|
|
dateCell.appendChild(createCustomInput(
|
|
|
|
|
"number",
|
|
|
|
|
"minute",
|
|
|
|
|
now.getMinutes().toString(),
|
|
|
|
|
{"required": "required", "min": "0", "max": "59"},
|
|
|
|
|
{"width": "40px"},
|
|
|
|
|
));
|
|
|
|
|
dateCell.appendChild(document.createTextNode(": "))
|
|
|
|
|
dateCell.appendChild(createCustomInput(
|
|
|
|
|
"number",
|
|
|
|
|
"second",
|
|
|
|
|
now.getSeconds().toString(),
|
|
|
|
|
{"required": "required", "min": "0", "max": "59"},
|
|
|
|
|
{"width": "40px"},
|
|
|
|
|
));
|
|
|
|
|
dateCell.appendChild(document.createTextNode(". "))
|
|
|
|
|
dateCell.appendChild(createCustomInput(
|
|
|
|
|
"number",
|
|
|
|
|
"tenth",
|
|
|
|
|
Math.floor(now.getMilliseconds()/100).toString(),
|
|
|
|
|
{"required": "required", "min": "0", "max": "9"},
|
|
|
|
|
{"width": "40px"},
|
|
|
|
|
));
|
|
|
|
|
dateRow.appendChild(dateCell);
|
|
|
|
|
borderList.appendChild(dateRow);
|
|
|
|
|
|
|
|
|
|
let unitBorderList = createCustomElement("table", {"class": "borderlist"});
|
|
|
|
|
let unitTitleRow = createCustomElement("tr");
|
|
|
|
|
for (let unit in UNITS) {
|
|
|
|
|
let unitTitleCell = createCustomElement("th", null, null, {"text-align": "center"});
|
|
|
|
|
let unitTitleImg = createCustomElement(
|
|
|
|
|
"img", {"src": "/img/units/unit_"+unit+".png", "alt": UNITS[unit], "title": UNITS[unit]}
|
|
|
|
|
);
|
|
|
|
|
unitTitleCell.appendChild(unitTitleImg);
|
|
|
|
|
unitTitleRow.appendChild(unitTitleCell);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unitBorderList.appendChild(unitTitleRow);
|
|
|
|
|
let unitInputRow = createCustomElement("tr");
|
|
|
|
|
for (let unit in UNITS) {
|
|
|
|
|
let unitInputCell = createCustomElement("td");
|
|
|
|
|
let unitInput = createCustomInput("number", unit, null, {"min": "0"}, {"width": "61px"});
|
|
|
|
|
switch (unit) {
|
|
|
|
|
case "spy": case "light": case "heavy": case "ram": case "snob":
|
|
|
|
|
unitInput.style.width = "62px";
|
|
|
|
|
break;
|
|
|
|
|
case "kata":
|
|
|
|
|
unitInput.addEventListener("change", function () {
|
|
|
|
|
if (autoPlanerForm.kata.value !== "0" && autoPlanerForm.genre.value === "attack") {
|
|
|
|
|
autoPlanerForm.building.removeAttribute("disabled");
|
|
|
|
|
} else {
|
|
|
|
|
autoPlanerForm.building.setAttribute("disabled", "disabled");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
unitInputCell.appendChild(unitInput);
|
|
|
|
|
unitInputRow.appendChild(unitInputCell);
|
|
|
|
|
}
|
|
|
|
|
unitBorderList.appendChild(unitInputRow);
|
|
|
|
|
|
|
|
|
|
let additionalBorderList = createCustomElement("table", {"class": "borderlist", "width": "820"});
|
|
|
|
|
let additionalTitleRow = createCustomElement("tr");
|
|
|
|
|
additionalTitleRow.appendChild(createCustomElement("th", {"colspan": "7"}, "Données additionnelles"));
|
|
|
|
|
additionalBorderList.appendChild(additionalTitleRow);
|
|
|
|
|
|
|
|
|
|
let labelRow = createCustomElement("tr");
|
|
|
|
|
labelRow.appendChild(createCustomElement("td", null, "Étiquette:"));
|
|
|
|
|
let labelCell = createCustomElement("td", {"colspan": "6"});
|
|
|
|
|
let labelInput = createCustomInput(
|
|
|
|
|
"text", "label", null, {"maxlength": "10"}, {"width": "100px"}
|
|
|
|
|
);
|
|
|
|
|
labelCell.appendChild(labelInput);
|
|
|
|
|
labelRow.appendChild(labelCell);
|
|
|
|
|
additionalBorderList.appendChild(labelRow);
|
|
|
|
|
|
|
|
|
|
let occurrencesRow = createCustomElement("tr");
|
|
|
|
|
occurrencesRow.appendChild(createCustomElement("td", null, "Occurrences:"));
|
|
|
|
|
let occurrencesCell = createCustomElement("td", {"colspan": "6"});
|
|
|
|
|
let occurrencesInput = createCustomInput(
|
|
|
|
|
"number", "occurrences", "1", {"required": "required", "min": "1"}, {"width": "50px"}
|
|
|
|
|
);
|
|
|
|
|
occurrencesCell.appendChild(occurrencesInput);
|
|
|
|
|
occurrencesRow.appendChild(occurrencesCell);
|
|
|
|
|
additionalBorderList.appendChild(occurrencesRow);
|
|
|
|
|
|
|
|
|
|
let genreRow = createCustomElement("tr");
|
|
|
|
|
genreRow.appendChild(createCustomElement("td", null, "Type:"));
|
|
|
|
|
let genreCell = createCustomElement("td", {"colspan": "6"});
|
|
|
|
|
let genreSelect = createCustomElement(
|
|
|
|
|
"select", {"name": "genre", "value": "attack"}, {"required": "required"}, {"width": "200px"}
|
|
|
|
|
);
|
|
|
|
|
genreSelect.appendChild(createCustomElement("option", {"value": "attack"}, "Attaque"));
|
|
|
|
|
genreSelect.appendChild(createCustomElement("option", {"value": "support"}, "Renfort"));
|
|
|
|
|
genreSelect.appendChild(createCustomElement("option", {"value": "spy"}, "Espionnage"));
|
|
|
|
|
genreSelect.addEventListener("change", function () {
|
|
|
|
|
if (autoPlanerForm.kata.value !== "0" && autoPlanerForm.genre.value === "attack") {
|
|
|
|
|
autoPlanerForm.building.removeAttribute("disabled");
|
|
|
|
|
} else {
|
|
|
|
|
autoPlanerForm.building.setAttribute("disabled", "disabled");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
genreCell.appendChild(genreSelect);
|
|
|
|
|
genreRow.appendChild(genreCell);
|
|
|
|
|
additionalBorderList.appendChild(genreRow);
|
|
|
|
|
|
|
|
|
|
let buildingRow = createCustomElement("tr");
|
|
|
|
|
buildingRow.appendChild(createCustomElement("td", null, "Bâtiment visé:"));
|
|
|
|
|
let buildingCell = createCustomElement("td", {"colspan": "6"});
|
|
|
|
|
let buildingSelect = createCustomElement(
|
|
|
|
|
"select", {"name": "building", "disabled": "disabled"}, null, {"width": "200px"}
|
|
|
|
|
);
|
|
|
|
|
buildingSelect.appendChild(createCustomElement("option", null, "Sélectionner bâtiment"));
|
|
|
|
|
for (let building in BUILDINGS) {
|
|
|
|
|
buildingSelect.appendChild(createCustomElement("option", {"value": building}, BUILDINGS[building]));
|
|
|
|
|
}
|
|
|
|
|
buildingCell.appendChild(buildingSelect);
|
|
|
|
|
buildingRow.appendChild(buildingCell);
|
|
|
|
|
additionalBorderList.appendChild(buildingRow);
|
|
|
|
|
|
|
|
|
|
autoPlanerForm.addEventListener("submit", function (event) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
let formData = new FormData(this);
|
|
|
|
|
let autoPlanedAttacks = localStorage.getItem("autoPlanedAttacks");
|
|
|
|
|
if (autoPlanedAttacks === null) {
|
|
|
|
|
autoPlanedAttacks = [];
|
|
|
|
|
} else {
|
|
|
|
|
autoPlanedAttacks = JSON.parse(autoPlanedAttacks);
|
|
|
|
|
}
|
|
|
|
|
autoPlanedAttacks.push(Object.fromEntries(formData));
|
|
|
|
|
localStorage.setItem("autoPlanedAttacks", JSON.stringify(autoPlanedAttacks));
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
autoPlanerForm.appendChild(borderList);
|
|
|
|
|
autoPlanerForm.appendChild(createCustomElement("br"));
|
|
|
|
|
autoPlanerForm.appendChild(unitBorderList);
|
|
|
|
|
autoPlanerForm.appendChild(createCustomElement("br"));
|
|
|
|
|
autoPlanerForm.appendChild(additionalBorderList);
|
|
|
|
|
autoPlanerForm.appendChild(createCustomElement("br"));
|
|
|
|
|
autoPlanerForm.appendChild(createCustomInput(
|
|
|
|
|
"submit",
|
|
|
|
|
null,
|
|
|
|
|
"> Ajouter une nouvelle entrée",
|
|
|
|
|
null,
|
|
|
|
|
{"font-weight": "bold", "padding": "5px 20px", "cursor": "pointer"}
|
|
|
|
|
));
|
|
|
|
|
mainContentPane.appendChild(autoPlanerForm);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showVillageUnitPoints() {
|
|
|
|
|
let settlementElt = document.getElementById("settlement");
|
|
|
|
|
if (settlementElt === null) {
|
|
|
|
|
@@ -339,9 +874,13 @@ function showBarrackSelectAllUnits() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showCountupTimeDecimals() {
|
|
|
|
|
let tomorrow = new Date(new Date().getTime() + 24*60*60*1000);
|
|
|
|
|
tomorrow.setHours(0, 0, 0, 0);
|
|
|
|
|
let after_tomorrow = new Date(tomorrow.getTime() + 24*60*60*1000);
|
|
|
|
|
|
|
|
|
|
let oldCell = document.getElementById("countup-time");
|
|
|
|
|
let hms = oldCell.parentElement.previousElementSibling.getElementsByTagName("td")[1].textContent.split(":");
|
|
|
|
|
movingDuration = parseInt(hms[0]) * 3600 + parseInt(hms[1]) * 60 + parseInt(hms[2]) ;
|
|
|
|
|
let movingDuration = parseInt(hms[0]) * 3600 + parseInt(hms[1]) * 60 + parseInt(hms[2]) ;
|
|
|
|
|
let newRow = createCustomElement("tr");
|
|
|
|
|
let newLeftCell = createCustomElement("td", null, "Arrivée:");
|
|
|
|
|
newRow.appendChild(newLeftCell);
|
|
|
|
|
@@ -349,7 +888,7 @@ function showCountupTimeDecimals() {
|
|
|
|
|
newRow.appendChild(newRightCell);
|
|
|
|
|
oldCell.parentElement.parentElement.insertBefore(newRow, oldCell.parentElement);
|
|
|
|
|
oldCell.parentElement.style.display = "none";
|
|
|
|
|
setInterval(countUpMs, 100);
|
|
|
|
|
setInterval(countUpMs, 100, tomorrow, after_tomorrow, movingDuration);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showOccurrencesInput() {
|
|
|
|
|
@@ -384,26 +923,20 @@ function showOccurrencesInput() {
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
xhr.open(this.method, this.action, true);
|
|
|
|
|
xhr.send(formData);
|
|
|
|
|
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
|
|
|
let formParams = new URLSearchParams(formData);
|
|
|
|
|
xhr.send(formParams.toString());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function fixSelectVillageBug() {
|
|
|
|
|
let select = document.getElementsByName("village_name")[0];
|
|
|
|
|
select.removeAttribute("onchange");
|
|
|
|
|
select.addEventListener("change", function () {
|
|
|
|
|
let sendX = document.getElementById("send_x");
|
|
|
|
|
let sendY = document.getElementById("send_y");
|
|
|
|
|
if (this.selectedIndex === 0) {
|
|
|
|
|
sendX.value = "";
|
|
|
|
|
sendY.value = "";
|
|
|
|
|
} else {
|
|
|
|
|
let xy = this.value.split("|");
|
|
|
|
|
sendX.value = xy[0];
|
|
|
|
|
sendY.value = xy[1];
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
let selects = document.getElementsByName("village_name");
|
|
|
|
|
if (selects.length === 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
selects[0].removeAttribute("onchange");
|
|
|
|
|
selects[0].addEventListener("change", function () { selectVillage("TODO", "send_x", "send_y") });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showThousandInputs() {
|
|
|
|
|
@@ -463,10 +996,16 @@ function showSecondsAndCalculator() {
|
|
|
|
|
let table = contentPane.getElementsByClassName("borderlist")[0];
|
|
|
|
|
let rows = table.getElementsByTagName("tr");
|
|
|
|
|
|
|
|
|
|
let headCell = createCustomElement("th");
|
|
|
|
|
rows[0].appendChild(headCell);
|
|
|
|
|
let titleRowIndex = 0;
|
|
|
|
|
if (rows[titleRowIndex].getElementsByTagName("th").length === 0) {
|
|
|
|
|
titleRowIndex = 1;
|
|
|
|
|
}
|
|
|
|
|
console.log(titleRowIndex)
|
|
|
|
|
|
|
|
|
|
for (let i = 1; i < rows.length; i ++) {
|
|
|
|
|
let headCell = createCustomElement("th", null, "Calcul", {"width": "45px"});
|
|
|
|
|
rows[titleRowIndex].appendChild(headCell);
|
|
|
|
|
|
|
|
|
|
for (let i = titleRowIndex + 1; i < rows.length; i ++) {
|
|
|
|
|
let cells = rows[i].getElementsByTagName("td");
|
|
|
|
|
let arrivalDateCell = cells[3]
|
|
|
|
|
let arrivalTimeCell = cells[4];
|
|
|
|
|
@@ -480,7 +1019,16 @@ function showSecondsAndCalculator() {
|
|
|
|
|
let targetPoint = searchPoint(cells[1].textContent);
|
|
|
|
|
let calculatorCell = createCustomElement("td");
|
|
|
|
|
let calculatorForm = createCustomElement(
|
|
|
|
|
"form", {"method": "post", "action": "/?s=tools&m=runtime_calculator&inta=calculate"}
|
|
|
|
|
"form",
|
|
|
|
|
{
|
|
|
|
|
"method": "post",
|
|
|
|
|
"action": "/?s=tools&m=runtime_calculator&inta=calculate",
|
|
|
|
|
"title": "Calculateur de trajet",
|
|
|
|
|
},
|
|
|
|
|
null,
|
|
|
|
|
{
|
|
|
|
|
"display": "inline-block",
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
calculatorForm.appendChild(createCustomInput("hidden", "start_x", startPoint.x));
|
|
|
|
|
calculatorForm.appendChild(createCustomInput("hidden", "start_y", startPoint.y));
|
|
|
|
|
@@ -495,6 +1043,14 @@ function showSecondsAndCalculator() {
|
|
|
|
|
);
|
|
|
|
|
calculatorForm.appendChild(calculatorImg);
|
|
|
|
|
calculatorCell.appendChild(calculatorForm);
|
|
|
|
|
|
|
|
|
|
let calculatorFormBlank = calculatorForm.cloneNode(true);
|
|
|
|
|
calculatorFormBlank.setAttribute("target", "_blank");
|
|
|
|
|
calculatorFormBlank.setAttribute("title", "Calculateur de trajet dans nouvel onglet");
|
|
|
|
|
let calculatorBlankImg = calculatorFormBlank.getElementsByTagName("input")[4]
|
|
|
|
|
calculatorBlankImg.setAttribute("src", chrome.runtime.getURL("images/blank.svg"));
|
|
|
|
|
calculatorCell.appendChild(calculatorFormBlank);
|
|
|
|
|
|
|
|
|
|
rows[i].appendChild(calculatorCell);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -506,6 +1062,24 @@ function main() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Exit immediately if not authorized */
|
|
|
|
|
let xhrAlly = new XMLHttpRequest();
|
|
|
|
|
let serverID = window.location.hostname.replace(/^(s\d+)-.*$/, "$1");
|
|
|
|
|
if (serverID in AUTHORIZED_ALLIANCES) {
|
|
|
|
|
xhrAlly.addEventListener("readystatechange", function () {
|
|
|
|
|
if (xhrAlly.readyState === xhrAlly.DONE) {
|
|
|
|
|
let parser = new DOMParser();
|
|
|
|
|
let doc = parser.parseFromString(xhrAlly.responseText, "text/html");
|
|
|
|
|
let h1 = doc.getElementsByTagName("h1")[0];
|
|
|
|
|
if (!AUTHORIZED_ALLIANCES[serverID].includes(h1.textContent)) {
|
|
|
|
|
window.location.replace("about:blank");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
xhrAlly.open("GET", "/?s=ally");
|
|
|
|
|
xhrAlly.send();
|
|
|
|
|
|
|
|
|
|
/* Exit immediately if extension has already been loaded */
|
|
|
|
|
let kaplus = document.getElementById("kaplus-marker");
|
|
|
|
|
if (kaplus) {
|
|
|
|
|
@@ -521,11 +1095,14 @@ function main() {
|
|
|
|
|
/* Customize navbar */
|
|
|
|
|
customizeNavbar(layCastleTopElements[0]); // test: OK
|
|
|
|
|
|
|
|
|
|
/* Store session storage values */
|
|
|
|
|
storeOwnVillages();
|
|
|
|
|
|
|
|
|
|
/* Parse url params and switch case */
|
|
|
|
|
let urlParams = new URLSearchParams(window.location.search);
|
|
|
|
|
let section = urlParams.get("s");
|
|
|
|
|
let module = urlParams.get("m");
|
|
|
|
|
let sub = urlParams.get("sub");
|
|
|
|
|
let village = urlParams.get("village");
|
|
|
|
|
|
|
|
|
|
/* Choose action according to section, module and sub */
|
|
|
|
|
switch (section) {
|
|
|
|
|
@@ -548,6 +1125,15 @@ function main() {
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "tools":
|
|
|
|
|
showAutoPlanerMenu(village, module);
|
|
|
|
|
switch (module) {
|
|
|
|
|
case "auto_planer":
|
|
|
|
|
showAutoPlanerPage(village);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "overview":
|
|
|
|
|
showVillageUnitPoints(); // test: FAILED because settlement element has been removed
|
|
|
|
|
break;
|
|
|
|
|
@@ -555,14 +1141,12 @@ function main() {
|
|
|
|
|
case "build_barracks":
|
|
|
|
|
switch (module) {
|
|
|
|
|
case "command": case null:
|
|
|
|
|
switch (sub) {
|
|
|
|
|
case null:
|
|
|
|
|
showBarrackSelectAllUnits(); // test: OK
|
|
|
|
|
break;
|
|
|
|
|
case "send":
|
|
|
|
|
showCountupTimeDecimals(); // test: OK
|
|
|
|
|
showOccurrencesInput(); // test: OK
|
|
|
|
|
break;
|
|
|
|
|
let sendCommandForm = document.getElementById("sendCommandForm");
|
|
|
|
|
if (sendCommandForm !== null) {
|
|
|
|
|
showBarrackSelectAllUnits(); // test: OK
|
|
|
|
|
} else {
|
|
|
|
|
showCountupTimeDecimals(); // test: OK
|
|
|
|
|
showOccurrencesInput(); // test: OK
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|