Advertisement
Guest User

Problematic Text (Symptom)

a guest
Sep 11th, 2015
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.79 KB | None | 0 0
  1. [code]// ==UserScript==
  2. // @name         Nations Collect All
  3. // @namespace    http://eli.atonis.nations.com
  4. // @version      1.2
  5. // @description  Adds a collect all button to Nations
  6. // @author       Eli Atonis
  7. // @match        http://nationsgame.net/nation/Xenforo*
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11. //Exclude list, add the factory ID or the factory name of factories you do not want to be auto collected here
  12. var factoryExclude = [
  13. "Quarry",
  14. "Beekeeper",
  15. "Silver Mine",
  16. "Hunting Lodge",
  17. "Hardened Fishermen",
  18. "Fishery (Mackerel)",
  19. "Dairy",
  20. "Shrimp Trawler",
  21. "Hunter's Hut",
  22. "Whaler",
  23. "Gold Mine"
  24. ];
  25.  
  26. //Global
  27. var globInput;
  28. var globButton;
  29. var globCollect;
  30. var scanRes = false;
  31. var collect = false;
  32. var showStat = false;
  33.  
  34. //Resources
  35. var resources = {};
  36.  
  37. //Factories
  38. var factories = {};
  39.  
  40. //Collection Stats
  41. var stats = {};
  42.  
  43. function updateFactory(li) {
  44.    var id = li.attr("id").replace("nation_view_factory_", "");
  45.    factories[id] = {};
  46.    factories[id].name = li.find("span[class='data scroller']").clone().children().remove().end().text();
  47.    factories[id].num = parseInt(li.find("span[class='data scroller'] span.tag").text().replace(new RegExp(",", 'g'), ""));
  48.    factories[id].proCur = parseInt(li.find("span[class='info']:eq(0)").text().split(":")[1].split("/")[0].replace(new RegExp(",", 'g'), "").trim());
  49.    factories[id].proMax = parseInt(li.find("span[class='info']:eq(0)").text().split(":")[1].split("/")[1].replace(new RegExp(",", 'g'), "").trim());
  50.    factories[id].input = {};
  51.    var input = li.find("span[class='info']:eq(1)").text().split(":")[1].split(",");
  52.    input.forEach(function(inp) {
  53.        var inpArr = inp.trim().split(" ");
  54.        factories[id].input[inp.replace(inpArr[0], "").trim()] = parseInt(inpArr[0]);
  55.    });
  56.    factories[id].output = {};
  57.    var output = li.find("span[class='info']:eq(2)").text().split(":")[1].split(",");
  58.    output.forEach(function(out) {
  59.        var outArr = out.trim().split(" ");
  60.        factories[id].output[out.replace(outArr[0], "").trim()] = parseInt(outArr[0]);
  61.    });
  62.    factories[id].proEff = parseInt(li.find("span[class='info']:eq(3)").text().split(":")[1].replace("%", "").trim());
  63. }
  64.  
  65. function updateResources(li) {
  66.    var res = li.find("span[class='data']").text().toLowerCase();
  67.    res = alias(res);
  68.    resources[res] = parseInt(li.find("span[class='num']").text().replace(new RegExp(",", 'g'), ""));
  69. }
  70.  
  71. function updateBasic(li) {
  72.    var name = li.find("h2").text().toLowerCase();
  73.    var val = parseInt(li.find("span[class='value']").last().text().replace(new RegExp(",", 'g'), "").trim());
  74.    resources[name] = val;
  75. }
  76.  
  77. function collectFactory(id) {
  78.    var factory = factories[id];
  79.    if ($.inArray(id, factoryExclude) == -1 && $.inArray(factory.name.toLowerCase(), factoryExclude) == -1) {
  80.        var production = factory.proCur;
  81.        for (var inp in factory.input) {
  82.            if (!(inp in resources)) {
  83.                production = 0;
  84.            }
  85.            if (resources[inp] < factory.input[inp] * production) {
  86.                production = resources[inp];
  87.            }
  88.        }
  89.        if (production > 0) {
  90.            globInput.attr("value", production);
  91.            globButton.attr("data-amount", production);
  92.            globButton.attr("data-href", "collect.php?key=" + id);
  93.            globButton.click();
  94.            for (var statIn in factory.input) {
  95.                if (!(statIn in stats)) {
  96.                    stats[statIn] = {loss: 0, gain: 0};
  97.                }
  98.                stats[statIn].loss += factory.input[statIn] * production;
  99.            }
  100.            for (var statOut in factory.output) {
  101.                if (!(statOut in stats)) {
  102.                    stats[statOut] = {loss: 0, gain: 0};
  103.                }
  104.                stats[statOut].gain += Math.ceil(factory.output[statOut] * production * (factory.proEff / 100));
  105.            }
  106.        }
  107.    }
  108. }
  109.  
  110. function collectAll() {
  111.    scanRes = true;
  112.    collect = true;
  113.    $("#nationResourcesContent").parent().find("a[data-suffix^='4']").click();
  114. }
  115.  
  116. function alias(name) {
  117.    switch(name) {
  118.        case "cods":
  119.            return "cod";
  120.        case "cows":
  121.            return "cow";
  122.        case "whales":
  123.            return "whale";
  124.        case "goats":
  125.            return "goat";
  126.        case "beehives":
  127.            return "beehive";
  128.        case "panthers":
  129.            return "panther";
  130.        case "foxes":
  131.            return "fox";
  132.        case "shrimps":
  133.            return "shrimp";
  134.        case "clams":
  135.            return "clam";
  136.        case "gemstones":
  137.            return "gemstone";
  138.        case "elephants":
  139.            return "elephant";
  140.        case "piranhas":
  141.            return "piranha";
  142.        case "sharks":
  143.            return "shark";
  144.        case "buffalos":
  145.            return "buffalo";
  146.        case "boars":
  147.            return "boar";
  148.        case "yaks":
  149.            return "yak";
  150.    }
  151.    return name;
  152. }
  153.  
  154. var observer = new MutationObserver(function(mutations) {
  155.    mutations.forEach(function(mutation) {
  156.        if (!mutation.addedNodes) return
  157.  
  158.        for (var i = 0; i < mutation.addedNodes.length; i++) {
  159.            var node = mutation.addedNodes[i]
  160.  
  161.            if (node.id === "nationFactoriesList") {
  162.                $("#nationFactoriesList li").each(function() {
  163.                    updateFactory($(this));
  164.                });
  165.  
  166.                $("#resourcesBottomList").children().each(function() {
  167.                    updateBasic($(this));
  168.                });
  169.  
  170.                if (collect) {
  171.                    collect = false;
  172.                    showStat = true;
  173.                    for (var factory in factories) {
  174.                        collectFactory(factory);
  175.                    }
  176.                }
  177.                
  178.                globInput.remove();
  179.                globButton.remove();
  180.            }
  181.            
  182.            if (node.id === "popup_1" && showStat) {
  183.                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>";
  184.                var baseResOrder = ["money", "food", "power", "building materials", "consumer goods", "metal", "ammunition", "fuel", "uranium"];
  185.                for (var i = 0; i < baseResOrder.length; i++) {
  186.                    if (baseResOrder[i] in stats) {
  187.                        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>";
  188.                        delete stats[baseResOrder[i]];
  189.                    }
  190.                }
  191.                for (var statRes in stats) {
  192.                    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>";
  193.                }
  194.                statString += "</table>";
  195.                $("#popup_1 p").html(statString);
  196.                $("#popup_1 p tr:nth-child(odd)").css("background", "#E9E9E9");
  197.                showStat = false;
  198.            }
  199.  
  200.            if (node.id === "nationResourcesList") {
  201.                var num = $("#nationResourcesContent").attr("data-data").split("&")[0].split("=")[1];
  202.  
  203.                if (num == "4") {
  204.                    //Update Fauna
  205.                    $("#nationResourcesList li").each(function() {
  206.                        updateResources($(this));
  207.                    });
  208.                    if (scanRes) {
  209.                        //Goto Mined
  210.                        $("#nationResourcesContent").parent().find("a[data-suffix^='2']").click();
  211.                    }
  212.                }
  213.  
  214.                if (num == "2") {
  215.                    //Update Mined
  216.                    $("#nationResourcesList li").each(function() {
  217.                        updateResources($(this));
  218.                    });
  219.                    if (scanRes) {
  220.                        //Goto Rare
  221.                        $("#nationResourcesContent").parent().find("a[data-suffix^='3']").click();
  222.                    }
  223.                }
  224.  
  225.                if (num == "3") {
  226.                    //Update Rare
  227.                    $("#nationResourcesList li").each(function() {
  228.                        updateResources($(this));
  229.                    });
  230.                    if (scanRes) {
  231.                        //Stop Init
  232.                        scanRes = false;
  233.                        //Reset resource view
  234.                        $("#nationResourcesContent").parent().find("a[data-suffix^='1']").click();
  235.                        //Goto Factories
  236.                        $("#nationFactoriesContent").parent().find("a[data-suffix^='all']").click();
  237.                    }
  238.                }
  239.            }
  240.        }
  241.    })
  242. })
  243.  
  244. observer.observe(document.body, {
  245.    childList: true
  246.    , subtree: true
  247.    , attributes: false
  248.    , characterData: false
  249. })
  250.  
  251. $(document).ready(function() {
  252.    $.each(factoryExclude, function(index, value) {
  253.        factoryExclude[index] = value.toLowerCase();
  254.    });
  255.    globInput = $("<input name=\"item_amount\" id=\"prod_amount\" value=\"0\" />");
  256.    globButton = $("<button id=\"collectButton\" class=\"box-button action\" data-amount=\"0\" data-type=\"collect\" data-href=\"collect.php?key=0\">Collect</button>");
  257.    globCollect = $("<span class=\"button hl\"><span style=\"font-weight: bold; color: #75620D; vertical-align: middle;\">Collect All</span></span>");
  258.    $("#nationFactoriesContent").parent().prepend(globCollect);
  259.    globInput.hide();
  260.    globButton.hide();
  261.    globCollect.click(function() {
  262.        stats = {};
  263.        $("#nationHeaderBackgroundOverlay").append(globInput);
  264.        $("#nationHeaderBackgroundOverlay").append(globButton);
  265.        collectAll();
  266.    });
  267. });
  268. [/code]
  269.  
  270. Created by: [url=http://nationsgame.net/user/Ash%20Ketchum/]Ash[/url] (of [url=http://nationsgame.net/nation/Kanto/]Kanto[/url])
  271.  
  272. [b]Please change the following:[/b][/i][/i][/i][/i][/i][/i][/i][/i]
  273. [list]
  274. [*][b]Nation Link[/b]
  275. [i]// @match        http://nationsgame.net/nation/Xenforo*[/i]
  276. [*][b]Factories Exclusion List[/b]
  277. [i]//Exclude list, add the factory ID or the factory name of factories you do not want to be auto collected here
  278. var factoryExclude = [
  279. "Quarry",
  280. "Beekeeper",
  281. "Silver Mine",
  282. "Hunting Lodge",
  283. "Hardened Fishermen",
  284. "Fishery (Mackerel)",
  285. "Dairy",
  286. "Shrimp Trawler",
  287. "Hunter's Hut",
  288. "Whaler",
  289. "Gold Mine"
  290. ];[/i]
  291. [/list][i][i][i][i][i][i][i][i]
  292.  
  293. Method 1: Browser Console[/i][/i][/i][/i][/i][/i][/i][/i]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement