Melvor Idle - Queue End Fight

Adds a button to the combat interface to leave combat after defeating the current enemy or dungeon.

当前为 2022-04-30 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Melvor Idle - Queue End Fight
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Adds a button to the combat interface to leave combat after defeating the current enemy or dungeon.
// @author       Seil#1780
// @license      MIT
// @match        https://*.melvoridle.com/*
// @exclude		 https://wiki.melvoridle.com/*
// @exclude		 https://*.wiki.melvoridle.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=melvoridle.com
// @grant        none
// ==/UserScript==

function script() {
    var runQueued = false;
    var _oldFunction = combatManager.onEnemyDeath;

    let queueRunButton = '<button type="button" id="queueRunButton" class="btn btn-sm btn-warning m-1 w-100">Queue Leave Encounter</button>';

    let combatButtons = document.querySelector("#combat-enemy-options").parentNode;
    let runButton = document.querySelector("#combat-enemy-options");

    combatButtons.children[0].className = "col-4";
    combatButtons.children[1].className = "col-4";
    combatButtons.children[1].insertAdjacentHTML("afterend", '<div class="col-4"></div>');
    combatButtons.children[2].innerHTML += queueRunButton

    document.getElementById("queueRunButton").addEventListener("click", toggleQueue);

    function toggleQueue() {
        if(runQueued) {
            document.getElementById("queueRunButton").className = "btn btn-sm btn-warning m-1 w-100";
            runQueued = false;
        } else {
            document.getElementById("queueRunButton").className = "btn btn-sm btn-danger m-1 w-100";
            runQueued = true;
        }
    }

    combatManager.onEnemyDeath = function onEnemyDeath() {
        var encounterCompleted = false;
        var dungeonCompleted = this.dungeonProgress+1==this.areaData.monsters.length;

        _oldFunction.apply(this);
        if(runQueued) {
            if(this.areaData.type==="Dungeon"&&!dungeonCompleted) {
                encounterCompleted = false;
            } else {
                encounterCompleted = true;
                this.stopCombat();
                toggleQueue();
            }
        }

        return encounterCompleted;
    }
}




(() => {
    function loadScript() {
        if (typeof confirmedLoaded !== typeof undefined && confirmedLoaded) {
            clearInterval(scriptLoader);

            const scriptElem = document.createElement("script");
            scriptElem.textContent = `try {(${script})();} catch (e) {console.log(e);}`;
            document.body.appendChild(scriptElem).parentNode.removeChild(scriptElem);
        }
    }
    const scriptLoader = setInterval(loadScript, 200);
})();