Melvor Idle - Mastery Enhancements

Colors buttons to spend pool xp depending on current xp and adds progress bars for pools to skills in the menu

目前為 2020-10-22 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Melvor Idle - Mastery Enhancements
// @description Colors buttons to spend pool xp depending on current xp and adds progress bars for pools to skills in the menu
// @version     1.0
// @namespace   Visua
// @match       https://melvoridle.com/*
// @match       https://www.melvoridle.com/*
// @grant       none
// ==/UserScript==
/* jshint esversion: 6 */

((main) => {
    var script = document.createElement('script');
    script.textContent = `try { (${main})(); } catch (e) { console.log(e); }`;
    document.body.appendChild(script).parentNode.removeChild(script);
})(() => {
    'use strict';

    function addColoredButtons() {
        const _updateMasteryPoolProgress = updateMasteryPoolProgress;
        updateMasteryPoolProgress = (...args) => {
            _updateMasteryPoolProgress(...args);
            try {
                colorButtons(args[0]);
            } catch (e) {
                console.error(e);
            }
        };

        function colorButtons(skill) {
            const poolXP = Math.floor(MASTERY[skill].pool);
            const threshold = getMasteryPoolTotalXP(skill) * (skill === CONSTANTS.skill.Farming ? 0.5 : 0.95);
            for (let i = 0; i < MASTERY[skill].xp.length; i++) {
                const masteryRequired = document.getElementById(`mastery-item-xp-required-${skill}-${i}`);
                if (masteryRequired != null) {
                    const masteryXP = parseInt(masteryRequired.innerText.replace(/,/g, ''));
                    const button = masteryRequired.parentElement.parentElement.parentElement.parentElement.getElementsByClassName("btn")[0];
                    button.classList.remove('btn-success', 'btn-danger', 'btn-warning');
                    if (poolXP < masteryXP) {
                        button.classList.add('btn-danger');
                    } else if ((poolXP - masteryXP) < threshold) {
                        button.classList.add('btn-warning');
                    } else {
                        button.classList.add('btn-success');
                    }
                }
            }
        }
    }

    function addProgressBars() {
        setInterval(() => {
            for (const id in SKILLS) {
                if (SKILLS[id].hasMastery) {
                    if ($(`#skill-nav-mastery-${id} .progress-bar`)[0]) {
                        $(`#skill-nav-mastery-${id} .progress-bar`)[0].style.width = ((MASTERY[id].pool / getMasteryPoolTotalXP(id)) * 100) + '%';
                        const tip = $(`#skill-nav-mastery-${id}`)[0]._tippy;
                        tip.setContent(((MASTERY[id].pool / getMasteryPoolTotalXP(id)) * 100).toFixed(2) + '%');
                    } else {
                        const skillItem = $(`#skill-nav-name-${id}`)[0].parentNode;
                        skillItem.style.flexWrap = 'wrap';
                        skillItem.style.setProperty('padding-top', '.25rem', 'important');
                        const progress = document.createElement('div');
                        const progressBar = document.createElement('div');
                        progress.id = `skill-nav-mastery-${id}`;
                        progress.className = 'progress active pointer-enabled';
                        progress.style.height = '6px';
                        progress.style.width = '100%';
                        progress.style.margin = '.25rem 0rem';
                        progress.style.setProperty('background', 'rgb(76,80,84)', 'important');
                        progressBar.className = 'progress-bar bg-warning';
                        progressBar.style.width = ((MASTERY[id].pool / getMasteryPoolTotalXP(id)) * 100) + '%';
                        progress.appendChild(progressBar);
                        skillItem.appendChild(progress);
                        tippy($(`#skill-nav-mastery-${id}`)[0], {
                            placement: 'right',
                            content: ((MASTERY[id].pool / getMasteryPoolTotalXP(id)) * 100).toFixed(2) + '%'
                        });
                    }
                }
            }
        }, 5000);
    }

    function loadScript() {
        if (typeof confirmedLoaded !== 'undefined' && confirmedLoaded && !currentlyCatchingUp) {
            clearInterval(interval);
            console.log('Loading Mastery Enhancements');
            addColoredButtons();
            addProgressBars();
        }
    }

    const interval = setInterval(loadScript, 500);
});