Not Solved [Error Message] Duplicated [i] and [/i]
#1
Not Solved
// ==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();
   });
});

Created by: Ash (of Kanto)

Please change the following:[/i][/i][/i][/i][/i][/i][/i][/i]
  • Nation Link
    // @match        http://nationsgame.net/nation/Xenforo*
  • Factories Exclusion List
    //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][i][i][i][i][i][i]

Method 1: Browser Console
[/i][/i][/i][/i][/i][/i][/i]

The whole above text is very problematic when pasted into an editor.

This is the original text:

http://pastebin.com/QbBtPGFa

When I paste it into my forum's editor, it becomes:

http://pastebin.com/g5JVsTEq

If I paste the text into this forum's editor and switch between visual and raw text, it'll go wrong too.
I'm new to MyBB, has been using WordPress and only know HTML/CSS.
Reply
#2
Not Solved
No one can help me this?
I'm new to MyBB, has been using WordPress and only know HTML/CSS.
Reply
#3
Not Solved
@XP Mai I test it on my forum and it work

[Image: e42028bf3f93e048f4d42d396e0013d9.png]
My Projects - Support My Projects

Don't forget to rate posts!
Reply
#4
Not Solved
Test it in this forum and you'll instantly understand what I mean.
I'm new to MyBB, has been using WordPress and only know HTML/CSS.
Reply
#5
Not Solved
// ==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();
   });
});

Created by: Ash (of Kanto)

Please change the following:
  • Nation Link
    // @match http://nationsgame.net/nation/Xenforo*
  • Factories Exclusion List
    //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"
    ];


Method 1: Browser Console

mmm... for post this I had to edit the post 3 times, it only showed me code tag
My Projects - Support My Projects

Don't forget to rate posts!
Reply
#6
Not Solved
now go to edit, switch between visual/source editor.

Then everything will be messed up when you attempt to edit the content.
I'm new to MyBB, has been using WordPress and only know HTML/CSS.
Reply
#7
Not Solved
Yes, it is bugged, but I don't know why
My Projects - Support My Projects

Don't forget to rate posts!
Reply
#8
Not Solved
(2015-09-23, 02:07 PM)chack1172 Wrote: mmm... for post this I had to edit the post 3 times, it only showed me code tag

Now you believe me this code is problematic?

In this forum, the symptom is showing code tag only. In my forum, the symptom is duplicated [/i] tags.

I hope someone can troubleshoot this for me...
I'm new to MyBB, has been using WordPress and only know HTML/CSS.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)