Enable Attack Button on Torn Profile Page

Enables the disabled button on Torn profile page when a player is in hospital and redirects to the attack page when the button is clicked

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Enable Attack Button on Torn Profile Page
// @namespace    https://lordrhino.co.uk/
// @version      1.2
// @description  Enables the disabled button on Torn profile page when a player is in hospital and redirects to the attack page when the button is clicked
// @match        https://www.torn.com/profiles.php?XID=*
// ==/UserScript==

(function() {
    'use strict';

    function enableButton(button) {
        if (button && button.classList.contains('disabled')) {
            button.classList.remove('disabled');
            button.classList.add('active');
            button.removeAttribute('aria-disabled');
            button.removeAttribute('href');
            button.addEventListener('click', handleButtonClick);
            button.querySelector('svg').removeAttribute('fill');
            button.querySelector('svg').setAttribute('fill', 'url(#linear-gradient-dark-mode)');
            button.style.border = '1px solid red';
        }
    }

    function handleButtonClick(event) {
        event.preventDefault();
        // Get the user ID from the button's ID
        const userID = new URLSearchParams(window.location.search).get('XID');

        // Redirect to the attack page with the user ID
        window.location.href = `https://www.torn.com/loader.php?sid=attack&user2ID=${userID}`;
    }

    const checkButtonAvailability = setInterval(function() {
        const buttons = document.querySelectorAll('[id^="button0-profile-"]');
        if (buttons.length > 0) {
            clearInterval(checkButtonAvailability);
            buttons.forEach(enableButton);
        }
    }, 1000);
})();