Request Outgoing Attack Re-namer

  • Thread starter DeletedUser118618
  • Start date

DeletedUser118618

Guest
Who would be kind enough to share an working Outgoing Attack Re-namer Script
 

Ibra Gonza II

Non-stop Poster
Reaction score
140
few days back I was indeed looking for the same thing, but couldn't find one. So I wrote my own. Feel free to use it (might be a bit late for you... but anyhow):

Code:
javascript:$.getScript('https://dl.dropboxusercontent.com/s/2bdabunmw6hf17t/TroopRename.js');void(0);

It works in the 'Commands --> Attacks' overview.

Suggestions for improvement are always welcome :)

 

DeletedUser117168

Guest
We have one too works fine from any place, it will redirect you to your commands overview. easy to edit the labels too

[spoil]
Code:
javascript: /*12-Jan-2015*/
var labels = {
    " FAKE": {
        "max-unit":2
    },
    " FARM": {
        "min-scout":100
    },
    " NUKE": {
        "min-pop":2000
    },
    " NOBLE": {
        "min-snob":1
    }
};


$.each(labels, function (name, criteria) {
    $.each(criteria, function (type, amount) {
        if (!type.match("min") && !type.match("max")) {
            alert("label error at: (" + type + ": " + amount + ")");
            void(0);
        }
    });
});


var url = document.URL;
var destination = "&mode=commands&screen=overview_villages&type=attack";
var iMode = url.indexOf(destination);


if (iMode == -1) {
    var keyUrl = url.indexOf("village=") + 8;
    var valUrl = parseInt(url.substr(keyUrl)).toString().length;
    var baseUrl   = url.substr(0, keyUrl + valUrl);
    document.location.href = baseUrl + destination;
    void(0);
};
    var label = null;
    var name = "";
    var AssessTroop = {
        available: {
            "spear":false,
            "sword":false,
            "axe":false,
            "archer":false,
            "spy":false,
            "light":false,
            "marcher":false,
            "heavy":false,
            "ram":false, 
            "catapult":false, 
            "knight":false,
            "snob":false
        },
        availableAmount: {
            "spear":0,
            "sword":0,
            "axe":0,
            "archer":0,
            "spy":0,
            "light":0,
            "marcher":0,
            "heavy":0,
            "ram":0, 
            "catapult":0, 
            "knight":0,
            "snob":0
        },
        unitIndex: [
            "spear",
            "sword",
            "axe",
            "archer",
            "spy",
            "light",
            "marcher",
            "heavy",
            "ram",
            "catapult",
            "knight",
            "snob"
        ],
        popAmount: {
            "spear":1,
            "sword":1,
            "axe":1,
            "archer":1,
            "spy":2,
            "light":4,
            "marcher":5,
            "heavy":6,
            "ram":5, 
            "catapult":8, 
            "knight":10,
            "snob":100
        },
        label:"",
        labels: labels,
        assessAvailibility: function(types) {
            $.each(types, function(i, type) {
                AssessTroop.available[type.src.match(/unit_(.*).png/)[1]] = true;
            });
            $.each(AssessTroop.available, function (key, value) {
                if (!value) {
                    AssessTroop.unitIndex.splice(AssessTroop.unitIndex.indexOf(key), 1);
                    delete AssessTroop.availableAmount[key];
                }
            });
        },
        assessTroop: function(troops) {
            AssessTroop.storeTroopAmount(troops);
            AssessTroop.matchTroopAmountWithLabels();
            if (AssessTroop.label.match("NUKE")) {
                AssessTroop.assessNukePower();
            }
            AssessTroop.insertTroopAmount();
            return AssessTroop.label;
        },
        assessNukePower: function() {
            AssessTroop.label = AssessTroop.label.concat(" " + Math.min((AssessTroop.totalPop() * 100 / 20500).toFixed(2), 100).toString() + "%");
        },
        insertTroopAmount: function() {
            AssessTroop.label = AssessTroop.label.concat(" (");
            $.each(AssessTroop.availableAmount, function (unit, amount) {
                if (amount > 0) {
                    AssessTroop.label = AssessTroop.label.concat(" " + unit);
                    AssessTroop.label = AssessTroop.label.concat(":" + amount);
                }
            });
            AssessTroop.label = AssessTroop.label.concat(" )");
        },
        storeTroopAmount: function(troops) {
            $.each(troops, function(i, troop) {
                AssessTroop.availableAmount[AssessTroop.unitIndex[i]] = parseInt(troop.innerHTML);
            });
        },
        matchTroopAmountWithLabels: function() {
            $.each(labels, function (name, criteria) {
                if (AssessTroop.troopMatch(criteria)) {
                    AssessTroop.label = AssessTroop.label.concat(name);
                }
            });
        },
        troopMatch: function(criteria) {
            var flag = true;
            $.each(criteria, function (type, amount) {
                if (type.match("min")) {
                    if (!AssessTroop.checkForMin(type, amount)) {
                        flag = false;
                    }
                } else {
                    if (!AssessTroop.checkForMax(type, amount)) {
                        flag = false;
                    }
                }
            });
            return flag;
        },
        checkForMin: function(type, amount) {
            type = type.match(/-(.*)/)[1];
            switch(type) {
                case "unit":
                return AssessTroop.totalUnit() >= amount;
                case "pop":
                return AssessTroop.totalPop() >= amount;
                default:
                return AssessTroop.availableAmount[type] >= amount;
            }
        },
        checkForMax: function(type, amount) {
            type = type.match(/-(.*)/)[1];
            switch(type) {
                case "unit":
                return AssessTroop.totalUnit() <= amount;
                case "pop":
                return AssessTroop.totalPop() <= amount;
                default:
                return AssessTroop.availableAmount[type] <= amount;
            }
        },
        totalPop: function() {
            var total = 0;
            $.each(AssessTroop.availableAmount, function (key, value) {
                total += value * AssessTroop.popAmount[key];
            });
            return total;
        },
        totalUnit: function() {
            var total = 0;
            $.each(AssessTroop.availableAmount, function (key, value) {
                total += value;
            });
            return total;
        },
        resetLabel: function() {
         AssessTroop.label = "";
        }
    };


    AssessTroop.assessAvailibility($("#commands_table img[alt][title]"));


    $.each($("#commands_table .nowrap"), function(i, command) {
        label = command.querySelector(".quickedit-label");
        if (label.innerHTML.match("Attack on")) {
            name = AssessTroop.assessTroop(command.querySelectorAll(".unit-item"));
            label.innerHTML = "                          " + name;
            command.querySelector(".rename-icon").click();
            command.querySelector(".btn").click();
            AssessTroop.resetLabel();
        }
    });
void(0);
[/spoil]
 

DeletedUser117392

Guest
Code:
javascript:$.getScript('https://dl.dropboxusercontent.com/u/15780029/twscripts/outgoingRenamer.js');void 0;

One of my friends wrote this script years ago. I am maintaining it now. Its not customizable but the predefined filter gives very good names. It is bit slow because tw support staff asked me to limit the rate of renames otherwise account may get temporary blocked. It renames at 2-3 commands per second. It skips LA commands. I am liking it so i use it. If you have any suggestions for improvement, let me know.
 
Top