Skip to content

Commit

Permalink
Fleet numbers are now scraped from the Fleet page and sent to the OGN…
Browse files Browse the repository at this point in the history
…ext instance.
  • Loading branch information
skiwi2 committed Jan 8, 2016
1 parent 0429105 commit 2ca9d30
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 @@ -204,6 +204,44 @@ function processDefenceNodes(nodes) {
});
}

function processFleetNodes(nodes) {
var fleet = [];

for (var i = 0; i < nodes.length; i++) {
var node = nodes[i];
var aTooltipElement = node.querySelector(".tooltip");
if (aTooltipElement !== null) {
var fleetId = node.id.replace(/\D/g, "");
var cloneLevelNode = aTooltipElement.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();

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

executeIfNotCached("fleet", fleet, function () {
var data = {
fleet: fleet
}
addPlanetData(data);
postData({
endpoint: "fleet",
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 @@ -126,6 +126,7 @@ function showOGNextSettings() {
saveSetting(getFullCacheKey("resource_buildings"), "");
saveSetting(getFullCacheKey("facility_buildings"), "");
saveSetting(getFullCacheKey("defences"), "");
saveSetting(getFullCacheKey("fleet"), "");
showSuccessMessage("Settings have been saved.");
});
}
Expand Down Expand Up @@ -163,6 +164,10 @@ else if (page === "defense") {
var itemBoxDivs = document.querySelectorAll(".item_box");
processDefenceNodes(itemBoxDivs);
}
else if (page === "fleet1") {
var liButtonDivs = document.querySelectorAll("li[id^='button']");
processFleetNodes(liButtonDivs);
}

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

0 comments on commit 2ca9d30

Please sign in to comment.