Torn Defender Status

Adds status icon to defender name plate when attacking.

目前為 2025-07-01 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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