Pete's Eternity Tower Quick Sets

Equips skin, gear, and abilities in configurable sets

当前为 2017-12-27 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name          Pete's Eternity Tower Quick Sets
// @icon          https://www.eternitytower.net/favicon.png
// @namespace     http://mean.cloud/
// @version       1.02
// @description   Equips skin, gear, and abilities in configurable sets
// @match         http*://*.eternitytower.net/*
// @copyright     2017, MeanCloud
// @grant         GM_getValue
// @grant         GM_setValue
// @grant         GM_deleteValue
// @run-at        document-body
// ==/UserScript==

function addJQuery(callback)
{
    var script = document.createElement("script");
    script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js");
    script.addEventListener('load', function()
    {
        var script = document.createElement("script");
        script.textContent = "window.jQ=jQuery.noConflict(true);(" + callback.toString() + ")();";
        document.body.appendChild(script);
    }, false);
    document.body.appendChild(script);
}

document.PETQS_SkinEquipped = "";
document.PETQS_EquippedItems = [];
document.PETQS_EquippedAbilities = [];
document.PETQS_UserID = "";
document.PETQS_CombatID = "";
document.PETQS_AllItems = [];

function main()
{
    document.PETQS_TestUI();

    Meteor.connection._stream.on('message', function(sMeteorRawData)
    {
        try
        {
            var oMeteorData = JSON.parse(sMeteorRawData);

            try
            {
                if (oMeteorData.collection == "users")
                    document.PETQS_UserID = oMeteorData.id;

                if (oMeteorData.collection == "combat")
                {
                    if ((oMeteorData.fields.owner === document.PETQS_UserID) && (document.PETQS_CombatID === ""))
                        document.PETQS_CombatID = oMeteorData.id;

                    if ((oMeteorData.id === document.PETQS_CombatID) || (document.PETQS_CombatID === ""))
                        if (oMeteorData.fields.characterIcon)
                            document.PETQS_SkinEquipped = oMeteorData.fields.characterIcon;
                }
            }
            catch (err) { console.log("Error with PETQS/combat: " + err); }

            try
            {
                if (oMeteorData.collection == "abilities")
                {
                    if (oMeteorData.fields && oMeteorData.fields.learntAbilities)
                    {
                        document.PETQS_EquippedAbilities = [];

                        jQ.makeArray(oMeteorData.fields.learntAbilities).forEach(function(oAbility, index, array)
                        {
                            try
                            {
                                if (oAbility.equipped)
                                    document.PETQS_EquippedAbilities.push(oAbility);
                            }
                            catch (err) { console.log("Error with PETQS/ability: " + err); }
                        });
                    }
                }
            }
            catch (err) { console.log("Error with PETQS/abilities: " + err); }

            try
            {
                if (oMeteorData.collection == "items")
                {
                    if (oMeteorData.msg == "added")
                        if (oMeteorData.fields && oMeteorData.fields.itemId && oMeteorData.fields.name && oMeteorData.fields.category)
                            document.PETQS_AllItems.push(oMeteorData);

                    if (oMeteorData.fields.equipped)
                    {
                        document.PETQS_EquippedItems.push(oMeteorData);
                    }
                    else
                    {
                        if (document.PETQS_EquippedItems.length > 0)
                        {
                            for (i = 0; i < document.PETQS_EquippedItems.length; i++)
                            {
                                if (document.PETQS_EquippedItems[i].id == oMeteorData.id)
                                {
                                    document.PETQS_EquippedItems.splice(i, 1);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            catch (err) { console.log("Error with PETQS/items: " + err); }
        }
        catch (err) { console.log("Error with PETQS/meteor: " + err); }
    });
}

document.PETQS_TestUI = function()
{
    try
    {
        if (jQ("div#PETQS_UI").length === 0)
            if (jQ("div.hidden-lg-down").length > 0)
                document.PETQS_CreateUI();
    }
    catch (err) { }

    setTimeout(document.PETQS_TestUI, 1000);
};

document.PETQS_CreateUI = function()
{
    jQ("div#PETQS_UI").remove();

    jQ(jQ("div.hidden-lg-down").children("div").get(0)).append
    (
        "<div style=\"margin-top: 20px; border: 1px solid #dde; background-color: #fafbfd; padding: 5px; width: 280px; font-size: 14px;\" id=\"PETQS_UI\">" +
        "<div style=\"width: 270px; max-width: 270px; cursor: hand;\" id=\"PETQS_Slotbar01\" onclick=\"javascript:document.PETQS_LoadSet(1,true);\">[empty set]</div>" +
        "<div style=\"width: 270px; max-width: 270px; cursor: hand;\" id=\"PETQS_Slotbar02\" onclick=\"javascript:document.PETQS_LoadSet(2,true);\">[empty set]</div>" +
        "<div style=\"width: 270px; max-width: 270px; cursor: hand;\" id=\"PETQS_Slotbar03\" onclick=\"javascript:document.PETQS_LoadSet(3,true);\">[empty set]</div>" +
        "<div style=\"width: 270px; max-width: 270px; cursor: hand;\" id=\"PETQS_Slotbar04\" onclick=\"javascript:document.PETQS_LoadSet(4,true);\">[empty set]</div>" +
        "<div style=\"width: 270px; max-width: 270px; cursor: hand;\" id=\"PETQS_Slotbar05\" onclick=\"javascript:document.PETQS_LoadSet(5,true);\">[empty set]</div>" +
        "<div style=\"width: 270px; max-width: 270px; cursor: hand;\" id=\"PETQS_Slotbar06\" onclick=\"javascript:document.PETQS_LoadSet(6,true);\">[empty set]</div>" +
        "<div style=\"width: 270px; max-width: 270px; cursor: hand;\" id=\"PETQS_Slotbar07\" onclick=\"javascript:document.PETQS_LoadSet(7,true);\">[empty set]</div>" +
        "<div style=\"width: 270px; max-width: 270px; cursor: hand;\" id=\"PETQS_Slotbar08\" onclick=\"javascript:document.PETQS_LoadSet(8,true);\">[empty set]</div>" +
        "<div style=\"width: 270px; max-width: 270px; cursor: hand;\" id=\"PETQS_Slotbar09\" onclick=\"javascript:document.PETQS_LoadSet(9,true);\">[empty set]</div>" +
        "<div style=\"width: 270px; max-width: 270px; cursor: hand;\" id=\"PETQS_Slotbar10\" onclick=\"javascript:document.PETQS_LoadSet(10,true);\">[empty set]</div>" +
        "<div style=\"width: 270px; max-width: 270px; cursor: hand;\" id=\"PETQS_Slotbar11\" onclick=\"javascript:document.PETQS_LoadSet(11,true);\">[empty set]</div>" +
        "<div style=\"width: 270px; max-width: 270px; cursor: hand;\" id=\"PETQS_Slotbar12\" onclick=\"javascript:document.PETQS_LoadSet(12,true);\">[empty set]</div>" +
        "<div style=\"width: 270px; max-width: 270px; padding-top: 10px;\">" +
        "<input type=\"button\" value=\"Save #1\" onclick=\"javascript:document.PETQS_SaveSet(1);\" style=\"display: inline-block; width: 64px; font-size: 12px;\" /> " +
        "<input type=\"button\" value=\"Save #2\" onclick=\"javascript:document.PETQS_SaveSet(2);\" style=\"display: inline-block; width: 64px; font-size: 12px;\" /> " +
        "<input type=\"button\" value=\"Save #3\" onclick=\"javascript:document.PETQS_SaveSet(3);\" style=\"display: inline-block; width: 64px; font-size: 12px;\" /> " +
        "<input type=\"button\" value=\"Save #4\" onclick=\"javascript:document.PETQS_SaveSet(4);\" style=\"display: inline-block; width: 64px; font-size: 12px;\" /><br />" +
        "<input type=\"button\" value=\"Save #5\" onclick=\"javascript:document.PETQS_SaveSet(5);\" style=\"display: inline-block; width: 64px; font-size: 12px;\" /> " +
        "<input type=\"button\" value=\"Save #6\" onclick=\"javascript:document.PETQS_SaveSet(6);\" style=\"display: inline-block; width: 64px; font-size: 12px;\" /> " +
        "<input type=\"button\" value=\"Save #7\" onclick=\"javascript:document.PETQS_SaveSet(7);\" style=\"display: inline-block; width: 64px; font-size: 12px;\" /> " +
        "<input type=\"button\" value=\"Save #8\" onclick=\"javascript:document.PETQS_SaveSet(8);\" style=\"display: inline-block; width: 64px; font-size: 12px;\" /><br />" +
        "<input type=\"button\" value=\"Save #9\" onclick=\"javascript:document.PETQS_SaveSet(9);\" style=\"display: inline-block; width: 64px; font-size: 12px;\" /> " +
        "<input type=\"button\" value=\"Save #10\" onclick=\"javascript:document.PETQS_SaveSet(10);\" style=\"display: inline-block; width: 64px; font-size: 12px;\" /> " +
        "<input type=\"button\" value=\"Save #11\" onclick=\"javascript:document.PETQS_SaveSet(11);\" style=\"display: inline-block; width: 64px; font-size: 12px;\" /> " +
        "<input type=\"button\" value=\"Save #12\" onclick=\"javascript:document.PETQS_SaveSet(12);\" style=\"display: inline-block; width: 64px; font-size: 12px;\" /><br />" +
        "</div>" +
        "</div>"
    );

    document.PETQS_LoadSet(1);
    document.PETQS_LoadSet(2);
    document.PETQS_LoadSet(3);
    document.PETQS_LoadSet(4);
    document.PETQS_LoadSet(5);
    document.PETQS_LoadSet(6);
    document.PETQS_LoadSet(7);
    document.PETQS_LoadSet(8);
    document.PETQS_LoadSet(9);
    document.PETQS_LoadSet(10);
    document.PETQS_LoadSet(11);
    document.PETQS_LoadSet(12);
};

document.PETQS_SaveSet = function(iSlot)
{
    var sSetting = "";

    sSetting += "skin&&" + document.PETQS_SkinEquipped + "||";

    try
    {
        jQ.makeArray(document.PETQS_EquippedItems).forEach(function(oEquippedItem, index, array)
        {
            //console.log(oEquippedItem);

            try
            {
                var oEquippedItemToUse = oEquippedItem;

                if (!oEquippedItem.fields.category)
                {
                    jQ.makeArray(document.PETQS_AllItems).forEach(function(oThisItem, index2, array2)
                    {
                        if ((oThisItem.id === oEquippedItem.id) && (oThisItem.fields.category))
                        {
                            oEquippedItemToUse = oThisItem;
                            //console.log("--> ", oEquippedItemToUse);
                        }
                    });
                }

                sSetting +=     "item&&"
                              + oEquippedItemToUse.id + "&&"
                              + oEquippedItemToUse.fields.itemId + "&&"
                              + oEquippedItemToUse.fields.name + "&&"
                              + (oEquippedItem.fields.slot ? oEquippedItem.fields.slot : oEquippedItemToUse.fields.slot) + "&&"
                              + oEquippedItemToUse.fields.icon + "&&"
                              + (oEquippedItemToUse.fields.quality ? oEquippedItemToUse.fields.quality.toFixed(0) : "-1") + "&&"
                              + (oEquippedItemToUse.fields.enhanced ? "E" : "X") + "||";
            }
            catch (err) { console.log("Error with PETQS/saveItem: " + err); }
        });
    }
    catch (err) { console.log("Error with PETQS/saveItems: " + err); }

    try
    {
        jQ.makeArray(document.PETQS_EquippedAbilities).forEach(function(oEquippedAbility, index, array)
        {
            //console.log(oEquippedAbility);

            try
            {
                sSetting +=     "ability&&"
                              + oEquippedAbility.abilityId + "&&"
                              + oEquippedAbility.name + "&&"
                              + oEquippedAbility.slot + "&&"
                              + oEquippedAbility.icon + "||";
            }
            catch (err) { console.log("Error with PETQS/saveAbility: " + err); }
        });
    }
    catch (err) { console.log("Error with PETQS/saveAbilities: " + err); }

    //console.log("Save: " + sSetting);

    document.CookieSet("PETQS_QS" + document.pad(iSlot, 2), sSetting);

    document.PETQS_LoadSet(iSlot);
};

document.PETQS_LoadSet = function(iSlot, bEquip = false)
{
    var sRawSetting = document.CookieGet("PETQS_QS" + document.pad(iSlot, 2)) || "";
    //console.log("Load: " + sRawSetting);
    if (sRawSetting === "") return;

    var sSettingLines = jQ.makeArray(sRawSetting.split("||"));
    var sHotbarHTML = "";

    const sImageSize = "22px";

    if (bEquip)
    {
        Meteor.connection._send({"msg":"method","method":"abilities.unequip","params":["head"],"id":"-1"});
        Meteor.connection._send({"msg":"method","method":"abilities.unequip","params":["chest"],"id":"-1"});
        Meteor.connection._send({"msg":"method","method":"abilities.unequip","params":["offHand"],"id":"-1"});
        Meteor.connection._send({"msg":"method","method":"abilities.unequip","params":["mainHand"],"id":"-1"});
        Meteor.connection._send({"msg":"method","method":"abilities.unequip","params":["legs"],"id":"-1"});

        var equipmentCopy = document.PETQS_EquippedItems.slice();

        if (equipmentCopy.length > 0)
            for (i = 0; i < equipmentCopy.length; i++)
                if (equipmentCopy[i].fields.category != "mining")
                    Meteor.connection._send({"msg":"method","method":"items.unequip","params":[equipmentCopy[i].id,equipmentCopy[i].fields.itemId],"id":"-1"});
    }

    // look for skins first
    sSettingLines.forEach(function(sSettingLine, index, array)
    {
        try
        {
            var sSettingVals = jQ.makeArray(sSettingLine.split("&&"));

            if (sSettingVals[0] == "skin")
            {
                //console.log("skin: " + sSettingVals[1]);

                sHotbarHTML += "<img src=\"/icons/" + sSettingVals[1] + "\" class=\"extra-small-icon\" style=\"width: " + sImageSize + "; height: " + sImageSize + "; padding: 0px; margin: 0px; border: none;\" />";

                if (bEquip)
                {
                    // there's a lookup table for this, but this code is simpler since there's not that many skins
                    // I am a lazy programmer
                    if (sSettingVals[1] == "mageT1HD.png") Meteor.connection._send({"msg":"method","method":"combat.updateCharacterIcon","params":["mage_t1"],"id":"-1"});
                    if (sSettingVals[1] == "mageT2HD.png") Meteor.connection._send({"msg":"method","method":"combat.updateCharacterIcon","params":["mage_t2"],"id":"-1"});
                    if (sSettingVals[1] == "damageT1HD.png") Meteor.connection._send({"msg":"method","method":"combat.updateCharacterIcon","params":["damage_t1"],"id":"-1"});
                    if (sSettingVals[1] == "damageT2HD.png") Meteor.connection._send({"msg":"method","method":"combat.updateCharacterIcon","params":["damage_t2"],"id":"-1"});
                    if (sSettingVals[1] == "tankT1HD.png") Meteor.connection._send({"msg":"method","method":"combat.updateCharacterIcon","params":["tank_t1"],"id":"-1"});
                    if (sSettingVals[1] == "tankT2HD.png") Meteor.connection._send({"msg":"method","method":"combat.updateCharacterIcon","params":["tank_t2"],"id":"-1"});
                    if (sSettingVals[1] == "phoenixT1.png") Meteor.connection._send({"msg":"method","method":"combat.updateCharacterIcon","params":["phoenix_t1"],"id":"-1"});
                    if (sSettingVals[1] == "phoenixT2.png") Meteor.connection._send({"msg":"method","method":"combat.updateCharacterIcon","params":["phoenix_t2"],"id":"-1"});
                    if (sSettingVals[1] == "crowT1.png") Meteor.connection._send({"msg":"method","method":"combat.updateCharacterIcon","params":["crow_t1"],"id":"-1"});
                    if (sSettingVals[1] == "crowT2.png") Meteor.connection._send({"msg":"method","method":"combat.updateCharacterIcon","params":["crow_t2"],"id":"-1"});
                    if (sSettingVals[1] == "vallaT1.png") Meteor.connection._send({"msg":"method","method":"combat.updateCharacterIcon","params":["valla_t1"],"id":"-1"});
                    if (sSettingVals[1] == "adalgarT1.png") Meteor.connection._send({"msg":"method","method":"combat.updateCharacterIcon","params":["adalgar_t1"],"id":"-1"});
                }
            }
        }
        catch (err) { }
    });

    // look for gear
    for (i = 1; i <= 6; i++)
    {
        sSettingLines.forEach(function(sSettingLine, index, array)
        {
            try
            {
                var sSettingVals = jQ.makeArray(sSettingLine.split("&&"));

                if (sSettingVals[0] == "item")
                {
                    if ((i == 1) && (sSettingVals[4] != "mainHand")) return;
                    if ((i == 2) && (sSettingVals[4] != "offHand")) return;
                    if ((i == 3) && (sSettingVals[4] != "head")) return;
                    if ((i == 4) && (sSettingVals[4] != "neck")) return;
                    if ((i == 5) && (sSettingVals[4] != "chest")) return;
                    if ((i == 6) && (sSettingVals[4] != "legs")) return;

                    //console.log("item: " + sSettingVals[3]);

                    sHotbarHTML += "<img src=\"/icons/" + sSettingVals[5] + "\" class=\"extra-small-icon\" style=\"width: " + sImageSize + "; height: " + sImageSize + "; padding: 0px; margin: 0px; border: none;\" />";

                    if (bEquip)
                        Meteor.connection._send({"msg":"method","method":"items.equip","params":[sSettingVals[1],sSettingVals[2]],"id":"-1"});
                }
            }
            catch (err) { }
        });
    }

    // look for abilities
    for (i = 1; i <= 5; i++)
    {
        sSettingLines.forEach(function(sSettingLine, index, array)
        {
            try
            {
                var sSettingVals = jQ.makeArray(sSettingLine.split("&&"));

                if (sSettingVals[0] == "ability")
                {
                    if ((i == 1) && (sSettingVals[3] != "mainHand")) return;
                    if ((i == 2) && (sSettingVals[3] != "offHand")) return;
                    if ((i == 3) && (sSettingVals[3] != "head")) return;
                    if ((i == 4) && (sSettingVals[3] != "chest")) return;
                    if ((i == 5) && (sSettingVals[3] != "legs")) return;

                    //console.log("ability: " + sSettingVals[2]);

                    sHotbarHTML += "<img src=\"/icons/" + sSettingVals[4] + "\" class=\"extra-small-icon\" style=\"width: " + sImageSize + "; height: " + sImageSize + "; padding: 0px; margin: 0px; border: none;\" />";

                    if (bEquip)
                        Meteor.connection._send({"msg":"method","method":"abilities.equip","params":[sSettingVals[1]],"id":"-1"});
                }
            }
            catch (err) { }
        });
    }

    jQ("div#PETQS_Slotbar" + document.pad(iSlot, 2)).html(sHotbarHTML);
};

document.CDbl = function(v)
{
	try
	{
		if (!isNaN(v)) return parseFloat(v);
		if (typeof v === 'undefined') return parseFloat(0.0);
		if (v === null) return parseFloat(0.0);
		var t = parseFloat(v);
		if (isNaN(t)) return parseFloat(0.0);
		return t;
	}
	catch (err) { }

	return parseFloat(0.0);
};

document.CInt = function(v)
{
	try
	{
		if (!isNaN(v)) return parseInt(v);
		if (typeof v === 'undefined') return parseInt(0);
		if (v === null) return parseInt(0);
		var t = parseInt(v);
		if (isNaN(t)) return parseInt(0);
		return t;
	}
	catch (err) { }

	return parseInt(0);
};

document.is_visible = (function () {
    var x = window.pageXOffset ? window.pageXOffset + window.innerWidth - 1 : 0,
        y = window.pageYOffset ? window.pageYOffset + window.innerHeight - 1 : 0,
        relative = !!((!x && !y) || !document.elementFromPoint(x, y));
        function inside(child, parent) {
            while(child){
                if (child === parent) return true;
                child = child.parentNode;
            }
        return false;
    };
    return function (elem) {
        if (
            document.hidden ||
            elem.offsetWidth==0 ||
            elem.offsetHeight==0 ||
            elem.style.visibility=='hidden' ||
            elem.style.display=='none' ||
            elem.style.opacity===0
        ) return false;
        var rect = elem.getBoundingClientRect();
        if (relative) {
            if (!inside(document.elementFromPoint(rect.left + elem.offsetWidth/2, rect.top + elem.offsetHeight/2),elem)) return false;
        } else if (
            !inside(document.elementFromPoint(rect.left + elem.offsetWidth/2 + window.pageXOffset, rect.top + elem.offsetHeight/2 + window.pageYOffset), elem) ||
            (
                rect.top + elem.offsetHeight/2 < 0 ||
                rect.left + elem.offsetWidth/2 < 0 ||
                rect.bottom - elem.offsetHeight/2 > (window.innerHeight || document.documentElement.clientHeight) ||
                rect.right - elem.offsetWidth/2 > (window.innerWidth || document.documentElement.clientWidth)
            )
        ) return false;
        if (window.getComputedStyle || elem.currentStyle) {
            var el = elem,
                comp = null;
            while (el) {
                if (el === document) {break;} else if(!el.parentNode) return false;
                comp = window.getComputedStyle ? window.getComputedStyle(el, null) : el.currentStyle;
                if (comp && (comp.visibility=='hidden' || comp.display == 'none' || (typeof comp.opacity !=='undefined' && comp.opacity != 1))) return false;
                el = el.parentNode;
            }
        }
        return true;
    };
})();

document.CookieSet = function(name, value, days = 1000)
{
	GM_setValue(name, value);
};

document.CookieGet = function(name, defVal = null)
{
	try { return GM_getValue(name, defVal); } catch (err) { }
	return null;
};

document.CookieDelete = function(name)
{
	GM_deleteValue(name);
};

document.pad = function(n, width, z)
{
  z = z || '0';
  n = n + '';
  return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
};

addJQuery(main);