Torn Defender Status

Adds status icon to defender name plate when attacking.

Stan na 01-07-2025. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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();
        });
})();