Doobie's Hospital Button Bypass For Torn City

Enables attack button even if the target is in the hospital, changes icon to red, and works on Left click hold menu

当前为 2024-11-13 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Doobie's Hospital Button Bypass For Torn City
// @namespace    http://tampermonkey.net/DoobiesHospitalBypass
// @version      1.6
// @description  Enables attack button even if the target is in the hospital, changes icon to red, and works on Left click hold menu
// @match        https://www.torn.com/profiles.php*
// @match        https://www.torn.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function updateAttackButton(button) {
        if (button && button.classList.contains('disabled')) {
            button.classList.remove('disabled');
            button.classList.add('active');
            button.style.pointerEvents = 'auto';
            button.style.opacity = '1';
            button.setAttribute('aria-label', 'Attack (Bypass Hospital Restriction)');

            let svgIcon = button.querySelector('svg');
            if (svgIcon) {
                svgIcon.style.filter = 'none';
                svgIcon.style.fill = '#cf3b13';
            }

            button.addEventListener('click', function(e) {
                e.preventDefault();
                const attackUrl = button.getAttribute('href');
                if (attackUrl) {
                    window.location.href = attackUrl;
                }
            });
        }
    }

    function enableWarAttackButton() {
        const outOfHospitalAttackButtons = document.querySelectorAll('.attack.left.attack___wBWp2 a.t-blue.h.c-pointer');
        outOfHospitalAttackButtons.forEach(button => {
            if (!button.classList.contains('disabled')) {
                updateAttackButton(button);
            }
        });

        const inHospitalAttackSpans = document.querySelectorAll('.status.left.hospital .t-gray-9');
        inHospitalAttackSpans.forEach(span => {
            const attackUrl = span.closest('.status.left.hospital').querySelector('a');
            if (attackUrl) {
                const newButton = document.createElement('a');
                newButton.href = attackUrl.href;
                newButton.classList.add('t-blue', 'h', 'c-pointer');
                newButton.innerText = 'Attack';
                span.replaceWith(newButton);
                updateAttackButton(newButton);
            }
        });
    }

    function initializeObserver() {
        const observer = new MutationObserver(function(mutations) {
            mutations.forEach(function(mutation) {
                if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
                    mutation.addedNodes.forEach(function(node) {
                        if (node.nodeType === 1) {
                            enableWarAttackButton();
                            const profileAttackButton = document.querySelector('.profile-button-attack.disabled');
                            if (profileAttackButton) updateAttackButton(profileAttackButton);

                            const miniAttackButtons = document.querySelectorAll('[id^="mini-button"].profile-button-attack.disabled');
                            miniAttackButtons.forEach(button => updateAttackButton(button));
                        }
                    });
                }
            });
        });

        const targetNode = document.body;
        observer.observe(targetNode, { childList: true, subtree: true });
    }

    window.onload = function() {
        initializeObserver();
        enableWarAttackButton();
        const profileAttackButton = document.querySelector('.profile-button-attack.disabled');
        if (profileAttackButton) updateAttackButton(profileAttackButton);

        const miniAttackButtons = document.querySelectorAll('[id^="mini-button"].profile-button-attack.disabled');
        miniAttackButtons.forEach(button => updateAttackButton(button));
    };

})();

// Made with Love By Doobiesuckin