Melvor TimeRemaining

Shows time remaining for completing a task with your current resources. Takes into account Mastery Levels and other bonuses.

目前为 2020-04-15 提交的版本。查看 最新版本

// ==UserScript==
// @name         Melvor TimeRemaining
// @namespace    http://tampermonkey.net/
// @version      0.1.1
// @description  Shows time remaining for completing a task with your current resources. Takes into account Mastery Levels and other bonuses.
// @author       Breindahl#2660
// @match        https://*.melvoridle.com/*
// @grant        none
// ==/UserScript==

function ding() {
	new Audio("https://www.myinstants.com/media/sounds/ding-sound-effect.mp3").play();
}

function notify(msg) {
	One.helpers('notify', {
		type: 'dark',
		from: 'bottom',
		align: 'center',
		message: msg
	});
}

document.getElementById("smith-item-have").outerHTML += "<br><small id =\"timeLeft\">"+""+"<small>";
console.log('Loading Breindahl TimeRemaining');

function timeRemaining(){
    // Define Selected Item
    item = smithingItems[selectedSmith].itemID;

    //Funtion to get unformatted number for SmithQty
    function getSmithQtyUnformat(itemID) {
        let qty = 0;
        for (let i = 0; i < bank.length; i++) {
            if (bank[i].id === itemID) {
                qty += bank[i].qty;
            }
        }
        return qty;
    }

    // Reset variable
    var itemCraft = []
    var recordCraft = Infinity;
    var smithingMasteryLevel = smithingMastery[smithingItems[selectedSmith].smithingID].mastery;
    var chanceToKeep = 0;
    if (smithingMasteryLevel >= 80) {
        chanceToKeep = 40;
    } else if (smithingMasteryLevel >= 60) {
        chanceToKeep = 30;
    } else if (smithingMasteryLevel >= 40) {
        chanceToKeep = 20;
    } else if (smithingMasteryLevel >= 20) {
        chanceToKeep = 10;
    }
    //console.log('Chance to preserve resource: '+chanceToKeep);

    // Get Item Requirements and Current Requirements
    for (let i = 0; i < items[item].smithReq.length; i++) {
        if (equippedItems[CONSTANTS.equipmentSlot.Cape] === CONSTANTS.item.Smithing_Skillcape && items[item].smithReq[i].id == 48) {
            itemReq = Math.floor(items[item].smithReq[i].qty / 2)
        } else {
            itemReq = items[item].smithReq[i].qty;
        }
        //console.log('ItemReq: '+itemReq);
        itemQty = getSmithQtyUnformat(items[item].smithReq[i].id);
        //console.log('ItemQty['+items[item].smithReq[i].id+']: '+itemQty);
        // Calculate max items you can craft for each itemReq
        itemCraft[i] = Math.floor(itemQty/itemReq);
        //console.log('ItemCraft: '+itemCraft[i]);
        //console.log('Old Record: '+recordCraft)
        // Calculate limiting factor and set new record
        if(itemCraft[i] < recordCraft) {
            recordCraft = itemCraft[i];
            //console.log('New Record: '+recordCraft)
        };

    };

    window.timeLeftLast = window.timeLeftGlobal;

    //Calculate time
    var timeLeft = Math.floor(recordCraft * smithInterval / 1000 /(1-chanceToKeep/100));
    window.timeLeftGlobal = timeLeft;

    //Convert seconds to hours/minutes/seconds
    function secondsToHms(d) {
        d = Number(d);
        var h = Math.floor(d / 3600);
        var m = Math.floor(d % 3600 / 60);
        var s = Math.floor(d % 3600 % 60);
        var sDisplay = s > 0 ? s + (s == 1 ? " second" : " seconds") : "";
        var mDisplay = m > 0 ? m + (m == 1 ? " minute" : " minutes") + (s == "" ? "" : ", ") : "";
        var hDisplay = h > 0 ? h + (h == 1 ? " hour" : " hours") + ((s == "" && m == "") ? "" : ", ") : "";
        return hDisplay + mDisplay + sDisplay;
    };

    //Inject HTML
    elementToChange = document.getElementById("timeLeft");
	if (timeLeft !== 0) {
		if(elementToChange !== null) {
			elementToChange.innerHTML = secondsToHms(timeLeft) + " remaining";
		};
	} else {
		if(elementToChange !== null) {
			elementToChange.innerHTML = secondsToHms(timeLeft) + "";
		};
	};
};

var tempFunc = startSmithing;
window.startSmithing = function() {
    tempFunc(true);
    timeRemaining();
    if (window.timeLeftLast > 1 && window.timeLeftGlobal == 0) {
        notify("Task Done");
        console.log('task done');
        ding();
    };
    console.log('timeLeftLast'+window.timeLeftLast);
    console.log('timeLeftGlobal'+window.timeLeftGlobal);
};

var tempFunc2 = selectSmith;
window.selectSmith = function(smithingID) {
    tempFunc2(smithingID);
    timeRemaining();
};

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址