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, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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 getProfileID() {
    const url = new URL(location.href);
    const xid = url.searchParams.get('XID');
    if (xid && /^\d+$/.test(xid)) return xid;
    const m = location.href.match(/[?&]XID=(\d+)/i);
    return m ? m[1] : '';
  }
  const PROFILE_ID = getProfileID();

  function enableButton(button) {
    if (!button) return;
    if (button.classList.contains('disabled') || button.hasAttribute('disabled')) {
      button.classList.remove('disabled');
      button.classList.add('active');
      button.removeAttribute('aria-disabled');
      button.removeAttribute('disabled');
      button.removeAttribute('href');
      button.addEventListener('click', handleButtonClick);
      const svg = button.querySelector('svg');
      if (svg) {
        svg.removeAttribute('fill');
        svg.setAttribute('fill', 'url(#linear-gradient-dark-mode)');
      }
      button.style.border = '1px solid red';
      button.style.pointerEvents = 'auto';
      button.style.cursor = 'pointer';
      button.style.opacity = '1';
      button.style.filter = 'none';
    } else {
      button.addEventListener('click', handleButtonClick);
    }
  }

  function handleButtonClick(event) {
    event.preventDefault();
    if (!PROFILE_ID) {
      console.warn('Could not read XID from URL.');
      return;
    }
    window.location.href = `https://www.torn.com/loader.php?sid=attack&user2ID=${PROFILE_ID}`;
  }

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