Throne3d

NARR

Jun 25th, 2014
3,742
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 18.05 KB | None | 0 0
  1. /*
  2. javascript: var format = "{DefName} {DefCoord} [{DefTroopsRemain}] Wall: {Wall}"; $.getScript("http://pastebin.com/raw.php?i=TcBzhfKF", function(){ rename(format); });
  3. {ReportID} - Report ID (e.g. 12221212)
  4. {AtkName} - Attacker's Player Name (e.g. Nineza)
  5. {AtkID} - Attacker's Player ID (e.g. 111223)
  6. {AtkCoord} - Attacker's Village Coords (e.g. 555|444)
  7. {AtkVilName} - Attacker's Village Name (e.g. 001)
  8. {AtkVilID} - Attacker's village ID (e.g. 1221)
  9. {AtkVilK} - Attacker's K/continent (e.g. K53)
  10. {DefName} - Defender's Player Name (e.g. Throne3d)
  11. {DefID} - Defender's Player ID (e.g. 222113)
  12. {DefCoord} - Defender's Village Coords (e.g. 444|555)
  13. {DefVilName} - Defender's Village Name (e.g. 002)
  14. {DefVilID} - Defender's village ID (e.g. 2112)
  15. {DefVilK} - Defender's K/continent (e.g. K51)
  16. {Distance} - Distance between attacker and defender (e.g. 156.98)
  17. {Resources} - Resources of the defending village (e.g. Wood:397400 Clay:397400 Iron:397440)
  18. {Wood} - Wood of the defending village (e.g. 397400)
  19. {Clay} - Clay of the defending village (e.g. 397400)
  20. {Iron} - Iron of the defending village (e.g. 397440)
  21. {AtkTroopsOriginal} - Attacker's original troops (e.g. Scouts:50 LC:25)
  22. {AtkTroopsLoss} - Attacker's troop loss (e.g. Scouts:1 LC:3)
  23. {AtkTroopsRemain} - Attacker's remaining troops (e.g. Scouts:49 LC:22)
  24. {DefTroopsOriginal} - Defender's original troops (e.g. Spears:5 Scouts:10)
  25. {DefTroopsLoss} - Defender's troop loss (e.g. Spears:5 Scouts:8)
  26. {DefTroopsRemain} - Defender's remaining troops (e.g. Scouts:2)
  27. {Cleared} - Whether the defender was cleared (e.g. Cleared; e.g. [blank])
  28. {%Lost} - The percentage of troops the attacker lost (e.g. 5.3%)
  29. {%Killed} - The percentage of troops the defender lost (e.g. 86.7%)
  30. {%Hauled} - The percentage of resources taken versus those left in village (e.g. 0.1%) 1760/1192240
  31. {%OfHaul} - The percentage hauled of maximum possible to haul with remaining troops (e.g. 100%)
  32. {Wall} - The level of the wall (after the attack) (e.g. 2)
  33. {Loyalty} - The loyalty of the defending village (after the attack, if visible) (e.g. 56 or ?)
  34. */
  35.  
  36. _lang = {
  37.     "en" : {
  38.         "Attacker" : "Attacker",
  39.         "Defender" : "Defender",
  40.         "Buildings" : "Buildings",
  41.         "None of your troops have returned" : "None of your troops have returned",
  42.         "Cleared" : "Cleared",
  43.         "Haul" : "Haul",
  44.         "Wood" : "Wood",
  45.         "Clay" : "Clay",
  46.         "Iron" : "Iron",
  47.         "Unexpected troop type!" : "Unexpected troop type!",
  48.         "Wall" : "Wall",
  49.         "Loyalty" : "Loyalty",
  50.         "to" : "to"
  51.     },
  52.     "no" : {
  53.         "Attacker" : "Angriper",
  54.         "Defender" : "Forsvarer",
  55.         "Buildings" : "Bygninger",
  56.         "None of your troops have returned" : "Ingen av dine tropper har returnert",
  57.         "Cleared" : "Tt",
  58.         "Haul" : "Bytte",
  59.         "Wood" : "Hogstfelt",
  60.         "Clay" : "Leirgrav",
  61.         "Iron" : "Jerngruve",
  62.         "Unexpected troop type!" : "Ukjent enhetstype",
  63.         "Wall" : "Mur",
  64.         "Loyalty" : "Lojalitet",
  65.         "to" : "til"
  66.     }
  67. };
  68. var worldLetters = window.location.host.split(/\W+/)[0].substring(0, 2);
  69. var lang = (_lang[worldLetters] && worldLetters) || "en";
  70.  
  71. function _(thing){
  72.     return (_lang[lang] && _lang[lang][thing]) || (_lang["en"] && _lang["en"][thing]) || thing;
  73. }
  74.  
  75. function rename(format){
  76.     format = format || "{DefName} {DefCoord} [{DefTroopsRemain}] Wall: {Wall}";
  77.     var attackerStuff = $("table[id='attack_info_att']");
  78.     var attackerName = $("tr:has(th:contains('" + _("Attacker") + ":')) th:not(th:contains('" + _("Attacker") + ":'))", attackerStuff).text();
  79.     var attackerLink = $("tr:has(th:contains('" + _("Attacker") + ":')) th:not(th:contains('" + _("Attacker") + ":')) a", attackerStuff);
  80.     var attackerID = (attackerLink.length > 0 && attackerLink.attr("href").match(/&id=(\d+)/)[1]) || "?";
  81.     var attackerVil = $(".village_anchor", attackerStuff).text();
  82.     var attackerVilCoords = attackerVil.split("(")[1].split(")")[0];
  83.     var attackerVilContinent = attackerVil.match(/K\d+/)[0];
  84.     var attackerVilName = attackerVil.split("(")[0].trim();
  85.     var attackerVilID = $(".village_anchor a[href!='#']", attackerStuff).attr("href").match(/id=(\d+)/)[1];
  86.    
  87.     var defenderStuff = $("table[id='attack_info_def']");
  88.     var defenderName = $("tr:has(th:contains('" + _("Defender") + ":')) th:not(th:contains('" + _("Defender") + ":'))", defenderStuff).text();
  89.     var defenderLink = $("tr:has(th:contains('" + _("Defender") + ":')) th:not(th:contains('" + _("Defender") + ":')) a", defenderStuff);
  90.     var defenderID = (defenderLink.length > 0 && defenderLink.attr("href").match(/&id=(\d+)/)[1]) || "?";
  91.     var defenderVil = $(".village_anchor", defenderStuff).text();
  92.     var defenderVilCoords = defenderVil.split("(")[1].split(")")[0];
  93.     var defenderVilContinent = defenderVil.match(/K\d+/)[0];
  94.     var defenderVilName = defenderVil.split("(")[0].trim();
  95.     var defenderVilID = $(".village_anchor a[href!='#']", defenderStuff).attr("href").match(/id=(\d+)/)[1];
  96.    
  97.     var attackerVilCoordsA = attackerVilCoords.split("|");
  98.     var defenderVilCoordsA = defenderVilCoords.split("|");
  99.     var distance = Math.floor(Math.sqrt(Math.pow(attackerVilCoordsA[0] - defenderVilCoordsA[0], 2) + Math.pow(attackerVilCoordsA[1] - defenderVilCoordsA[1], 2)) * 100 + 0.5) / 100;
  100.    
  101.     var espionage = $("#attack_spy");
  102.     var wood, clay, iron, wall;
  103.     if (espionage.length > 0){
  104.         var resources = $($("tr td", espionage).get(0));
  105.         var resz = resources.text().trim().split("  ");
  106.         if (resources.get(0).innerHTML.indexOf("wood") === -1){
  107.             resz.unshift("0");
  108.         }
  109.         if (resources.get(0).innerHTML.indexOf("stone") === -1){
  110.             if (resz[1]) { resz.push(resz[1]); resz[1] = "0"; }
  111.             else resz.push("0");
  112.         }
  113.         if (resources.get(0).innerHTML.indexOf("iron") === -1){
  114.             resz.push("0");
  115.         }
  116.         wood = parseInt(resz[0].replace(".", ""));
  117.         clay = parseInt(resz[1].replace(".", ""));
  118.         iron = parseInt(resz[2].replace(".", ""));
  119.         var buildingBox = $("tr:has(th:contains('" + _("Buildings") + "')) td", espionage);
  120.         if (buildingBox.length > 0){
  121.             var buildingsText = buildingBox.text().trim().replace(/\t/g, "");
  122.             if (buildingsText.match(new RegExp(_("Wall") + " \(" + _("Level") + " (\d+)\)")))
  123.                 var wall = buildingsText.match(new RegExp(_("Wall") + " \(" + _("Level") + " (\d+)\)"))[1];
  124.             else
  125.                 var wall = "0";
  126.         } else {
  127.             var buildingsText = "";
  128.         }
  129.     } else {
  130.         var espiRes = $("#attack_spy_resources"),
  131.             espiBuild = $("#attack_spy_building_data");
  132.        
  133.         if (espiRes.length > 0){
  134.             var resources = $($("tr td", espiRes).get(0));
  135.             var resz = resources.text().trim().split("  ");
  136.             if (resources.get(0).innerHTML.indexOf("wood") === -1){
  137.                 resz.unshift("0");
  138.             }
  139.             if (resources.get(0).innerHTML.indexOf("stone") === -1){
  140.                 if (resz[1]) { resz.push(resz[1]); resz[1] = "0"; }
  141.                 else resz.push("0");
  142.             }
  143.             if (resources.get(0).innerHTML.indexOf("iron") === -1){
  144.                 resz.push("0");
  145.             }
  146.             wood = parseInt(resz[0].replace(".", ""));
  147.             clay = parseInt(resz[1].replace(".", ""));
  148.             iron = parseInt(resz[2].replace(".", ""));
  149.         }
  150.         if (espiBuild.length > 0){
  151.             var builds = JSON.parse(espiBuild.attr("value"));
  152.             builds.forEach(function(build){
  153.                 if (build.id === "wall")
  154.                     wall = build.level;
  155.             });
  156.             wall = wall || 0;
  157.         }
  158.     }
  159.     wood = wood && wood.toString() || "?";
  160.     clay = clay && clay.toString() || "?";
  161.     iron = iron && iron.toString() || "?";
  162.     wall = wall && wall.toString() || "?";
  163.    
  164.     var reportID = window.location.href.match(/&view=(\d+)/)[1];
  165.    
  166.     var attackerTroops = $("#attack_info_att_units");
  167.     var defenderTroops = $("#attack_info_def_units");
  168.    
  169.     var atttroopsExisting = $("tr[class='center'] td[width='35']", attackerTroops);
  170.     var attworldFunctionality = [];
  171.     atttroopsExisting.each(function(){
  172.         if ($(this).html().match("spear")) attworldFunctionality.push(_("Spear"));
  173.         else if ($(this).html().match("sword")) attworldFunctionality.push(_("Sword"));
  174.         else if ($(this).html().match("axe")) attworldFunctionality.push(_("Axe"));
  175.         else if ($(this).html().match("archer")) attworldFunctionality.push(_("Archer"));
  176.         else if ($(this).html().match("spy")) attworldFunctionality.push(_("Scout"));
  177.         else if ($(this).html().match("light")) attworldFunctionality.push(_("LC"));
  178.         else if ($(this).html().match("marcher")) attworldFunctionality.push(_("MA"));
  179.         else if ($(this).html().match("heavy")) attworldFunctionality.push(_("HC"));
  180.         else if ($(this).html().match("ram")) attworldFunctionality.push(_("Ram"));
  181.         else if ($(this).html().match("catapult")) attworldFunctionality.push(_("Cat"));
  182.         else if ($(this).html().match("knight")) attworldFunctionality.push(_("Paladin"));
  183.         else if ($(this).html().match("snob")) attworldFunctionality.push(_("Noble"));
  184.         else alert(_("Unexpected troop type!"));
  185.     });
  186.    
  187.     var deftroopsExisting = $("tr[class='center'] td[width='35']", defenderTroops);
  188.     var defworldFunctionality = [];
  189.     deftroopsExisting.each(function(){
  190.         if ($(this).html().match("spear")) defworldFunctionality.push(_("Spear"));
  191.         else if ($(this).html().match("sword")) defworldFunctionality.push(_("Sword"));
  192.         else if ($(this).html().match("axe")) defworldFunctionality.push(_("Axe"));
  193.         else if ($(this).html().match("archer")) defworldFunctionality.push(_("Archer"));
  194.         else if ($(this).html().match("spy")) defworldFunctionality.push(_("Scout"));
  195.         else if ($(this).html().match("light")) defworldFunctionality.push(_("LC"));
  196.         else if ($(this).html().match("marcher")) defworldFunctionality.push(_("MA"));
  197.         else if ($(this).html().match("heavy")) defworldFunctionality.push(_("HC"));
  198.         else if ($(this).html().match("ram")) defworldFunctionality.push(_("Ram"));
  199.         else if ($(this).html().match("catapult")) defworldFunctionality.push(_("Cat"));
  200.         else if ($(this).html().match("knight")) defworldFunctionality.push(_("Paladin"));
  201.         else if ($(this).html().match("snob")) defworldFunctionality.push(_("Noble"));
  202.         else if ($(this).html().match("militia")) defworldFunctionality.push(_("Militia"));
  203.         else alert(_("Unexpected troop type!"));
  204.     });
  205.    
  206.     var attackerTroopsOriginal = $("tr[class!='center']", attackerTroops).get(0);
  207.     var attackerTroopsLoss = $("tr[class!='center']", attackerTroops).get(1);
  208.     var attackerTroopsOriginalListA = $("td[width!='20%']", attackerTroopsOriginal);
  209.     var attackerTroopsLossListA = $("td[width!='20%']", attackerTroopsLoss);
  210.     var attackerTroopsOriginalList = {};
  211.     var attackerTroopsLossList = {};
  212.     var attackerTroopsRemainingList = {};
  213.     var attackerTroopsOriginalString = "";
  214.     var attackerTroopsLossString = "";
  215.     var attackerTroopsRemainingString = "";
  216.     var attackerTroopsOriginalNumber;
  217.     var attackerTroopsLossNumber;
  218.     var attackerTroopsRemainingNumber;
  219.    
  220.     var defenderTroopsOriginal = $("tr[class!='center']", defenderTroops).get(0);
  221.     var defenderTroopsLoss = $("tr[class!='center']", defenderTroops).get(1);
  222.     if (defenderStuff.html().match(_("None of your troops have returned"))) defenderTroopsOriginalListA = $();
  223.     else defenderTroopsOriginalListA = $("td[width!='20%']", defenderTroopsOriginal);
  224.     if (defenderStuff.html().match(_("None of your troops have returned"))) defenderTroopsLossListA = $();
  225.     else defenderTroopsLossListA = $("td[width!='20%']", defenderTroopsLoss);
  226.     var defenderTroopsOriginalList = {};
  227.     var defenderTroopsLossList = {};
  228.     var defenderTroopsRemainingList = {};
  229.     var defenderTroopsOriginalString = "";
  230.     var defenderTroopsLossString = "";
  231.     var defenderTroopsRemainingString = "";
  232.     var defenderTroopsOriginalNumber;
  233.     var defenderTroopsLossNumber;
  234.     var defenderTroopsRemainingNumber;
  235.    
  236.     defenderTroopsOriginalListA.each(function(index){
  237.         if (parseInt($(this).html()) !== 0){
  238.             defenderTroopsOriginalList[defworldFunctionality[index]] = parseInt($(this).html());
  239.             defenderTroopsOriginalString += " " + defworldFunctionality[index] + ":" + $(this).html();
  240.             defenderTroopsOriginalNumber += parseInt($(this).html());
  241.         }
  242.     });
  243.     defenderTroopsLossListA.each(function(index){
  244.         if (parseInt($(this).html()) !== 0){
  245.             defenderTroopsLossList[defworldFunctionality[index]] = parseInt($(this).html());
  246.             defenderTroopsLossString += " " + defworldFunctionality[index] + ":" + $(this).html();
  247.             defenderTroopsLossNumber += parseInt($(this).html());
  248.         }
  249.     });
  250.     attackerTroopsOriginalListA.each(function(index){
  251.         if (parseInt($(this).html()) !== 0){
  252.             attackerTroopsOriginalList[attworldFunctionality[index]] = parseInt($(this).html());
  253.             attackerTroopsOriginalString += " " + attworldFunctionality[index] + ":" + $(this).html();
  254.             attackerTroopsOriginalNumber += parseInt($(this).html());
  255.         }
  256.     });
  257.     attackerTroopsLossListA.each(function(index){
  258.         if (parseInt($(this).html()) !== 0){
  259.             attackerTroopsLossList[attworldFunctionality[index]] = parseInt($(this).html());
  260.             attackerTroopsLossString += " " + attworldFunctionality[index] + ":" + $(this).html();
  261.             attackerTroopsLossNumber += parseInt($(this).html());
  262.         }
  263.     });
  264.     for (unit in defenderTroopsOriginalList){
  265.         defenderTroopsRemainingList[unit] = (defenderTroopsLossList[unit]) ? defenderTroopsOriginalList[unit] - defenderTroopsLossList[unit] : defenderTroopsOriginalList[unit];
  266.         if (defenderTroopsRemainingList[unit] === 0) delete defenderTroopsRemainingList[unit];
  267.         else {
  268.             defenderTroopsRemainingString += " " + unit + ":" + defenderTroopsRemainingList[unit];
  269.             defenderTroopsRemainingNumber += parseInt(defenderTroopsRemainingList[unit]);
  270.         }
  271.     }
  272.     for (unit in attackerTroopsOriginalList){
  273.         attackerTroopsRemainingList[unit] = (attackerTroopsLossList[unit]) ? attackerTroopsOriginalList[unit] - attackerTroopsLossList[unit] : attackerTroopsOriginalList[unit];
  274.         if (attackerTroopsRemainingList[unit] === 0) delete attackerTroopsRemainingList[unit];
  275.         else {
  276.             attackerTroopsRemainingString += " " + unit + ":" + attackerTroopsRemainingList[unit];
  277.             attackerTroopsRemainingNumber += parseInt(attackerTroopsRemainingList[unit]);
  278.         }
  279.     }
  280.    
  281.     attackerTroopsOriginalString = attackerTroopsOriginalString.trim();
  282.     attackerTroopsLossString = attackerTroopsLossString.trim();
  283.     attackerTroopsRemainingString = attackerTroopsRemainingString.trim();
  284.    
  285.     defenderTroopsOriginalString = defenderTroopsOriginalString.trim();
  286.     defenderTroopsLossString = defenderTroopsLossString.trim();
  287.     defenderTroopsRemainingString = defenderTroopsRemainingString.trim();
  288.    
  289.     if (defenderTroopsRemainingString === "") var cleared = _("Cleared"); else var cleared = "";
  290.     var percLost = Math.floor((attackerTroopsLossNumber / attackerTroopsOriginalNumber) * 10000 + 0.5) / 100;
  291.     var percKilled = Math.floor((defenderTroopsLossNumber / defenderTroopsOriginalNumber) * 10000 + 0.5) / 100;
  292.     var haul = $("#attack_results tr:has(th:contains('" + _("Haul") + "')) td");
  293.     if (haul.length > 0){
  294.         var haulDet = $(haul.get(1)).text().trim().replace(/\./g, "").split("/");
  295.         var hauled = haulDet[0];
  296.         var percResHauled = (Math.floor((haulDet[0] / haulDet[1]) * 10000 + 0.5) / 100).toString();
  297.         var percOfPossibleHaul = (Math.floor((haulDet[0] / (parseInt(haulDet[0]) + parseInt(wood) + parseInt(clay) + parseInt(iron))) * 10000 + 0.5) / 100).toString();
  298.     } else {
  299.         var percOfPossibleHaul = "?";
  300.         var percResHauled = "?";
  301.     }
  302.    
  303.     var loyalt = $("tr:has(> th:contains('" + _("Loyalty") + ":'):not(:has(pan))) td");
  304.     var loyalty = (loyalt.length > 0) ? (loyalt.text().split(_("to") + " ").length > 1) ? parseInt(loyalt.text().split(_("to") + " ")[1]) : "?" : "?";
  305.    
  306.     var name = format;
  307.     name = name.replace("{ReportID}", reportID);
  308.     name = name.replace("{AtkName}", attackerName);
  309.     name = name.replace("{AtkID}", attackerID);
  310.     name = name.replace("{AtkCoord}", attackerVilCoords);
  311.     name = name.replace("{AtkVilName}", attackerVilName);
  312.     name = name.replace("{AtkVilID}", attackerVilID);
  313.     name = name.replace("{AtkVilK}", attackerVilContinent);
  314.     name = name.replace("{DefName}", defenderName);
  315.     name = name.replace("{DefID}", defenderID);
  316.     name = name.replace("{DefCoord}", defenderVilCoords);
  317.     name = name.replace("{DefVilName}", defenderVilName);
  318.     name = name.replace("{DefVilID}", defenderVilID);
  319.     name = name.replace("{DefVilK}", defenderVilContinent);
  320.     name = name.replace("{Distance}", distance);
  321.     name = name.replace("{Resources}", _("Wood") + ":" + wood + " " + _("Clay") + ":" + clay + " " + _("Iron") + ":" + iron);
  322.     name = name.replace("{Wood}", wood);
  323.     name = name.replace("{Clay}", clay);
  324.     name = name.replace("{Iron}", iron);
  325.     name = name.replace("{AtkTroopsOriginal}", attackerTroopsOriginalString);
  326.     name = name.replace("{AtkTroopsLoss}", attackerTroopsLossString);
  327.     name = name.replace("{AtkTroopsRemain}", attackerTroopsRemainingString);
  328.     name = name.replace("{DefTroopsOriginal}", defenderTroopsOriginalString);
  329.     name = name.replace("{DefTroopsLoss}", defenderTroopsLossString);
  330.     name = name.replace("{DefTroopsRemain}", defenderTroopsRemainingString);
  331.     name = name.replace("{Cleared}", cleared);
  332.     name = name.replace("{%Lost}", percLost);
  333.     name = name.replace("{%Killed}", percKilled);
  334.     name = name.replace("{%ResHauled}", percResHauled);
  335.     name = name.replace("{%OfPossibleHaul}", percOfPossibleHaul);
  336.     name = name.replace("{Wall}", wall);
  337.     name = name.replace("{Loyalty}", loyalty);
  338.     /*console.log(name);*/
  339.    
  340.     $(".quickedit .rename-icon").click();
  341.     setTimeout(function(){ $(".quickedit input[type='text']").val(name); setTimeout(function(){ $(".quickedit input[type='button']").click(); }, 250); }, 100);
  342. }
Advertisement
Add Comment
Please, Sign In to add comment