Estimates Time needed to naturally level
当前为
// ==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) + " 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();
})();