First commit

This commit is contained in:
2025-08-29 13:19:36 +02:00
commit e9cca7ea8b
19 changed files with 275 additions and 0 deletions

113
src/kaplus.js Normal file
View File

@@ -0,0 +1,113 @@
function num(s) {
return parseInt(s.replace(".", ""));
}
function str(n) {
if (n == 0) {
return "0";
}
s = "";
while (n > 0) {
if (s != "") {
s = "." + s;
}
r = n % 1000;
s = r.toString().padStart(3, "0") + s;
n = ~~(n/1000);
}
return s.replace(/^0+/, "");
}
function createRow(key, value) {
keyCell = document.createElement("td");
keyCell.textContent = key;
valueCell = document.createElement("td");
valueCell.textContent = value;
row = document.createElement("tr");
row.appendChild(keyCell);
row.appendChild(valueCell);
return row;
}
function shortcutElementReplace(elt, img, text) {
spanImageElement = document.createElement("span");
spanImageElement.classList.add("shortcut_element_image");
imgElement = document.createElement("img");
imgElement.setAttribute("src", chrome.runtime.getURL("images/"+img+".svg"));
spanImageElement.appendChild(imgElement);
hyperlinkElements = elt.getElementsByTagName("a");
if (hyperlinkElements.length == 2) {
hyperlinkElements[0].remove();
elt.getElementsByTagName("a")[0].classList.add("has_notif");
}
hyperlinkElement = elt.getElementsByTagName("a")[0];
hyperlinkElement.textContent = "";
hyperlinkElement.appendChild(spanImageElement);
if (text) {
spanDescElement = document.createElement("span");
spanDescElement.classList.add("shortcut_element_desc");
spanDescElement.textContent = text;
hyperlinkElement.appendChild(spanDescElement);
}
}
layCastleTopElements = document.getElementsByClassName("lay_castle_top");
if (layCastleTopElements.length == 1) {
shortcutElements = layCastleTopElements[0].getElementsByClassName("shortcut_element");
shortcutElementReplace(shortcutElements[0], "ranking", shortcutElements[0].textContent.replace(/[^0-9]/g, ""));
shortcutElementReplace(shortcutElements[1], "ally", "");
shortcutElementReplace(shortcutElements[2], "profile", "");
shortcutElementReplace(shortcutElements[3], "premium", "");
shortcutElementReplace(shortcutElements[4], "messages", "");
shortcutElementReplace(shortcutElements[5], "tools", "");
shortcutElementReplace(shortcutElements[6], "favorites", "");
}
if (document.body.id === "info_player") {
mainContentPane = document.getElementsByClassName("contentpane")[1];
borderLists = mainContentPane.getElementsByClassName("borderlist");
playerPropertiesTable = borderLists[0];
playerPropertiesRows = playerPropertiesTable.getElementsByTagName("tr");
totalPoints = num(playerPropertiesRows[2].getElementsByTagName("td")[1].textContent);
villagesCount = num(playerPropertiesRows[4].getElementsByTagName("td")[1].textContent);
villagesTable = borderLists[1];
villagesRows = villagesTable.getElementsByTagName("tr");
villagesPoints = 0;
for (i=1; i<villagesRows.length; i+=1) {
villagesPoints += num(villagesRows[i].getElementsByTagName("td")[2].textContent);
}
villagesBonus = 2250 * Math.max(0, villagesCount - 1);
armyPoints = totalPoints - villagesPoints - villagesBonus;
if (villagesCount > 0) {
armyPercent = (Math.round(armyPoints / villagesCount) / 100).toString() + " %";
} else {
armyPercent = "-";
}
playerPropertiesTable.appendChild(createRow("Points troupes:", str(armyPoints)));
playerPropertiesTable.appendChild(createRow("% points troupes:", armyPercent));
}
if (document.body.id === "overview") {
settlements = document.getElementById("settlement").textContent.split("|");
noborderRows = document.getElementsByClassName("noborder");
for (i=0; i<noborderRows.length; i++) {
if (noborderRows[i].textContent.startsWith("Points:")) {
villagePointsRow = noborderRows[i];
break;
}
}
unitPointsRow = villagePointsRow.cloneNode(true);
villagePointsRow.getElementsByTagName("td")[1].textContent = "Points village: " + settlements[3];
unitPointsRow.getElementsByTagName("td")[1].textContent = "Points troupes: " + settlements[4];
villagePointsRow.after(unitPointsRow);
}