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

77
src/kaplus.css Normal file
View File

@@ -0,0 +1,77 @@
#banner_container {
display: none;
}
#content_wrapper > table {
width: auto !important;
}
.lay_castle_top {
.shortcut-element {
top: 148px !important;
text-align: center !important;
}
.shortcut_container {
float: none;
display:
}
.shortcut_container:first-child {
text-align: right;
}
.shortcut_container:last-child {
text-align: left;
}
.shortcut_element {
margin: 0 !important;
padding: 0 !important;
float: none !important;
width: 70px !important;
text-align: center;
}
.shortcut_element_left, .shortcut_element_right, .shortcut_element_left_premium, .shortcut_element_right_premium {
display: none;
}
.shortcut_element_center, .shortcut_element_center_premium {
background: none;
float: none;
diplay: inline-block;
}
.shortcut_element_marker, .shortcut_element_marker_premium {
background-image: none !important;
float: none !important;
display: inline-block !important;
padding: 0 !important;
a {
position: relative;
opacity: 0.7;
}
a:hover, a.has_notif {
opacity: 1;
}
a.has_notif .shortcut_element_image::after {
background-image: url("moz-extension://__MSG_@@extension_id__/images/notif.svg"), url("chrome-extension://__MSG_@@extension_id__/images/notif.svg");
background-size: 13px 13px;
position: absolute;
top: -13px;
right: 3px;
width: 13px;
height: 13px;
content: "";
}
.shortcut_element_image {
padding: 5px 10px;
}
.shortcut_element_image img {
height: 22px;
}
.shortcut_element_desc {
display: inline-block;
vertical-align: top;
font-size: 15px;
font-weight: bold;
padding: 5px 10px 5px 0;
margin: 0 0 0 -10px;
}
}
}

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);
}