Torn Attack Enabler

Enables the attack button on profile pages and mini-profiles even if the target is in the hospital or otherwise unable to be attacked.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Torn Attack Enabler
// @namespace    http://tampermonkey.net/
// @version      1.4
// @description  Enables the attack button on profile pages and mini-profiles even if the target is in the hospital or otherwise unable to be attacked.
// @author       Deviyl[3722358]
// @match        https://www.torn.com/*
// @icon         https://raw.githubusercontent.com/deviyl/media/refs/heads/main/icons/devicon.png
// @grant        none
// @license      MIT
// @run-at       document-start
// ==/UserScript==

// Donations are always appreciated if you find this helpful. <3

(function() {
    'use strict';
    function enableAttackButton(button) {
        if (!button) return;
        if (button.dataset.enablerProcessed) return;
        let isOriginallyDisabled = button.classList.contains('disabled');
        const buttonDisabledClass = Array.from(button.classList).some(cls => cls.includes('disabled___') || cls.includes('_disabled___'));
        if (buttonDisabledClass) isOriginallyDisabled = true;
        const svgIcon = button.querySelector('svg');
        if (svgIcon && !isOriginallyDisabled) {
            const svgDisabledClass = Array.from(svgIcon.classList).some(cls => cls.includes('disabled___') || cls.includes('_disabled___') || cls.toLowerCase().includes('disabled'));
            if (svgDisabledClass) isOriginallyDisabled = true;
        }

        if (!isOriginallyDisabled) return;
        button.classList.remove('disabled');
        const elementsToClean = svgIcon ? [button, svgIcon] : [button];

        elementsToClean.forEach(el => {
            const classesToRemove = Array.from(el.classList).filter(cls => cls.includes('disabled___') || cls.includes('_disabled___'));
            classesToRemove.forEach(cls => el.classList.remove(cls));
        });

        button.style.setProperty('pointer-events', 'auto', 'important');
        button.style.setProperty('cursor', 'pointer', 'important');
        button.style.setProperty('opacity', '1', 'important');

        if (svgIcon) {
            svgIcon.style.setProperty('opacity', '1', 'important');
            svgIcon.style.setProperty('fill', '#ff3b30', 'important');
        }

        button.dataset.enablerProcessed = 'true';
        const clonedButton = button.cloneNode(true);
        clonedButton.style.setProperty('pointer-events', 'auto', 'important');
        clonedButton.style.setProperty('cursor', 'pointer', 'important');
        clonedButton.style.setProperty('opacity', '1', 'important');
        clonedButton.addEventListener('click', function(e) {
            e.stopPropagation();
            const href = clonedButton.getAttribute('href');
            if (href) window.location.href = href;
        }, true);
        button.parentNode.replaceChild(clonedButton, button);
    }

    function scanAndModify() {
        const attackButtons = document.querySelectorAll('a[href*="sid=attack"][class*="profile-button-attack"]');
        attackButtons.forEach(button => { enableAttackButton(button); });
    }

    const observer = new MutationObserver(() => { scanAndModify(); });
    const startObserver = () => {
        if (document.body) {
            observer.observe(document.body, {
                childList: true,
                subtree: true
            });
            scanAndModify();
        } else setTimeout(startObserver, 50);
    };

    startObserver();
    setInterval(scanAndModify, 1000);
})();