Skip to content

Commit

Permalink
Fleet numbers are now scraped from the Shipyard page and sent to the …
Browse files Browse the repository at this point in the history
…OGNext instance, closes #15.
  • Loading branch information
skiwi2 committed Jan 8, 2016
1 parent 2347387 commit 38b6560
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
38 changes: 38 additions & 0 deletions functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,44 @@ function processFleetNodes(nodes) {
});
}

function processShipyardNodes(nodes) {
var shipyard = [];

for (var i = 0; i < nodes.length; i++) {
var node = nodes[i];
var detailButtonElement = node.querySelector(".detail_button");
if (detailButtonElement !== null) {
var fleetId = detailButtonElement.getAttribute("ref");
var cloneLevelNode = detailButtonElement.querySelector(".level").cloneNode(true);
var children = [].slice.call(cloneLevelNode.children);

for (var j = 0; j < children.length; j++) {
var child = children[j];
if (child.className === "textlabel" || child.className === "undermark") {
cloneLevelNode.removeChild(child);
}
}
var fleetAmount = cloneLevelNode.innerHTML.trim();

shipyard.push({
id: fleetId,
amount: fleetAmount
});
}
}

executeIfNotCached("shipyard", shipyard, function () {
var data = {
shipyard: shipyard
}
addPlanetData(data);
postData({
endpoint: "shipyard",
data: data
});
});
}

function postData(object) {
addPlayerData(object.data);
console.log(JSON.stringify(object.data));
Expand Down
5 changes: 5 additions & 0 deletions ognext.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ function showOGNextSettings() {
saveSetting(getFullCacheKey("facility_buildings"), "");
saveSetting(getFullCacheKey("defences"), "");
saveSetting(getFullCacheKey("fleet"), "");
saveSetting(getFullCacheKey("shipyard"), "");
showSuccessMessage("Settings have been saved.");
});
}
Expand Down Expand Up @@ -168,6 +169,10 @@ else if (page === "fleet1") {
var liButtonDivs = document.querySelectorAll("li[id^='button']");
processFleetNodes(liButtonDivs);
}
else if (page === "shipyard") {
var itemBoxDivs = document.querySelectorAll(".item_box");
processShipyardNodes(itemBoxDivs);
}

var planetListDiv = document.getElementById("planetList");
if (planetListDiv !== null) {
Expand Down

0 comments on commit 38b6560

Please sign in to comment.