Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [code]// ==UserScript==
- // @name Nations Collect All
- // @namespace http://eli.atonis.nations.com
- // @version 1.2
- // @description Adds a collect all button to Nations
- // @author Eli Atonis
- // @match http://nationsgame.net/nation/Xenforo*
- // @grant none
- // ==/UserScript==
- //Exclude list, add the factory ID or the factory name of factories you do not want to be auto collected here
- var factoryExclude = [
- "Quarry",
- "Beekeeper",
- "Silver Mine",
- "Hunting Lodge",
- "Hardened Fishermen",
- "Fishery (Mackerel)",
- "Dairy",
- "Shrimp Trawler",
- "Hunter's Hut",
- "Whaler",
- "Gold Mine"
- ];
- //Global
- var globInput;
- var globButton;
- var globCollect;
- var scanRes = false;
- var collect = false;
- var showStat = false;
- //Resources
- var resources = {};
- //Factories
- var factories = {};
- //Collection Stats
- var stats = {};
- function updateFactory(li) {
- var id = li.attr("id").replace("nation_view_factory_", "");
- factories[id] = {};
- factories[id].name = li.find("span[class='data scroller']").clone().children().remove().end().text();
- factories[id].num = parseInt(li.find("span[class='data scroller'] span.tag").text().replace(new RegExp(",", 'g'), ""));
- factories[id].proCur = parseInt(li.find("span[class='info']:eq(0)").text().split(":")[1].split("/")[0].replace(new RegExp(",", 'g'), "").trim());
- factories[id].proMax = parseInt(li.find("span[class='info']:eq(0)").text().split(":")[1].split("/")[1].replace(new RegExp(",", 'g'), "").trim());
- factories[id].input = {};
- var input = li.find("span[class='info']:eq(1)").text().split(":")[1].split(",");
- input.forEach(function(inp) {
- var inpArr = inp.trim().split(" ");
- factories[id].input[inp.replace(inpArr[0], "").trim()] = parseInt(inpArr[0]);
- });
- factories[id].output = {};
- var output = li.find("span[class='info']:eq(2)").text().split(":")[1].split(",");
- output.forEach(function(out) {
- var outArr = out.trim().split(" ");
- factories[id].output[out.replace(outArr[0], "").trim()] = parseInt(outArr[0]);
- });
- factories[id].proEff = parseInt(li.find("span[class='info']:eq(3)").text().split(":")[1].replace("%", "").trim());
- }
- function updateResources(li) {
- var res = li.find("span[class='data']").text().toLowerCase();
- res = alias(res);
- resources[res] = parseInt(li.find("span[class='num']").text().replace(new RegExp(",", 'g'), ""));
- }
- function updateBasic(li) {
- var name = li.find("h2").text().toLowerCase();
- var val = parseInt(li.find("span[class='value']").last().text().replace(new RegExp(",", 'g'), "").trim());
- resources[name] = val;
- }
- function collectFactory(id) {
- var factory = factories[id];
- if ($.inArray(id, factoryExclude) == -1 && $.inArray(factory.name.toLowerCase(), factoryExclude) == -1) {
- var production = factory.proCur;
- for (var inp in factory.input) {
- if (!(inp in resources)) {
- production = 0;
- }
- if (resources[inp] < factory.input[inp] * production) {
- production = resources[inp];
- }
- }
- if (production > 0) {
- globInput.attr("value", production);
- globButton.attr("data-amount", production);
- globButton.attr("data-href", "collect.php?key=" + id);
- globButton.click();
- for (var statIn in factory.input) {
- if (!(statIn in stats)) {
- stats[statIn] = {loss: 0, gain: 0};
- }
- stats[statIn].loss += factory.input[statIn] * production;
- }
- for (var statOut in factory.output) {
- if (!(statOut in stats)) {
- stats[statOut] = {loss: 0, gain: 0};
- }
- stats[statOut].gain += Math.ceil(factory.output[statOut] * production * (factory.proEff / 100));
- }
- }
- }
- }
- function collectAll() {
- scanRes = true;
- collect = true;
- $("#nationResourcesContent").parent().find("a[data-suffix^='4']").click();
- }
- function alias(name) {
- switch(name) {
- case "cods":
- return "cod";
- case "cows":
- return "cow";
- case "whales":
- return "whale";
- case "goats":
- return "goat";
- case "beehives":
- return "beehive";
- case "panthers":
- return "panther";
- case "foxes":
- return "fox";
- case "shrimps":
- return "shrimp";
- case "clams":
- return "clam";
- case "gemstones":
- return "gemstone";
- case "elephants":
- return "elephant";
- case "piranhas":
- return "piranha";
- case "sharks":
- return "shark";
- case "buffalos":
- return "buffalo";
- case "boars":
- return "boar";
- case "yaks":
- return "yak";
- }
- return name;
- }
- var observer = new MutationObserver(function(mutations) {
- mutations.forEach(function(mutation) {
- if (!mutation.addedNodes) return
- for (var i = 0; i < mutation.addedNodes.length; i++) {
- var node = mutation.addedNodes[i]
- if (node.id === "nationFactoriesList") {
- $("#nationFactoriesList li").each(function() {
- updateFactory($(this));
- });
- $("#resourcesBottomList").children().each(function() {
- updateBasic($(this));
- });
- if (collect) {
- collect = false;
- showStat = true;
- for (var factory in factories) {
- collectFactory(factory);
- }
- }
- globInput.remove();
- globButton.remove();
- }
- if (node.id === "popup_1" && showStat) {
- var statString = "<table><tr><th style='width:150px'>Resource</th><th style='width:60px'>Gain</th><th style='width:60px'>Loss</th><th style='width:60px'>Change</th></tr>";
- var baseResOrder = ["money", "food", "power", "building materials", "consumer goods", "metal", "ammunition", "fuel", "uranium"];
- for (var i = 0; i < baseResOrder.length; i++) {
- if (baseResOrder[i] in stats) {
- statString += "<tr><td>" + baseResOrder[i] + "</td><td style='text-align:right'>" + stats[baseResOrder[i]].gain + "</td><td style='text-align:right'>" + stats[baseResOrder[i]].loss + "</td><td style='text-align:right'>" + (stats[baseResOrder[i]].gain - stats[baseResOrder[i]].loss) + "</td></tr>";
- delete stats[baseResOrder[i]];
- }
- }
- for (var statRes in stats) {
- statString += "<tr><td>" + statRes + "</td><td style='text-align:right'>" + stats[statRes].gain + "</td><td style='text-align:right'>" + stats[statRes].loss + "</td><td style='text-align:right'>" + (stats[statRes].gain - stats[statRes].loss) + "</td></tr>";
- }
- statString += "</table>";
- $("#popup_1 p").html(statString);
- $("#popup_1 p tr:nth-child(odd)").css("background", "#E9E9E9");
- showStat = false;
- }
- if (node.id === "nationResourcesList") {
- var num = $("#nationResourcesContent").attr("data-data").split("&")[0].split("=")[1];
- if (num == "4") {
- //Update Fauna
- $("#nationResourcesList li").each(function() {
- updateResources($(this));
- });
- if (scanRes) {
- //Goto Mined
- $("#nationResourcesContent").parent().find("a[data-suffix^='2']").click();
- }
- }
- if (num == "2") {
- //Update Mined
- $("#nationResourcesList li").each(function() {
- updateResources($(this));
- });
- if (scanRes) {
- //Goto Rare
- $("#nationResourcesContent").parent().find("a[data-suffix^='3']").click();
- }
- }
- if (num == "3") {
- //Update Rare
- $("#nationResourcesList li").each(function() {
- updateResources($(this));
- });
- if (scanRes) {
- //Stop Init
- scanRes = false;
- //Reset resource view
- $("#nationResourcesContent").parent().find("a[data-suffix^='1']").click();
- //Goto Factories
- $("#nationFactoriesContent").parent().find("a[data-suffix^='all']").click();
- }
- }
- }
- }
- })
- })
- observer.observe(document.body, {
- childList: true
- , subtree: true
- , attributes: false
- , characterData: false
- })
- $(document).ready(function() {
- $.each(factoryExclude, function(index, value) {
- factoryExclude[index] = value.toLowerCase();
- });
- globInput = $("<input name=\"item_amount\" id=\"prod_amount\" value=\"0\" />");
- globButton = $("<button id=\"collectButton\" class=\"box-button action\" data-amount=\"0\" data-type=\"collect\" data-href=\"collect.php?key=0\">Collect</button>");
- globCollect = $("<span class=\"button hl\"><span style=\"font-weight: bold; color: #75620D; vertical-align: middle;\">Collect All</span></span>");
- $("#nationFactoriesContent").parent().prepend(globCollect);
- globInput.hide();
- globButton.hide();
- globCollect.click(function() {
- stats = {};
- $("#nationHeaderBackgroundOverlay").append(globInput);
- $("#nationHeaderBackgroundOverlay").append(globButton);
- collectAll();
- });
- });
- [/code]
- Created by: [url=http://nationsgame.net/user/Ash%20Ketchum/]Ash[/url] (of [url=http://nationsgame.net/nation/Kanto/]Kanto[/url])
- [b]Please change the following:[/b][/i][/i][/i][/i][/i][/i][/i][/i]
- [list]
- [*][b]Nation Link[/b]
- [i]// @match http://nationsgame.net/nation/Xenforo*[/i]
- [*][b]Factories Exclusion List[/b]
- [i]//Exclude list, add the factory ID or the factory name of factories you do not want to be auto collected here
- var factoryExclude = [
- "Quarry",
- "Beekeeper",
- "Silver Mine",
- "Hunting Lodge",
- "Hardened Fishermen",
- "Fishery (Mackerel)",
- "Dairy",
- "Shrimp Trawler",
- "Hunter's Hut",
- "Whaler",
- "Gold Mine"
- ];[/i]
- [/list][i][i][i][i][i][i][i][i]
- Method 1: Browser Console[/i][/i][/i][/i][/i][/i][/i][/i]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement