Greasy Fork is available in English.

TheWest - Tamagotchi PG

Power up your character with the Tamagothi menu

Устаревшая версия на 22.11.2017. Перейти к последней версии.

// ==UserScript==
// @name         TheWest - Tamagotchi PG
// @namespace    http://www.petrucci.ch/_temp/thewest/
// @version      0.43
// @description  Power up your character with the Tamagothi menu
// @author       Adriano
// @license      LGPLv3
// @include      http*://*.the-west.*/game.php
// @include      http*://*.the-west.*.*/game.php*
// @include      http*://*.tw.innogames.*/game.php*
// @grant        none
// ==/UserScript==

function appendScript(fn) {
	var newScript = document.createElement('script');
	newScript.setAttribute("type", "application/javascript");
	newScript.textContent = '(' + fn + ')();';
	document.body.appendChild(newScript);
	document.body.removeChild(newScript);
}
appendScript(function() {
    //'use strict';
    var VERSION = 0.43;
	var URL_INSTALL = "https://greasyfork.org/scripts/35553-thewest-tamagotchi-pg";
	var URL_CODE = "https://greasyfork.org/scripts/35553-thewest-tamagotchi-pg/code/TW%20Friends.user.js";
	var scriptAuthor = "Adriano";
	var scriptCredits = '<span style="display: inline-block; vertical-align: middle;">TW Friends for the base script, Adriano (Tiger54) for this script<br />.</span>';
	var scriptName = "Tamagotchi PG";
	var scriptObject = "TamagotchiPG";
	this[scriptObject] = {
        options: {
            hide0Items : false,
            init: function()
            {
                var decodedCookie = decodeURIComponent(document.cookie);
                var ca = decodedCookie.split(';');
                for(var i = 0; i <ca.length; i++) {
                    var c = ca[i];
                    while (c.charAt(0) == ' ') {
                        c = c.substring(1);
                    }
                    if (c.indexOf("hideitems=") == 0) {
                        this.hide0Items = (c.substring("hideitems=".length, c.length) != 'false');
                    }
                }
                var desc = TamagotchiPG.localeManager.getMsg('description');
                desc = desc.replace("[OPTIONS]", "<input type='checkbox' " + (this.hide0Items?"checked":"") + " onclick='TamagotchiPG.options.hide0Items=this.checked;TamagotchiPG.options.save();'> &nbsp; " + TamagotchiPG.localeManager.getMsg('opt_hide0elements') + "<br>");
                TamagotchiPG.script.api.setGui(desc);
            },
            save: function()
            {
                var d = new Date();
                var exdays = 365;
                d.setTime(d.getTime() + (exdays*24*60*60*1000));
                var expires = "expires="+ d.toUTCString();
                document.cookie = "hideitems=" + this.hide0Items.toString() + ";" + expires + ";path=/";
                this.init();
            },
        },
        toolbar: {
            div1: null,
            menuicons : [],
            menutitles : [],
            init : function()
            {
                this.menutitles.push(TamagotchiPG.localeManager.getMsg("menu_energy"));  this.menuicons.push("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAGASURBVDhPY2QgADTnX+gDKkqBclHAfwaGOQQN0Jh3/tPmWAPer0DVyIAbqNN38YXPBA1QnXeuD2gXiguSAw14566/8JmBgXEOVIg4oDz39Kf57//8B9HKc04BDWZgYALLEAEUZh3v+/v3LwPXv38MIPpuilkRSJxoA/7+/5+yMMyIt2TNmc9AI+BOJ8oAqRmH+/79/8Pw7NsfBhD9KM0abDsIEAxEyRkH+hiAti8LseCNWnMCGHBIgJFxDiOueAbF8fVEgyKxaXs/rQiy5D37/icDLwsTgxovKwMvKxOYbbf08GdGjXnngPFsiBLPkDg+//lGkhGf8LQ9fYxAF0ClUMB/kAuU55zpA3oEriAlwIB3zgZgHP9nmHM3xQTuV7wAFEXys058mvvq538QDeJDpQgCRplZh4GBxJCyMcKc13/FSUQgMTLMeZJmS9gFEtP3f9r/6vv/npsf/s+8++k/iH3j06//IHGoEryAURQYSOhpHQIY57zOciEuDMgHDAwASoGne8UPddgAAAAASUVORK5CYII=");
                this.menutitles.push(TamagotchiPG.localeManager.getMsg("menu_live"));    this.menuicons.push("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAK9SURBVDhPZVFNSFRRFD73vvv+dP5/TA2LyFoMhkGZNtgiWtYiWkm1CwkXQYuWRT/Qpto2tYySWmUQCNFCcBU5i5FwkaILLTAzdd78vnnvvnc7943NWH2Xj3ff5ZzvnO8cArtYvnLsnNnbc72jtyejGIbl1WszvFx5n777Lr8bAmvXRhJqLBy1Q876ofuztnwLBBYvHXmgxaJ34kMnoKO/H5RwCITngbO+7tqrq1Pb8wsv3XL5fOr0qQuqoad4ubrIS9aT7kcfX5OvF/uvcrv+KjGQgejgAGipFFBNA6JqIIQPvlWEytIKcMeFSOYoUHzjpTLUf/yE2s72mDLeTZ8zXe/Tk3FgGgNh18ErWcCLRfCsHfy3gZkGClIQDQeEg+QciBDg1+z9pJCNrKnhcF+orwfMrnQzmFI01xpPcBe+hxRAFSV48hwOjaL1ncyPxgqEKceNeAz0eBSYgQIKCjTHA+ij+UUIvAfiIFDABduqLJDCaOIxTuwWM/SguqKqWGWPwB4IPASP7ISjFe7wpySfjRxWQMwRQhIEKFDaTvxfQoo0BXzfq1FBR4KY/HBoglGS87kHvoNEv7L1fwVabhSGJLeHC/bDVkz+ZGeOMjLhVnH/VRc9opDMaI8gANUo6Kb6ttHVGDs7C1yaDWDWqjeZC5NmJ6rrKthcgUqNQKkCYCFLVaxFVEgY+ozHGuMyWeY1d4LIbYK3L+5Md/sslQypQ9gAVGwfbBfARzPJCIMVpkxPNezLN5ZhZzetLSAxuwn+iw33A25KOZNWszhYygWBdFSFGR/e3PvWmPhcgiKGtoz9EZCzMJFp5ME5y1tZqotitosNxjsV7dmWO5nbcHPYjLQs6SCxx/am5GMYGUMmkXGkecCgmRgD/UvF/4T/v5BbSNlBDfmXgITsRkXiFIO7FJVBWDiAHJrknr0A/AaAiiZKS6khhwAAAABJRU5ErkJggg==");
                this.menutitles.push(TamagotchiPG.localeManager.getMsg("menu_work"));    this.menuicons.push("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAIvSURBVDhPY6AUMEJpOFi1ahUbLy+v47+/DP4MDP89GRj/Sf37/4+F8d+/M39+M/QHBAesgCoFAwwD1q5d+wFIff/D8O8X03+Gr4z/GVVMzUxY+XgFGG7fucVw9879/cwsjB5hYWG/IDoIgNmzl4nPnDHj56f3H////PHr/+kzp//PnTv3CFSagQlK4wTffnzar6GjzfbpyyeGt2/fM6goqzIwMTFaz5kzhxckzwxWhQNcWp0Weu8tRxIHlwALHz8fw6NHDxjWrV//RUdbj+3Bg/v5jo6OTBhhAANnlyV08QgIl0qrOzJMXX6UgV9MmeHFsyfPGBkZwxgYGddYWVlIHNh/+ANWLxxbENXOxiVYqqBtx/Dn8QEGR/nHDLramgz///+Xra+vP/rv71/VA/v3//z583skVAsC7Jsa1n56ec7/b7fX/H+6Mfn//ulh/w9MD3SFSsNBcXGxPIhG8cLWPr8OHiHJchNrJ4Zn5zYz3H7+lYHh3293r6Itu6BKMADcC2tbPNvZuYTKDUwcGR4cXcNw5f5bhm9fvnng0wwCYBcsrXHs5BeWKrOy82a4f3IFw62XX4AW//OIbjuwE6wKD2CcXWjTLSQhWeLo5Mdw49AShpsvvjP8/f/HPaXnGF6bYYCJX0iyxNYpgOHK3oUM5x98Yvj68bsnsZpBgOnr188MF3bOYTh//yPDz6/f3HNmnd4BlSMKML16+8r44oPP237/+GFSNO8i0TZDAAMDAHNc5AhTlzLSAAAAAElFTkSuQmCC");
                this.menutitles.push(TamagotchiPG.localeManager.getMsg("menu_duel"));    this.menuicons.push("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAL7SURBVDhPpZLtS9NRFMe/d9vPzXRjLlvLXJsxl9rDLBMtehPVoCwiSMPeFFFJUQS+iCx67g8Ie5c9kVBEWZT1RiyVtCAte9A0NcVnck9u6tzDb7/TnduLqN5En8u553I438M991z8L/K4j5GTk5AmrNymUVlsU/7+r9HQ+vwD947uPHJ/IUzl3WMdDgnh9rnc31GnZVm3m8o+Pz3REHl2pUnKzdjalJVmf/HhUh9RBdHr1DZaxvJcPFUTU/yKwWDaqz0+6FC6iPKI6DZR3f6PdMP0iiYLZqkN36jW+J4q1lRRutbawhWqmDDeQqrKeOrs5LmiFaIFvvEInHUElTQKs2cMXf1edJnDCC6VI1u9CouFTGObu8kSivhrolpZdPNNOtNbNK34muLCiPADUvEZmO/YYa0rQaTgCdxeJWbGA3A4XbBIubCqVm/lsoyoFnq5+VZl4fVIz4VR+pbvpImSMt4DYva4kFz2D9S3Y5oa1vdQVXorHTdcI53cMMSlxrkCJ3XnQ569fmpf852ahS/UX7afJqpzyX+4gkLzR4jUvJaNyFcUpGO685ISyT1IwqY5MYcd05TPFEvF8zwJAai2GNHW6sbiIYbNoo3nKXiKH4x7p96HQ7Z96LA2Tkn+hAF391Q13kpX5f3B3rVauSk7Y1cehh0ejL93wChpkMgIITaLABNBSERNYi0aD95FYaleqcxULPQqA1uCnaIgD0EyZqo32tUzizDwbhgyivAZJUJk/Mvwh5AhGW8Mb3FJOC1Op84ytkRkjpAPXm+Qie8khSI6hsBkABOeKYh8udkoBlkHVksbeCEZOvEQ9aWP4FY7KHxXHJxlChNlh1mgWSL8QPRPQDcfaZ9KcY7KUEnZWBeRMXnvEqxw6mHy8meqTcib98b8YBUp7JrvSFLcRKYwjCT2lGv10QJR9AooazTQjfPzQ246blpusVkDi8yXl86YKi0Sv9aeeOyvJMf9HyzYnfJyebWFZBlCfTz0j6hRIKTLnrMkdjEe4QA/ATH/RfylZOdeAAAAAElFTkSuQmCC");
                this.menutitles.push(TamagotchiPG.localeManager.getMsg("menu_speed"));   this.menuicons.push("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAJsSURBVDhPjZNPSFRRFMZ/b96oOTYjo2hiJi0yK8ypSWqhgmMQmIIFuUiqhWkJBq2iiKJNiyiCIINSKwhqE0RDRQqhUZAIilqi9gcrUYREU1PTmd5M576ZMRWsPt7h/jnfOffe75yn8Z84tp0cw09DIIBL16HhHWasTP+NKhd7LDqvSsprUspPXCBgzJM40ZffOco9S5jzV/h9NFWevkayw0bjxUPkeopxJDh2V23FbV7juIv1Pj8fgwGswSDItwC5MpvdWXjyCmh/UMvnWUhISyUzx8ML7320ikzsAQtTh0+eYYs7d0mwgrnWLDw7V4xFkvVMQNc3ajKcXJ83aNWOZvGwcF/ZgY3rkulvus3sxBzaMmklHtGAKCt0j8LVNuJlO0Ns0iJaHsgrKOTDkxtoxhx2cSlzLLLVdnCmJhG/JonvP82cU2IdYp+0imy+yrvTnbGQvwFeD0hplt1A6YI1moNle6mtf8zdnlAJFax33lIsY0yFi3abJFEntA1RGh9NnFxdF2GNSR8zO1N8Xps9LhS1CKqMPWIdKmXsqtBG7xhNrSN43wzzSI1qrYsjJlr7c3QY5loaxWMYNBuisiJG6XhudfPSZIRRmU3Q75cAiVCdqFspquukUXQ139hcffYKxtgweuJa6i6dapHtJYcpHWrOXw5z0hTnuWxrWrVbMv+C0l3p3Hw6SHVJOt62QbNkkXKq4BU54t9RtY12T6Z0mA3GpdNa3kN9Fzmh8BBW4qifacSmMzA9x/7eEfgyLqqOcmToB43KFzFnHOOT0xRFOH3CGRRO5J2qPptCUxN9YnLOEkhLIZ2ygH5g5jfv5N3Eg1pTpAAAAABJRU5ErkJggg==");
                this.menutitles.push(TamagotchiPG.localeManager.getMsg("menu_special")); this.menuicons.push("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAHZSURBVDhPY2TAAXh5ec9KSkoKA5ksr1+//vX+/XsliAwqYILSKICLi8uIiYlJWFlZWR4IpJmZmfkkJCRModIoAKsBQNtTli1bJqumpsagpaXFMHnyJGEpKalqqDRRQMTKyurwgwcP/l+7evW/v7//a5AYRAoVYHUBELxhYWH5CWUzsLKy/gFSbyA8VIDLAKIBLgPEgDHAD2IAA5BBUECAFyQG4hMFREREuk6dOvULFAb379//v3PH9v+6uroLodIEAa+7u/txkOYLFy78j4tIuO1o4PlIjFf6FUgOogQBMBISGxNHpaqceqIgh+ivH6/+MVtw+qrwMAuw3P557f/hd8t6X/1+WgpVCgboBrApsGvvjZYps/kPCnck8OnfJ4Zd7xY/v/X1lAKQ+wsiihaIrEysCfZCQVoMbJgpnJuRm0Gdy0yCl0kkCyoEBsgGMIqyyEZIC6gJ/f/2HyqEAMyMzAzS7CqMouzSeUAu3AZkA6QVOLREGP9jaoYDoDZRNjlxIEsKIoBqwJMrX49duPXu/DMoHw5+AwPk/d/3DPe+X/734Pulw0ChpxAZzEBkZGJijZRglYvmYRZUZGFk5QTawfaP4e+/738/PX/96/G0b/8+g9ID1JkMDAC5gYpHMXGa0wAAAABJRU5ErkJggg==");
            },
            closeDefault : function()
            {
                if(typeof CharacterWindow.window != 'undefined' && CharacterWindow.window !== null) CharacterWindow.window.destroy();
                return true;
            },
        },
        powerItems: {
            subdivs : [],
            riposo : [],
            vita : [],
            lavoro : [],
            duello : [],
            createFunc : function (msg) {return function(){$.globalEval(msg);};},
            createFunc2 : function (index, div) {
                return function() {
                    TamagotchiPG.powerItems.showItems(index, ([
                        TamagotchiPG.powerItems.riposo,
                        TamagotchiPG.powerItems.vita,
                        TamagotchiPG.powerItems.lavoro,
                        TamagotchiPG.powerItems.duello]
                                                             )[index], div);
                };
            },
            move : function(qty, div) {
                var currLeft = parseInt(div.style.left) / 61;
                if(currLeft - qty > 0) qty = currLeft;
                if(div.childNodes.length <= -(currLeft - qty)) qty = 0;
                if(qty !== 0)
                {
                    var single = qty / Math.abs(qty);
                    div.style.left = ((currLeft - single) * 61) + "px";
                    if(single != qty) setTimeout(function(){TamagotchiPG.powerItems.move(qty - single, div);}, 40);
                }
            },
            showItems : function(el, arr, div) {
                for(var j=0;j<this.subdivs.length;j++) this.subdivs[j].style.opacity = "0.5";
                this.subdivs[el].style.opacity = "1.0";
                while(div.childNodes.length > 0) div.removeChild(div.childNodes[0]);
                div.style.left = "0px";
                var t = new ServerDate().getTime()/1000;
                var hideItems = TamagotchiPG.options.hide0Items;
                for(j in arr)
                {
                    if(!(!isNaN(parseFloat(arr[j])) && isFinite(arr[j]))) continue;
                    var it = ItemManager.get(arr[j]);
                    if(it === null || it.name === null || it.name =='undefined')
                    {
                        console.error("TW-Tamagotchi Script: Item " + arr[j] + " not found");
                        continue;
                    }
                    var bagItem = Bag.getItemByItemId(arr[j]);
                    var itemCounts = (bagItem !== null && typeof bagItem !=='undefined' && bagItem.count != 'undefined') ? bagItem.count : 0;
                    var divi = document.createElement("div");
                    divi.className = "item item_inventory not_upgradeable hasMousePopup";
                    var img = document.createElement("img");
                    img.className = "tw_item item_inventory_img dnd_draggable";
                    img.setAttribute("src", "https://westit.innogamescdn.com/" + it.image );
                    var cooldownvar = false;
                    var span = null;
                    if(itemCounts > 0)
                    {
                        var itemCooldown=Bag.itemCooldown[arr[j]],globalCooldown=bagItem.obj.has_cooldown?Character.cooldown:0,cooldown=Math.max(itemCooldown||0,globalCooldown||0);
                        img.addEventListener("click", this.createFunc(it.action));

                        if(parseInt(bagItem.cooldown) > 0 || parseInt(cooldown) > 0)
                        {
                            cooldownvar = (parseInt(bagItem.cooldown) > 0)?bagItem.cooldown:cooldown;
                            if(t < cooldownvar)
                            {
                                span = document.createElement("span");
                                span.className = "cooldown";
                                span.setAttribute("style", "display:block;");
                                span.appendChild(document.createTextNode((cooldownvar - t).getTime2EndShort()));
                            }
                        }
                    }
                    else if(hideItems) continue;
                    var tt = new ItemPopup(it,{show_buffs:false,show_compare:false,show_alreadyown:false,traderCharge:false,show_setboni:true,character:this.character,show_sell_price:true,show_lifetime:false,show_cooldown:cooldownvar});
                    tt.bindTo(img);
                    divi.appendChild(img);
                    var spa = document.createElement("span");
                    spa.className = "count";
                    spa.setAttribute("style", "display:block;");
                    spa.appendChild(document.createTextNode(itemCounts));
                    divi.appendChild(spa);
                    if(span !== null) divi.appendChild(span);
                    div.appendChild(divi);
                }
            },
            init : function() {
                this.riposo.push(1928000);     // sacco a pelo 15%R 15%L
                this.riposo.push(1971000);     // calumet 100%R
                this.riposo.push(1997000);     // arrosto 100%R 100%L
                this.riposo.push(2130000);     // tè maté 100%R 20%L 20%D
                this.riposo.push(17028000);    // barattolo spinaci 100%R 100%V 100%L 100%D
                this.riposo.push(2129000);     // guaranà 50%R 10%L 10%D
                this.riposo.push(16100000);    // borsa medico 40%R 25%V
                this.riposo.push(2128000);     // caffé 25%R 5%L 5%D
                this.riposo.push(1890000);     // tè 20%R
                this.riposo.push(1969000);     // whiskey invecchiato 20%R
                this.riposo.push(1970000);     // torta di ciliegie 20%R
                this.riposo.push(2356000);     // birra 15%R
                this.riposo.push(13704000);    // liquore qualità 15%R
                this.riposo.push(2294000);     // colore blu 15%R
                this.riposo.push(2670000);     // tamales 15%R
                this.riposo.push(12704000);    // pan pepato 15%R
                this.riposo.push(2525000);     // inchiostro 15%R 15%V
                this.riposo.push(1898000);     // acqua di rosa 15%R 25%V
                this.riposo.push(2485000);     // sacco riposo 10%R
                this.riposo.push(1943000);     // fagioli cotti 10%R
                this.riposo.push(2358000);     // salsiccia 10%R 10%V
                this.riposo.push(13706000);    // arancia 10%R 10%V
                this.riposo.push(12706000);    // marzapane 10%R 10%V
                this.riposo.push(2672000);     // bambola 10%R 10%V
                this.riposo.push(2296000);     // fuoco artificio 10%V 10%R
                this.riposo.push(185205000);   // uovo pasqua 10%R 10%V
                this.riposo.push(255000);      // insalata pomodori 10%R 10%L
                this.riposo.push(1892000);     // liquore fruttato 10%R 15%V
                this.riposo.push(1985000);     // liquore squisito 10%R 15%D
                this.riposo.push(1937000);     // zaino 5%R
                this.vita.push(17028000);      // barattolo spinaci 100%R 100%V 100%L 100%D
                this.vita.push(2117000);       // liquido 75%V
                this.vita.push(1974000);       // elisir 50%V
                this.vita.push(2116000);       // linfa 25%V
                this.vita.push(16100000);      // borsa medico 40%R 25%V
                this.vita.push(1898000);       // acqua di rosa 15%R 25%V
                this.vita.push(2295000);       // colore bianco 20%V
                this.vita.push(2357000);       // crauti 20%V
                this.vita.push(2671000);       // pan muertos 20%V
                this.vita.push(12705000);      // tortino 20%V
                this.vita.push(13705000);      // fagioli e pancetta 20%V
                this.vita.push(185204000);     // uovo pasqua 20%V
                this.vita.push(2734000);       // lanterna 20%V 20%D
                this.vita.push(1892000);       // liquore fruttato 10%R 15%V
                this.vita.push(2525000);       // inchiostro 15%R 15%V
                this.vita.push(2358000);       // salsiccia 10%R 10%V
                this.vita.push(12706000);      // marzapane 10%R 10%V
                this.vita.push(2296000);       // fuoco artificio 10%V 10%R
                this.vita.push(13706000);      // arancia 10%R 10%V
                this.vita.push(2672000);       // bambola 10%R 10%V
                this.vita.push(185205000);     // uovo pasqua 10%R 10%V
                this.vita.push(1883000);       // medicina stomaco 10%V
                this.lavoro.push(2484000);     // sacco motivazione 10%L 10%D
                this.lavoro.push(1997000);     // arrosto 100%R 100%L
                this.lavoro.push(2391000);     // zucca 100%L 100%D
                this.lavoro.push(17028000);    // barattolo spinaci 100%R 100%V 100%L 100%D
                this.lavoro.push(1934000);     // pomello da sella 30%L 30%D
                this.lavoro.push(1984000);     // lozione capelli 20%L
                this.lavoro.push(185200000);   // uovo pasqua 15%L
                this.lavoro.push(1891000);     // tabacco 25%L
                this.lavoro.push(2130000);     // tè maté 100%R 20%L 20%D
                this.lavoro.push(2353000);     // pretzel 15%L
                this.lavoro.push(2667000);     // mezcal 15%L
                this.lavoro.push(13701000);    // pomodoro 15%L
                this.lavoro.push(12701000);    // liquirizia 15%L
                this.lavoro.push(2291000);     // fuoco artificio 15%L
                this.lavoro.push(1928000);     // sacco a pelo 15%R 15%L
                this.lavoro.push(2516000);     // hushpuppy 15%L 15%D
                this.lavoro.push(2706000);     // coniglio 10%L
                this.lavoro.push(2707000);     // coniglio 10%L
                this.lavoro.push(2129000);     // guaranà 50%R 10%L 10%D
                this.lavoro.push(255000);      // insalata pomodori 10%R 10%L
                this.lavoro.push(1939000);     // sigarette con filtro 7%L 7%D
                this.lavoro.push(2128000);     // caffé 25%R 5%L 5%D
                this.duello.push(2484000);     // sacco motivazione 10%L 10%D
                this.duello.push(2391000);     // zucca 100%L 100%D
                this.duello.push(17028000);    // barattolo spinaci 100%R 100%V 100%L 100%D
                this.duello.push(1934000);     // pomello da sella 30%L 30%D
                this.duello.push(2734000);     // lanterna 20%V 20%D
                this.duello.push(2130000);     // tè maté 100%R 20%L 20%D
                this.duello.push(2355000);     // pan zenzero 15%D
                this.duello.push(185202000);   // uovo pasqua 15%D
                this.duello.push(2294000);     // colore rosso 15%D
                this.duello.push(2669000);     // calavera 15%D
                this.duello.push(13703000);    // sigarette 15%D
                this.duello.push(12703000);    // petardo 15%D
                this.duello.push(1985000);     // liquore squisito 10%R 15%D
                this.duello.push(2516000);     // hushpuppy 15%L 15%D
                this.duello.push(1882000);     // spazzola tubolare 10%D
                this.duello.push(1952000);     // sacco del cibo 10%D
                this.duello.push(1988000);     // fondina 10%D
                this.duello.push(2129000);     // guaranà 50%R 10%L 10%D
                this.duello.push(1939000);     // sigarette con filtro 7%L 7%D
                this.duello.push(2128000);     // caffé 25%R 5%L 5%D
                // ultimo inserito: petardo
            },
        },
        localeManager: {
			localeDefault: 'en_US',
			localeScript: 'en_US',
			getMsg: function(msg) {
				if(undefined !== this.languages[this.localeScript][msg]) return this.languages[this.localeScript][msg];
				if(undefined !== this.languages[this.localeDefault][msg]) return this.languages[this.localeDefault][msg];
				return '';
			},
            checkLanguages: function() {
				var langs = Object.keys(this.languages), messages = Object.keys(this.languages[this.localeDefault]), that = this;
				$.each(messages, function(i, msg) {
					$.each(langs, function(j, lang) {
						if(!that.languages[lang].hasOwnProperty(msg)) console.log('Missing '+lang+'.'+msg);
						else if(typeof that.languages[that.localeDefault][msg] == "object") {
							$.each(Object.keys(that.languages[that.localeDefault][msg]), function(k, msg2) {
								if(!that.languages[lang][msg].hasOwnProperty(msg2)) console.log('Missing '+lang+'.'+msg+'.'+msg2);
							});
						}
					});
				});
				$.each(langs, function(i, lang) {
					$.each(Object.keys(that.languages[lang]), function(j, msg) {
						if(!messages.includes(msg)) console.log('Obsolete message '+lang+'.'+msg);
						else if(typeof that.languages[lang][msg] == "object") {
							$.each(Object.keys(that.languages[lang][msg]), function(j, msg2) {
								if(!that.languages[that.localeDefault][msg].hasOwnProperty(msg2)) console.log('Obsolete message '+lang+'.'+msg+'.'+msg2);
							});
						}
					});
				});
			},
			setLocale: function(localeSelected) {
				this.localeScript = (undefined !== this.languages[localeSelected]) ? localeSelected : this.localeDefault;
			},
            languages: {
				en_US: {
					description: '<h1>The West - Tamagotchi PG</h1><p style="margin: 8pt;">Add a Tamagothi Toolbar over your PG</p><p style="margin: 8pt;">You will be able to use consumables ordered by type:</p><ul style="list-style: disc outside; margin-left: 16pt; padding-left: 16pt;"><li>Energy</li><li>Live</li><li>Working points</li><li>Duels points</li></ul><p style="margin: 8pt;"><b>Credits</b>: '+scriptCredits+'</p><p style="margin: 8pt;"><b>Options</b>: <span style="display: inline-block; vertical-align: middle;">[OPTIONS]</span></p>',
					version: 'version',
					version_checkFailed: 'Unable to check for updates',
					version_checkManual: 'Check manually',
					version_ok: 'You already have the latest version',
					version_upgrade: 'A new version is available. Do you want to upgrade now?',
					refresh: 'Refresh',
                    opt_hide0elements: 'Hide elements that are not in inventory',
                    menu_live : 'Live points',
                    menu_energy : 'Energy points',
                    menu_work : 'Work motivation',
                    menu_duel: 'Duel motivation',
                    menu_speed: 'Speed',
                    menu_special: 'Special items',
				},
                it_IT: {
					description: '<h1>The West - Tamagotchi PG</h1><p style="margin: 8pt;">Aggiungi un menu in stile Tamagotchi al tuo PG</p><p style="margin: 8pt;">Potrai usare in modo semplice i consumabili ordinati per:</p><ul style="list-style: disc outside; margin-left: 16pt; padding-left: 16pt;"><li>Riposo</li><li>Vita</li><li>Motivazione lavoro</li><li>Motivazione duello</li></ul><p style="margin: 8pt;"><b>Credits</b>: '+scriptCredits+'</p><p style="margin: 8pt;"><b>Opzioni</b>: <span style="display: inline-block; vertical-align: middle;">[OPTIONS]</span></p>',
					version: 'versione',
					version_checkFailed: 'impossibile cercare aggiornamenti',
					version_checkManual: 'Cerca manualmente',
					version_ok: 'Possiedi la versione più recente',
					version_upgrade: 'E\' disponibile una nuova versione, aggiornare ora?',
					refresh: 'Aggiorna',
                    opt_hide0elements: 'Nascondi gli elementi non presenti in inventario',
                    menu_live : 'Punti vita',
                    menu_energy : 'Punti riposo',
                    menu_work : 'Motivazione lavoro',
                    menu_duel: 'Motivazione duello',
                    menu_speed: 'Velocità',
                    menu_special: 'Oggetti speciali',
				}
            },
        },
        script: {
			api: null,
			listeningSignal: 'game_config_loaded',
			loaded: false,
			init: function() {
				var that = this;
				if(this.loaded) return false;
				EventHandler.listen(this.listeningSignal, function() {
					that.init();
					return EventHandler.ONE_TIME_EVENT;
				});
				if(!!(Game && Game.loaded)) {
					this.loaded = true;
					TamagotchiPG.localeManager.setLocale(Game.locale);
					this.api = TheWestApi.register(scriptObject, scriptName, VERSION.toString(), Game.version.toString(), scriptAuthor, URL_INSTALL);
                    TamagotchiPG.options.init();
                    TamagotchiPG.powerItems.init();
                    TamagotchiPG.toolbar.init();
                    var j;
                    AnimatedCharacter.getElement()[0].addEventListener("click", function(e) {
                        e.preventDefault();
                        if(TamagotchiPG.toolbar.div1 !== null)
                        {
                            for(var h1 in TamagotchiPG.toolbar.div1.childNodes)
                            {
                                if(e.target == TamagotchiPG.toolbar.div1.childNodes[h1]) return TamagotchiPG.toolbar.closeDefault();
                                for(var h2 in TamagotchiPG.toolbar.div1.childNodes[h1].childNodes)
                                {
                                    if(e.target == TamagotchiPG.toolbar.div1.childNodes[h1].childNodes[h2]) return TamagotchiPG.toolbar.closeDefault();
                                    for(var h3 in TamagotchiPG.toolbar.div1.childNodes[h1].childNodes[h2].childNodes)
                                    {
                                        if(e.target == TamagotchiPG.toolbar.div1.childNodes[h1].childNodes[h2].childNodes[h3]) return TamagotchiPG.toolbar.closeDefault();
                                    }
                                }
                            }
                            try
                            {
                                AnimatedCharacter.getElement()[0].removeChild(TamagotchiPG.toolbar.div1);
                                TamagotchiPG.toolbar.div1 = null;
                                TamagotchiPG.powerItems.subdivs = [];
                                return TamagotchiPG.toolbar.closeDefault();
                            }
                            catch(err){}
                        }
                        var div3 = document.createElement("div");
                        div3.setAttribute("style", "width:305px;height:60px;display:block;margin-left:20px;overflow:hidden;");
                        var div2 = document.createElement("div");
                        div2.setAttribute("style", "width:3000px;max-height:60px;padding-left:0px;left:0px;position:relative;");
                        div3.appendChild(div2);
                        TamagotchiPG.toolbar.div1 = document.createElement("div");
                        TamagotchiPG.toolbar.div1.setAttribute("style", "width:342px;border-radius:10px;overflow:hidden;height:60px;display:block;left:" + AnimatedCharacter.getElement()[0].style.left + ";top:" + AnimatedCharacter.getElement()[0].style.top + ";transform:translate(-120px,-146px);");
                        TamagotchiPG.toolbar.div1.className = "work hasMousePopup";
                        var divbg = document.createElement("div");
                        divbg.setAttribute("style", "background-color:black;opacity:0.3;width:342px;height:60px;position:absolute;left:0px;top:0px;");
                        TamagotchiPG.toolbar.div1.appendChild(divbg);

                        var table = document.createElement("div");
                        table.setAttribute("style","cursor:pointer;display:block;position:absolute;font-size:12px;margin-left:5px;margin-top:2px;float:left;width:16px;");
                        for(var k=0;k<4;k++)
                        {
                            var td = document.createElement("div");
                            var imgi = document.createElement("img");
                            td.setAttribute("style","width:15px;height:14px;opacity:0.5;margin:0px;display:block;background-size:cover;");
                            td.addEventListener("click", TamagotchiPG.powerItems.createFunc2(k, div2));
                            imgi.setAttribute("src", TamagotchiPG.toolbar.menuicons[k]);
                            imgi.setAttribute("style", "width:10px;height:10px;margin:1px;margin-left:2px;");
                            imgi.className = "tw_item item_inventory_img dnd_draggable";
                            imgi.setAttribute("title", TamagotchiPG.toolbar.menutitles[k]);
                            td.appendChild(imgi);
                            td.className = "item item_inventory title hasMousePopup";
                            TamagotchiPG.powerItems.subdivs.push(td);
                            table.appendChild(td);
                        }
                        TamagotchiPG.toolbar.div1.appendChild(table);

                        table = document.createElement("div");
                        table.setAttribute("style","cursor:pointer;font-size:18px;position:absolute;display:block;margin-left:324px;width:16px;");
                        for(k=0;k<2;k++)
                        {
                            var tx = document.createElement("div");
                            tx.setAttribute("style","width:15px;height:22px;color:white;padding:0px;margin-"+(k===0?"top":"bottom")+":4px;padding-top:3px;display:block;background-size:cover;text-align:center;");
                            tx.addEventListener("click", k===0?function(){TamagotchiPG.powerItems.move(+5,div2);}:function(){TamagotchiPG.powerItems.move(-5,div2);});
                            tx.appendChild(document.createTextNode([">","<"][k]));
                            tx.className = "item item_inventory title hasMousePopup";
                            table.appendChild(tx);
                        }
                        TamagotchiPG.toolbar.div1.appendChild(table);

                        TamagotchiPG.powerItems.showItems(0, TamagotchiPG.powerItems.riposo, div2);
                        TamagotchiPG.toolbar.div1.appendChild(div3);

                        AnimatedCharacter.getElement()[0].appendChild(TamagotchiPG.toolbar.div1);
                        return TamagotchiPG.toolbar.closeDefault();
                    });
				}
			},
		},
    };
    $(function() { try { TamagotchiPG.script.init(); } catch(x) { console.trace(x); } });
});