Torn Poker – Attack Button Above Players

Adds an attack button above poker player names linking to Torn attack page.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Torn Poker – Attack Button Above Players
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Adds an attack button above poker player names linking to Torn attack page.
// @author       X
// @match        https://www.torn.com/*
// @grant        none
// @run-at       document-idle
// @license Any
// ==/UserScript==


(function() {
    'use strict';

    const observed = new Set();

    function addAttackButton(playerBox) {
        if (observed.has(playerBox)) return;
        observed.add(playerBox);

        const idMatch = playerBox.id.match(/^player-(\d+)/);
        if (!idMatch) return;

        const playerID = idMatch[1];

        // Create the attack button
        const btn = document.createElement("a");
        btn.textContent = "Attack";
        btn.href = `https://www.torn.com/loader.php?sid=attack&user2ID=${playerID}`;
        btn.target = "_blank";

        // Style the button to bottom-right
        Object.assign(btn.style, {
            position: "absolute",
            bottom: "2px",
            right: "2px",
            padding: "2px 5px",
            background: "red",
            color: "white",
            borderRadius: "4px",
            fontSize: "11px",
            zIndex: 9999,
            textDecoration: "none",
            cursor: "pointer"
        });

        // Make sure the parent can handle absolute children
        const currentPosition = window.getComputedStyle(playerBox).position;
        if (currentPosition === "static" || !currentPosition) {
            playerBox.style.position = "relative";
        }

        playerBox.appendChild(btn);
    }

    function scanPlayers() {
        const players = document.querySelectorAll("[id^='player-']");
        players.forEach(addAttackButton);
    }

    // React updates — observe DOM changes
    const observer = new MutationObserver(scanPlayers);
    observer.observe(document.body, { childList: true, subtree: true });

    // Initial run
    scanPlayers();

})();