Easy Execute %

Calculate and display Execute %

目前為 2024-05-11 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Easy Execute %
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Calculate and display Execute %
// @author       ChatGPT
// @match        https://www.torn.com/loader.php?sid=attack*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to calculate 19% of a value
    function calculatePercentage(value) {
        return value * 0.19; // Change this to your Execute %
    }

    // Function to extract maximum health value from the webpage and calculate 19% of it
    function updatePercentage() {
        // Select all elements whose ID contains "player-health-value_"
        var healthValueElements = document.querySelectorAll('[id^="player-health-value_"]');
        if (healthValueElements.length > 0) {
            healthValueElements.forEach(function(element) {
                var healthText = element.textContent.trim();
                var maxHealth = healthText.split("/")[1].replace(",", "").trim(); // Extract maximum health value
                var value = parseFloat(maxHealth);
                if (!isNaN(value)) {
                    var percentage = calculatePercentage(value);
                    // Display the result on the screen
                    displayPercentage(percentage);
                    // Log the result to the console
                    console.log("19% of maximum health is: " + percentage.toFixed(2));
                }
            });
        }
    }

    // Function to display the calculated percentage on the screen
    function displayPercentage(percentage) {
        var existingDisplay = document.getElementById("percentage-display");
        if (existingDisplay === null) {
            // Create a new element if it doesn't exist
            var displayElement = document.createElement("div");
            displayElement.id = "percentage-display";
            displayElement.style.position = "absolute";
            displayElement.style.top = "109px";
            displayElement.style.left = "950px";
            displayElement.style.background = "transparent";
            displayElement.style.padding = "8px";
            document.body.appendChild(displayElement);
            existingDisplay = displayElement;
        }
        // Round down the percentage to remove decimal points
        var roundedPercentage = Math.floor(percentage);
        // Update the content of the element with the new rounded percentage
        existingDisplay.textContent = "Execute HP: " + roundedPercentage;
    }

    // Call updatePercentage after a short delay to allow the page to fully load
    setTimeout(updatePercentage, 500); // delay

})();