Torn Defender Status

Adds status icon to defender name plate when attacking.

Verze ze dne 01. 07. 2025. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Torn Defender Status
// @namespace    http://tampermonkey.net/
// @version      1.0.0
// @description  Adds status icon to defender name plate when attacking.
// @author       Cypher-[2641265]
// @license      GNU GPLv3
// @match        https://www.torn.com/loader.php?sid=attack&user2ID=*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=torn.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const API_KEY = 'YOUR_API_KEY_HERE'; // <-- Replace with Public API Key

    const SVGs = {
        Online: `<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="-1.5 -1.2 14 14"><circle cx="6" cy="6" r="6" fill="#43d854" stroke="#fff" stroke-width="0"/></svg>`,
        Idle: `<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="-1.5 -1.2 14 14"><circle cx="6" cy="6" r="6" fill="#f7c325" stroke="#fff" stroke-width="0"/><rect x="5" y="3" width="4" height="4" fill="#f2f2f2"/></svg>`,
        Offline: `<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="-1.5 -1.2 14 14"><circle cx="6" cy="6" r="6" fill="#b3b3b3" stroke="#fff" stroke-width="0"/><rect x="3" y="5" width="6" height="2" fill="#f2f2f2"/></svg>`
    };

    const urlParams = new URLSearchParams(window.location.search);
    const userID = urlParams.get('user2ID');
    if (!userID) return;

    fetch(`https://api.torn.com/user/${userID}?selections=profile&key=${API_KEY}`)
        .then(res => res.json())
        .then(data => {
            if (!data || !data.last_action || !data.last_action.status) return;
            const state = data.last_action.status;
            const svg = SVGs[state] || SVGs.Offline;

            function insertIcon() {
                const usernameElement = document.querySelector('div[class*="rose"] .user-name');
                if (usernameElement) {
                    if (!usernameElement.previousSibling || !usernameElement.previousSibling.classList || !usernameElement.previousSibling.classList.contains('torn-status-icon')) {
                        const iconSpan = document.createElement('span');
                        iconSpan.className = 'torn-status-icon';
                        iconSpan.innerHTML = svg;
                        iconSpan.style.verticalAlign = "middle";
                        iconSpan.style.marginRight = "4px";
                        iconSpan.title = state;
                        usernameElement.parentNode.insertBefore(iconSpan, usernameElement);
                    }
                } else {
                    setTimeout(insertIcon, 200);
                }
            }
            insertIcon();
        });
})();