Execute HP

Add Execute Under X HP to Secondary Weapon

当前为 2024-10-28 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Execute HP
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Add Execute Under X HP to Secondary Weapon
// @author       Stig [2648238]
// @match        https://www.torn.com/loader.php?*
// @grant        none
// ==/UserScript==

const executePercent = 29; // Change this to your Execute %

(function() {
    'use strict';

    function getPercentage(value) {
        var raw = value * (executePercent / 100);
        return Math.floor(raw);
    }

    function waitForElement(selector, callback) {
        let el = document.querySelector(selector);
        if (el) {
            callback(el);
        } else {
            setTimeout(function() {
                waitForElement(selector, callback);
            }, 500); // checks every 500ms
        }
    }

    function getHealth() {
        var healthValueElements = document.querySelectorAll('[id^="player-health-value_"]');
        if (healthValueElements.length > 0) {
            for (let element of healthValueElements) {
                var healthText = element.textContent.trim();
                var maxHealth = healthText.split("/")[1].replace(",", "").trim(); // Extract maximum health value
                var value = parseFloat(maxHealth);

                if (!isNaN(value)) {
                    return getPercentage(value);
                }
            }
        }
        return 0; // Default return if no health value found
    }

    function render() {
        var weaponSecond = document.getElementById('weapon_second');
        if (weaponSecond) {
            var targetDiv = weaponSecond.querySelector('.bottom___XSBgG');
            if (targetDiv) {
                var newDiv = document.createElement('div');
                newDiv.className = 'custom-execute-under';

                var underHP = getHealth();
                newDiv.textContent = `Execute Under: ${underHP} HP`;
                targetDiv.parentNode.insertBefore(newDiv, targetDiv.nextSibling);

                // Add CSS
                var css = `.custom-execute-under {position: absolute; top: 70px; left: 24px; font-size: 10px; color: red;}`;
                var style = document.createElement('style');
                document.head.appendChild(style);
                style.appendChild(document.createTextNode(css));
            }
        }
    }

    waitForElement('.entry___m0IK_', function() {
        render();
    });
})();