ET Battle Helper

A few interface tweaks to improve your battling experience

目前為 2017-10-16 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         ET Battle Helper
// @version      0.7
// @description  A few interface tweaks to improve your battling experience
// @author       jimborino
// @match        http*://*.eternitytower.net/*
// @run-at       document-idle
// @namespace https://greasyfork.org/users/156118
// ==/UserScript==



(function() {
    'use strict';

    var storage = window.localStorage;

    // Default settings, use window.ETBattleHelper in console to change settings
    unsafeWindow.ETBattleHelper = {
        showEnemyTargets: true,
        showPlayerTargets: true,
        highlightExecuteRange: true,
        showEnemyPercentHealth: true,
        highlightOwnTarget: true
    };


    if(storage.getItem("ETBattleHelper"))
        unsafeWindow.ETBattleHelper = JSON.parse(storage.getItem("ETBattleHelper"));

    $(window).on("beforeunload", function() {
        storage.setItem("ETBattleHelper", JSON.stringify(unsafeWindow.ETBattleHelper));
    });

    // a few styles
    $("<style type='text/css'> .playerTarget img { border: 1px solid red !important; } #target { font-size: 14px; text-transform: capitalize; } .battle-unit-container { max-width: 200px; } </style>").appendTo("head");

    // Prevent typing in chat input box from triggering abilities
    setTimeout(function() { $("input#simple-chat-message").on("keyup", function(e) { e.stopPropagation(); }); }, 2000);

    // Fix hovering for battle log drops
    var obs = new MutationObserver(function(mutations, observer) {
        $(".alert.alert-secondary div.d-flex div.align-items-center img").each(function() {
            $(this).parent().attr("title", $(this).attr("title"));
        });
    });
    obs.observe($("body").get(0), { childList: true, subtree: true });


    // Enemy HP % and targets
    Meteor.connection._stream.on("message", function(json) {
        var message = JSON.parse(json);
        if(message.msg == "changed" && message.collection == "redis" &&  message.id.includes("battles-")) {
            var battleState = JSON.parse(message.fields.value);

            battleState.enemies.forEach(function(enemy) {
                var enemyTarget = getUnitById(enemy.target, battleState);
                if (enemyTarget !== undefined) {
                    enemyTarget = enemyTarget.name;
                    var enemyHealth = enemy.stats.health;
                    var enemyHealthMax = enemy.stats.healthMax;
                    var enemyHealthPercent = (enemyHealth / enemyHealthMax) * 100;
                    var enemyImgEl = $("img#" + enemy.id);
                    if(unsafeWindow.ETBattleHelper.highlightExecuteRange) {
                        if(enemyHealthPercent < 30) {
                            enemyImgEl.siblings(".progress.health-bar").css("box-shadow", "0 0 0 2px red");
                        } else {
                            enemyImgEl.siblings(".progress.health-bar").css("box-shadow", "none");
                        }
                    }

                    if(unsafeWindow.ETBattleHelper.showEnemyPercentHealth) {
                        var enemyPercentEl = enemyImgEl.siblings("div#percent");
                        if(enemyPercentEl.length > 0) {
                            enemyPercentEl.html(enemyHealthPercent.toFixed(2) + "%");
                        } else {
                            enemyPercentEl = $("<div id='percent'>" + enemyHealthPercent.toFixed(2) + "%</div>");
                            enemyPercentEl.insertBefore(enemyImgEl);
                        }
                    }

                    if(unsafeWindow.ETBattleHelper.showEnemyTargets) {
                        var enemyTargetEl = enemyImgEl.siblings("div#target");
                        if(enemyTargetEl.length > 0) {
                            enemyTargetEl.html("( " + enemyTarget + " )");
                        } else {
                            enemyTargetEl = $("<div id='target'>( " + enemyTarget + " )</div>");
                            enemyTargetEl.insertBefore(enemyImgEl);
                        }
                    }
                }
            });

            battleState.units.forEach(function(unit) {
                var unitTarget = getUnitById(unit.target, battleState);
                var unitTargetId;
                if(unitTarget === undefined) { // player targets only change when the target is manually changed
                                               // for attacks after an enemy is dead, the target is always the first enemy
                    if(battleState.enemies.length < 1) { // we receive an update when all enemies are dead
                        return;
                    }
                    unitTargetId = battleState.enemies[0].id;
                    unitTarget = battleState.enemies[0].name;
                } else {
                    unitTargetId = unitTarget.id;
                    unitTarget = unitTarget.name;
                }
                var unitImgEl = $("img#" + unit.id);
                if(unsafeWindow.ETBattleHelper.showPlayerTargets) {
                    var unitTargetEl = unitImgEl.siblings("div#target");
                    if(unitTargetEl.length > 0) {
                        unitTargetEl.html("( " + unitTarget + " )");
                    } else {
                        unitTargetEl = $("<div id='target'>( " + unitTarget + " )</div>");
                        unitTargetEl.insertBefore(unitImgEl);
                    }
                }



                if(unsafeWindow.ETBattleHelper.highlightOwnTarget) {
                    $("img#" + unitTargetId).parent().addClass("playerTarget");
                    $("img#" + unitTargetId).parent()
                                            .parent()
                                            .siblings()
                                            .children()
                                            .removeClass("playerTarget");
                }


            });

        }
    });

    // Recolor your damage splats
    var oldReceive = Meteor.connection._livedata_data;
    var userId = Meteor.userId();

    Meteor.connection._livedata_data = function() {
        if(arguments[0].msg == "changed" && arguments[0].collection == "redis") {
            var battleState = JSON.parse(arguments[0].fields.value);
            battleState.tickEvents.forEach(function(tickEvent) {
                if(tickEvent.from == userId)
                    tickEvent.customColor = "black";
            });
            arguments[0].fields.value = JSON.stringify(battleState);
        }

        var ret = oldReceive.apply(this, arguments);
        return ret;
    };

    function getUnitById(unitId, battleState) {
        return battleState.units.concat(battleState.enemies).find(function (el) {
            if (el.id == unitId) return true;
        });
    }
})();