DOTV To Next Level Timer

Estimates Time needed to naturally level

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

// ==UserScript==
// @name         DOTV To Next Level Timer
// @namespace    http://tampermonkey.net/
// @version      1.1
// @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() {
    //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 Injected");
        } else {
            setTimeout(timedExecution, 1000);
        }
    }
    //TNL Counter
    function tnlCounter(){
        // Create a new <span> element
        const 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.textContent = "Fetching Data"; // Set the content of the new <span>
        newSpan.style.marginLeft = "10px"; // Add left margin to create spacing
        newSpan.setAttribute("data-v-9bf4bb04","");
        // 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);

        // Set up a timer to call scrapeUserData every minute
        setInterval(scrapeUserData, 60000); // 60000 milliseconds = 1 minute
    }
    // 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 totalRSS = 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 requiredRSS = Math.ceil(remainingExp / 1.5);

        // Create a new <span> element
        const newSpan = document.getElementById("tnl-span");
        newSpan.title = "TNL";
        newSpan.style.fontSize = "max(14px, var(--min-font-size))";
        newSpan.style.marginLeft = "10px";
        newSpan.setAttribute("data-v-9bf4bb04", "");

        if (totalRSS * 1.5 >= remainingExp) {
            newSpan.textContent = calculateTimeString(0); // Auto Leveling
            console.log("Auto Leveling True:");

        } else {
            const timeToLevelUp = (requiredRSS - totalRSS) / 1.6;
            newSpan.textContent = calculateTimeString(timeToLevelUp);
            console.log("Auto Leveling False:");
        }
        console.log("RequiredRSS:", requiredRSS);
        console.log("TotalRSS:", totalRSS);
        console.log("Remaining EXP:", remainingExp);

    }
    //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;
    }
    // Function to retrieve the bearer token from localStorage
    function getBearerToken() {
        return this.localStorage.token || "Bearer Token Not Found";
    }
    // Start the timed execution.
    timedExecution();
})();

QingJ © 2025

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