Melvor Show Modifiers

Adds a button to show all your modifiers

当前为 2021-03-12 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Melvor Show Modifiers
// @version      0.0.2
// @description  Adds a button to show all your modifiers
// @author       GMiclotte
// @match        https://*.melvoridle.com/*
// @exclude      https://wiki.melvoridle.com/*
// @grant        none
// @namespace    http://tampermonkey.net/
// @noframes
// ==/UserScript==

function script() {
    window.melvorShowModifiers = {};
    let codeString = showAllAgilityPassives.toString();
    codeString = codeString.replace(/^function (\w+) *\(\)/, 'window.melvorShowModifiers.showAllModifiers = (modifiers, text) => ');
    codeString = codeString.replace(/agilityPassiveBonuses/g, 'modifiers');
    codeString = codeString.replace('Current Global Active Passives from Agility', '${text}');
    eval(codeString);

    window.melvorShowModifiers.showModifiers = (modifiers, text = 'Active Modifiers') => {
        const filteredModifiers = {};
        Object.getOwnPropertyNames(modifiers).forEach(prop => {
            const value = modifiers[prop];
            if (value.length === undefined) {
                if (value === 0) {
                    return;
                }
                filteredModifiers[prop] = value;
            } else {
                if (value.length === 0) {
                    return;
                }
                filteredModifiers[prop] = value;
            }
        });
        window.melvorShowModifiers.showAllModifiers(filteredModifiers, text);
    }

    let modifierButton = () => {
        return '<div class="dropdown d-inline-block ml-2">'
            + '<button type="button" '
            + 'class="btn btn-sm btn-dual text-combat-smoke" '
            + 'id="page-header-modifiers" '
            + 'onclick="window.melvorShowModifiers.showModifiers(playerModifiers);" '
            + 'aria-haspopup="true" '
            + 'aria-expanded="true">'
            + `<img class="skill-icon-xxs" src="${getItemMedia(CONSTANTS.item.Event_Clue_1)}">`
            + '</button>'
            + '</div>';
    }
    let node = document.getElementById('page-header-potions-dropdown').parentNode;
    node.parentNode.insertBefore(html2Node(modifierButton()), node);
}


(function () {
    function injectScript(main) {
        const scriptElement = document.createElement('script');
        scriptElement.textContent = `try {(${main})();} catch (e) {console.log(e);}`;
        document.body.appendChild(scriptElement).parentNode.removeChild(scriptElement);
    }

    function loadScript() {
        if ((window.isLoaded && !window.currentlyCatchingUp)
            || (typeof unsafeWindow !== 'undefined' && unsafeWindow.isLoaded && !unsafeWindow.currentlyCatchingUp)) {
            // Only load script after game has opened
            clearInterval(scriptLoader);
            injectScript(script);
        }
    }

    const scriptLoader = setInterval(loadScript, 200);
})();