// ==UserScript== // @name TW Accessible items // @namespace https://greasyfork.org/users/205257 // @version 0.1 // @description Add any item to be always visible on the main game screen // @author qwerfghj // @match https://*.the-west.com.br/game.php* // @match https://*.the-west.com.pt/game.php* // @match https://*.the-west.cz/game.php* // @match https://*.the-west.de/game.php* // @match https://*.the-west.dk/game.php* // @match https://*.the-west.es/game.php* // @match https://*.the-west.fr/game.php* // @match https://*.the-west.gr/game.php* // @match https://*.the-west.hu/game.php* // @match https://*.the-west.it/game.php* // @match https://*.the-west.net/game.php* // @match https://*.the-west.nl/game.php* // @match https://*.the-west.org/game.php* // @match https://*.the-west.pl/game.php* // @match https://*.the-west.ro/game.php* // @match https://*.the-west.ru/game.php* // @match https://*.the-west.se/game.php* // @match https://*.the-west.sk/game.php* // @grant none // @downloadURL none // ==/UserScript== (function(fn) { var newScript = document.createElement('script'); newScript.setAttribute("type", "application/javascript"); newScript.textContent = '(' + fn + ')();'; (document.body || document.head || document.documentElement).appendChild(newScript); newScript.parentNode.removeChild(newScript); })(function() { var scriptName = "TW Accessible items"; var scriptURL = "TODO"; var scriptAuthor = "qwerfghj"; var scriptObject = "AccessibleItems"; this[scriptObject] = { helpers: { item_by_id: function(item_id) { var base_id = ItemManager.itemIdToBaseItemId(item_id); return ItemManager.getByBaseId(base_id); }, item_name: function(item_id) { return this.item_by_id(item_id).name; } }, inventoryManager: { listeningSignals: [ 'inventory_loaded', 'inventory_changed', 'cooldown_changed', 'item_lifetime_changed', 'item_used' ], timeout: null, items: {}, init: function() { EventHandler.listen(this.listeningSignals, this.signalHandler, this); }, destroy: function() { clearTimeout(this.timeout); EventHandler.unlisten(this.listeningSignals, this.signalHandler, this); }, check: function() { $.each(this.items, function(item_id, item) { item.getMainDiv().css("display", "none"); }); clearTimeout(this.timeout); var that = this; $.each(AccessibleItems.settings.getItems(), function(item_id, position) { var invItem = Bag.getItemByItemId(item_id); if(invItem) { that.handleItem(invItem, item_id, position); } }); }, handleItem: function(item, id, position) { if (this.items[id] === undefined) { this.items[id] = new tw2widget.InventoryItem(item.obj); this.items[id].initDisplay(); var div = this.items[id].getMainDiv(); div.css("position", "absolute"); div.css("z-index", 1); var action = item.obj.action; this.items[id].getImgEl().click(function() { eval(action); }); this.items[id].setShowcompare(false); div.appendTo(document.body); } item.initDisplay(); if (item.elCooldown) { this.items[id].showCooldown(); item.elCooldown = item.elCooldown.add(this.items[id].elCooldown); } this.items[id].setCooldown(Bag.itemCooldown[id]); this.items[id].setLifetime(item.lifetime, true); this.items[id].setCount(item.getCount()); this.items[id].getMainDiv().css("left", position[0]); this.items[id].getMainDiv().css("top", position[1]); this.items[id].getMainDiv().css("display", "block"); }, signalHandler: function() { var that = this; this.timeout = setTimeout(function() { that.check(); }, 1000); } }, settings: { init: function() { if (!AccessibleItems.storage.exists("items")) { AccessibleItems.storage.add("items", { 2485000: [80, 217] }); } }, getItems: function() { return AccessibleItems.storage.get("items"); }, saveItems: function(items) { AccessibleItems.storage.add("items", items); AccessibleItems.inventoryManager.check(); AccessibleItems.script.fillGui(); }, add: function() { this.createEditDialog(); }, createEditDialog: function(init_id = 0, init_x = "", init_y = "") { var that = this; var preview_item = null; var removePreviewIfNot = function(item_id) { if (preview_item && preview_item.getId() !== item_id) { preview_item.getMainDiv().remove(); preview_item = null; } }; var id = new west.gui.Textfield().setTooltip("1234000 or [item=1234000]"); var x = new west.gui.Textfield(null, "number").setPlaceholder("left").setWidth(72).setValue(init_x); var y = new west.gui.Textfield(null, "number").setPlaceholder("top").setWidth(72).setValue(init_y); var d = new west.gui.Dialog(scriptName, '
Enter item id: | ||
Position: |
Items to display:
'; $.each(AccessibleItems.settings.getItems(), function(item_id, position) { html += ''; html += Game.TextHandler.parse("[item=" + item_id + "]"); html += " at position [" + position + "]"; html += ' (change)'; html += ' [remove].'; html += "
"; }); html += ' '; this.api.setGui(html); var script_window = wman.getById("scripts"); if (script_window) { if (script_window.currentActiveTabId == scriptObject) { script_window.fireActivateTab(scriptObject); } } } } }; $(function() { try { AccessibleItems.script.init(); } catch(x) { console.trace(x); } }); });