The West - Item Set Manager

Manage your sets like a boss!

Versione datata 26/03/2015. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @namespace		https://greasyfork.org/users/8637
// @name        	The West - Item Set Manager
// @author      	neversleep1911
// @description		Manage your sets like a boss!
// @include     	http://*.the-west.*/game.php*
// @include     	https://*.the-west.*/game.php*
// @grant       	none
// @version     	1.0.2
// @copyright		Copyright (c) 2015 neversleep1911
// @license			MIT (http://opensource.org/licenses/MIT)
// ==/UserScript==

(function(func) {
    var script;
    script = document.createElement("script");
    script.setAttribute("type", "text/javascript");
    script.textContent = "(" + func.toString() + ")();";
    document.body.appendChild(script);
    document.body.removeChild(script);
})(function() {
    var Gui, I18n, ItemSetManager, ItemSetWindow, Recent;
    I18n = function() {
        var DEFAULT_LANGUAGE, STRINGS, language;
        function I18n() {}
        DEFAULT_LANGUAGE = "en_US";
        STRINGS = {
            en_US: {
                item_set_window: {
                    title: "Items"
                },
                messages: {
                    bag_is_not_loaded: "Bag is not loaded!"
                }
            },
            ru_RU: {
                item_set_window: {
                    title: "Предметы"
                },
                messages: {
                    bag_is_not_loaded: "Инвентарь не загружен!"
                }
            }
        };
        language = DEFAULT_LANGUAGE;
        I18n.language = function() {
            return language;
        };
        I18n.setLanguage = function(lang) {
            return language = STRINGS[lang] ? lang : DEFAULT_LANGUAGE;
        };
        I18n.tr = function(id) {
            var prop, properties, string, _i, _len;
            string = STRINGS[language];
            properties = id.split(".");
            for (_i = 0, _len = properties.length; _i < _len; _i++) {
                prop = properties[_i];
                if ((string = string[prop]) === void 0) {
                    break;
                }
            }
            return string || id;
        };
        return I18n;
    }();
    Gui = function() {
        function Gui() {}
        Gui.createMenuButton = function(options) {
            var button;
            if (options == null) {
                options = {};
            }
            button = $("<div class='menulink' title='" + options.title + "' />");
            if (options.image) {
                button.css("background-image", "url(" + options.image + ")");
            }
            button.hover(function() {
                $(this).css("background-position", "-25px 0px");
                return true;
            }, function() {
                $(this).css("background-position", "0px 0px");
                return true;
            }).on("click", options.onclick);
            $("div#ui_menubar").append($('<div class="ui_menucontainer" />').append(button).append('<div class="menucontainer_bottom" />'));
            return button;
        };
        Gui.createSelectbox = function(options) {
            var menu;
            if (options == null) {
                options = {};
            }
            menu = new west.gui.Selectbox();
            if (options.header) {
                menu.setHeader(options.header);
            }
            menu.setWidth(options.width || 175);
            if (options.height) {
                menu.setHeight(options.height);
            }
            if (options.onclick) {
                menu.addListener(options.onclick);
            }
            menu.elContent.css("overflow-y", "scroll");
            return menu;
        };
        return Gui;
    }();
    Recent = function() {
        function Recent() {}
        Recent.LSK_RECENT = "7d04d85e-cbc4-4d6f-acdc-7ccadcb24534";
        Recent.MAX_SIZE = 10;
        Recent.load = function() {
            return this.list = (localStorage.getItem(this.LSK_RECENT) || "").split(",");
        };
        Recent.push = function(value) {
            var i;
            i = this.list.indexOf(value);
            if (i !== -1) {
                this.list.splice(i, 1);
            }
            if (this.list.push(value) > this.MAX_SIZE) {
                this.list.shift();
            }
            localStorage.setItem(this.LSK_RECENT, this.list.join(","));
            return this.list.length;
        };
        return Recent;
    }();
    ItemSetManager = function() {
        ItemSetManager.prototype.ID = "tw_item_set_manager";
        ItemSetManager.prototype.NAME = "Item Set Manager";
        ItemSetManager.prototype.MENU_BUTTON_IMAGE = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAZCAYAAABzVH1EAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3QMfCxs7OcZVFwAADBZJREFUWMOd1cmP5sdZwPFvVf325d36fXud7pmensXjzObIjhMvMnHCGQ4gAQekiDM3BCdELkj5B+CCZIIESIgICRGyOAmOA5Zx7Iy3mfEsTM/0vr39vv2uv72KwzjmgBDjlFSHeh6pPqrSU0+JP/39a2Zvt0tr9hnubD3AjCbEfkTuTQmrGL+WkpSCRtRklGX0Byf4VcnQ1jSxoDTUwwaHJxM2Dnp08xQsRTuqUSUZCw2fq5da7O2mtOcXeLi1Sz6dUGu0GI81UVNj+aBTj0YcMJ1qxicDtJNSFgLtVUSFhROEHHcHHJyMOJ4WSFcSKRfLVHRqLuLPfusZc/ELz/DH3/o2e5VGlIAlKbVBGRtjbLRIsUxFhcRIg6MVuZC4JiBXJ0gURldoI/Etj6JMWKzBn/zRH3B442coL+D0ua/wwe2bHGZjjICqzHFFDAxJUwvb9am8MWUmsYygtDLcrIn2KqjGCCPRWlJRYds2SuQ03JgvXv4CD2+8hVpbqH3zBz96l/V+hhc5hIGPLyRBYGi4AZ6T0Ky71DCEnkU7dgktie0J/KDEd2zqUYAQFZawURIsDJPUUOY5v/nqZd69ucG//PQdJjJH+RbGFThG4yiLTORYtqbmOOTVhFhJWjUPI8CTIF2N74VgoMgSpPDA2ORZRZqWHB2M+doLZ7FA0J0MqRxFZMCXBcayiGox7fkW7dZTnFpt8ZOfrXPx4hquazOZJHRaEscyjHoJJ/0eG/snFCeCbtLDtQVVZfPerZvcefUaqtliLCc8PVPn+PgYS3goXyJr0AkazC8u4gUur33nBhcvnGYibJIy5enzEfXIQWmHg52HDByHOPQ5Pu5yIXI4Go+5s7fD/ewS6vkXnv/mD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Napoho3Nbf4b5k7HDMnw+8AAAAAASUVORK5CYII=";
        function ItemSetManager() {
            var self;
            self = this;
            TheWestApi.register(this.ID, this.NAME, "2.2", "2.2", "neversleep1911", "https://greasyfork.org/scripts/8596").setGui("Copyrights, changelog and other details see <a href='https://greasyfork.org/scripts/8596' target='_blank'>here</a>.");
            I18n.setLanguage(Game.locale);
            Recent.load();
            Gui.createMenuButton({
                title: this.NAME,
                image: this.MENU_BUTTON_IMAGE,
                onclick: function(e) {
                    self.onMenuButtonClick(e);
                    e.preventDefault();
                    return false;
                }
            });
            this.menu = Gui.createSelectbox({
                height: 500,
                onclick: function(value) {
                    self.onMenuItemClick(value);
                    return true;
                }
            });
            this.buildMenu();
        }
        ItemSetManager.prototype.onMenuButtonClick = function(e) {
            var offset;
            offset = $(e.target).offset();
            offset.left -= $(e.target).width();
            this.menu.show();
            this.menu.setPosition(offset.left, offset.top);
            return this;
        };
        ItemSetManager.prototype.onMenuItemClick = function(setId) {
            var css, invWasClosed, invWnd, self, set, wearWndDiv;
            self = this;
            set = west.storage.ItemSetManager.get(setId);
            if (Bag.loaded) {
                invWasClosed = wman.getById(Inventory.uid) ? false : true;
                if (wman.getById(Wear.uid)) {
                    if (wman.isMinimized(Wear.uid)) {
                        wman.reopen(Wear.uid);
                    }
                } else {
                    Wear.open();
                }
                if (invWasClosed) {
                    invWnd = wman.getById(Inventory.uid);
                    if (invWnd) {
                        invWnd.fireEvent(TWE("WINDOW_CLOSE"), invWnd);
                    }
                }
                if (ItemSetWindow.wnd) {
                    if (wman.isMinimized(ItemSetWindow.uid)) {
                        wman.reopen(ItemSetWindow.uid);
                    }
                    ItemSetWindow.wnd.bringToTop();
                } else {
                    wearWndDiv = $(wman.getById(Wear.uid).getMainDiv());
                    css = wearWndDiv.offset();
                    css.left += wearWndDiv.width();
                    css.width = 304;
                    css.height = wearWndDiv.height();
                    ItemSetWindow.open({
                        css: css
                    });
                }
                ItemSetWindow.setItemSet(set);
                setTimeout(function() {
                    Recent.push(setId);
                    self.buildMenu();
                }, 200);
            } else {
                new UserMessage(I18n.tr("messages.bag_is_not_loaded"), UserMessage.TYPE_ERROR).show();
            }
            return this;
        };
        ItemSetManager.prototype.buildMenu = function() {
            var i, img, item, menuItem, set, setId, sets, text, _i, _j, _k, _len, _len1, _len2, _ref;
            sets = west.storage.ItemSetManager.getAll().slice(0).reverse();
            if (Recent.list.length > 0) {
                _ref = Recent.list;
                for (_i = 0, _len = _ref.length; _i < _len; _i++) {
                    setId = _ref[_i];
                    for (i = _j = 0, _len1 = sets.length; _j < _len1; i = ++_j) {
                        set = sets[i];
                        if (setId === set.key) {
                            sets.splice(i, 1);
                            sets.unshift(set);
                            break;
                        }
                    }
                }
            }
            this.menu.removeAll();
            for (_k = 0, _len2 = sets.length; _k < _len2; _k++) {
                set = sets[_k];
                item = ItemManager.get(set.items[0]);
                img = $("<img />");
                img.attr("src", item.image);
                img.css({
                    position: "absolute",
                    width: 18,
                    height: 18,
                    left: 4
                });
                text = $("<span>" + set.name + "</span>");
                text.css("padding-left", 16);
                menuItem = $("<div />");
                menuItem.css({
                    overflow: "hidden",
                    "text-overflow": "ellipsis",
                    "white-space": "nowrap"
                });
                menuItem.append(img);
                menuItem.append(text);
                this.menu.addItem(set.key, menuItem, set.name);
            }
            return this;
        };
        return ItemSetManager;
    }();
    ItemSetWindow = function() {
        function ItemSetWindow() {}
        ItemSetWindow.uid = "item-set-window";
        ItemSetWindow.open = function(options) {
            if (options == null) {
                options = {};
            }
            if (!this.wnd) {
                this.wnd = wman.open(this.uid, null, "noreload");
                this.wnd.setTitle(I18n.tr("item_set_window.title"));
                this.wnd.addEventListener("WINDOW_DESTROY", function() {
                    ItemSetWindow.unlistenWearChagned();
                    delete ItemSetWindow.wnd;
                });
                if (options.css) {
                    $(this.wnd.getMainDiv()).css(options.css);
                }
                this.listenWearChagned();
            }
            return this;
        };
        ItemSetWindow.setItemSet = function(set) {
            var bagItem, invItem, invItemDiv, item, itemCount, itemId, timer, _i, _len, _ref;
            if (!ItemSetWindow.wnd) {
                return false;
            }
            this.set = set;
            timer = 0;
            ItemSetWindow.wnd.setMiniTitle(set.name);
            $(ItemSetWindow.wnd.getContentPane()).empty();
            _ref = set.items;
            for (_i = 0, _len = _ref.length; _i < _len; _i++) {
                itemId = _ref[_i];
                item = ItemManager.get(itemId);
                invItem = new tw2widget.InventoryItem(item);
                invItemDiv = $(invItem.getMainDiv());
                bagItem = Bag.getItemByItemId(itemId);
                itemCount = bagItem ? bagItem.getCount() : 0;
                invItemDiv.css({
                    border: "1px solid transparent",
                    "border-radius": 4
                });
                if (Wear.carries(itemId)) {
                    ++itemCount;
                    invItemDiv.css("border-color", "black");
                } else {
                    if (bagItem) {
                        (function(bagItem, invItemDiv) {
                            invItemDiv.on("click", function(e) {
                                if (!e.shiftKey) {
                                    if (timer) {
                                        clearTimeout(timer);
                                    }
                                    invItemDiv.off("click");
                                    invItemDiv.css("opacity", .5);
                                    ItemSetWindow.unlistenWearChagned();
                                    Wear.carry(bagItem);
                                    timer = setTimeout(function() {
                                        ItemSetWindow.setItemSet(set);
                                        ItemSetWindow.listenWearChagned();
                                        timer = 0;
                                    }, 1e3);
                                }
                                return true;
                            });
                        })(bagItem, invItemDiv);
                    } else {
                        invItemDiv.css("opacity", .5);
                    }
                }
                invItem.setCount(itemCount);
                ItemSetWindow.wnd.appendToContentPane(invItem.getMainDiv());
            }
            return this;
        };
        ItemSetWindow.listenWearChagned = function() {
            if (!this.listening) {
                EventHandler.listen("wear_changed", this.wearChangedHandler, this);
                this.listening = true;
            }
            return this.listening;
        };
        ItemSetWindow.unlistenWearChagned = function() {
            if (this.listening) {
                EventHandler.unlisten("wear_changed", this.wearChangedHandler, this);
                this.listening = false;
            }
            return this.listening;
        };
        ItemSetWindow.wearChangedHandler = function() {
            if (ItemSetWindow.set) {
                ItemSetWindow.setItemSet(ItemSetWindow.set);
            }
        };
        return ItemSetWindow;
    }();
    $(document).ready(function() {
        EventHandler.listen("itemmanager_loaded", function() {
            new ItemSetManager();
            return EventHandler.ONE_TIME_EVENT;
        });
        return true;
    });
});