DOTV To Next Level Timer

Estimates Time needed to naturally level

目前為 2023-08-29 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         DOTV To Next Level Timer
// @namespace    https://greasyfork.org/users/1159361
// @version      1.5
// @license MIT
// @description  Estimates Time needed to naturally level
// @author       Zaregoto_Gaming
// @match        https://play.dragonsofthevoid.com/*
// @grant        GM_getValue
// @grant        GM_setValue
// ==/UserScript==
(function() {
    //Public varaibles
    var newSpan;
    //Let page load before adding TNL text into EXP bar
    function timedExecution() {
        if (typeof document.getElementsByClassName("chat-container")[0] === "object") {
            tnlCounter();
            console.log("TNL Script Running");
        } else {
            setTimeout(timedExecution, 1000);
        }
    }
    //TNL Counter
    function tnlCounter(){
        // Create a new <span> element
        newSpan = document.createElement("span");
        newSpan.id = "tnl-span";
        newSpan.title = "TNL"; // Set the "title" attribute
        newSpan.style.fontSize = "max(14px, var(--min-font-size))"; // Set the "style" attribute
        newSpan.style.marginLeft = "20px"; // Add left margin to create spacing
        //Copy attribute so it doesnt break on app updates
        // Get an existing element from which you want to clone attributes
        const existingElement = document.querySelector('.level-up-bar-container .ammount-left span');
        // Clone attributes from the existing element and apply them to the new element
        const attributes = existingElement.attributes;
        for (const attribute of attributes) {
            newSpan.setAttribute(attribute.name, attribute.value);
        }
        // Get the element with class name "level-up-bar-container"
        const containerElement = document.querySelector('.level-up-bar-container');

        // Add a click event listener to the container element
        containerElement.addEventListener("click", function() {
            scrapeUserData(); // Trigger INFO fetch
        });

        // Get the existing <div> element with class name "ammount-left" within the container
        const existingDiv = document.querySelector('.level-up-bar-container .ammount-left');

        // Append the new <span> after the existing <span>
        existingDiv.appendChild(newSpan);

        scrapeUserData();

        // Set up a timer to call scrapeUserData every minute
        setInterval(scrapeUserData, 600000); // 60000 milliseconds = 1 minute // set to 10min
    }
    // Fetch User Info for TNL Calc
    async function scrapeUserData() {
        const bearerToken = getBearerToken();
        const response = await fetch("https://api.dragonsofthevoid.com/api/user/info", {
            headers: {
                Authorization: bearerToken,
            },
            referrer: "https://play.dragonsofthevoid.com/",
            referrerPolicy: "strict-origin-when-cross-origin",
            body: null,
            method: "GET",
            mode: "cors",
        });

        if (!response.ok) {
            throw new Error("Network response was not ok");
        }

        const responseData = await response.json();

        // Extract vitality, honor, and energy values
        const vitality = responseData.payload.user.vitality;
        const honor = responseData.payload.user.honor;
        const energy = responseData.payload.user.energy;
        const playerLevel = responseData.payload.user.level;
        const totalRSC = energy + honor + vitality;

        // Calculate remaining experience points needed to level up
        const remainingExpSpan = document.querySelector('.level-up-bar-container .ammount-left span[title]');
        const remainingExpTitle = remainingExpSpan.getAttribute('title');
        const remainingExp = parseInt(remainingExpTitle.replace(/,/g, '')); // Remove commas and parse

        // Calculate required resources
        const requiredRSC = Math.ceil(remainingExp / 1.45);
        //Find RSCPerMIn by Player Lvl
        let RSCPerMin;
        if (playerLevel < 100) {
            RSCPerMin = 1.6; // Set value for level under 100
        } else if (playerLevel >= 100 && playerLevel < 500) {
            RSCPerMin = 1.712; // Set value for level between 100 and 500
        } else if (playerLevel >= 500 && playerLevel < 1000) {
            RSCPerMin = 1.95; // Set value for level between 500 and 1000
        } else {
            RSCPerMin = 2.19; // Set value for level 1000 and 1,999
        }

        console.log("Average Resource Regen Per Minute:", RSCPerMin);
        newSpan.style.marginLeft = "20px";
        const existingDiv = document.querySelector('.level-up-bar-container .ammount-left');
        //Calc if Auto Leveling and time needed to regen to level
        if (totalRSC * 1.45 >= remainingExp) {
            newSpan.textContent = calculateTimeString(0); // Auto Leveling
            console.log("Auto Leveling: True");

        } else {
            const timeToLevelUp = (requiredRSC - totalRSC) / RSCPerMin;
            newSpan.innerHTML = calculateTimeString(timeToLevelUp) + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Estimated Resources Needed: " + totalRSC +" / "+ requiredRSC;
            console.log("Auto Leveling: False");
        }
        console.log("Resources needed to Level:", requiredRSC);
        //alert("You need " + requiredRSC + " resources to level");

    }
    //Function to calculate the time string
    function calculateTimeString(timeToLevelUp) {
        if (timeToLevelUp <= 0) {
            return "Auto Leveling";
        }

        let timeString = "";

        if (timeToLevelUp >= 1140) {
            const days = Math.floor(timeToLevelUp / 1440);
            timeString += days + "d ";
            timeToLevelUp %= 1440;
        }

        const hours = Math.floor(timeToLevelUp / 60);
        const minutes = Math.floor(timeToLevelUp % 60);

        if (hours > 0) {
            timeString += hours + "h ";
        }

        if (minutes > 0) {
            timeString += minutes + "min";
        }

        return timeString;
        console.log("TNL:", timeString);
    }
    // Function to retrieve the bearer token from localStorage
    function getBearerToken() {
        return this.localStorage.token || "Bearer Token Not Found";
    }
    // Start the timed execution.
    timedExecution();
})();