Torn Defender Status

Adds status icon to defender name plate when attacking.

01.07.2025 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

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