Torn Defender Status

Adds status icon to defender name plate when attacking.

当前为 2025-07-01 提交的版本,查看 最新版本

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址