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

  1. // ==UserScript==
  2. // @name Enable Attack Button on Torn Profile Page
  3. // @namespace https://lordrhino.co.uk/
  4. // @version 1.1
  5. // @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
  6. // @match https://www.torn.com/profiles.php?XID=*
  7. // ==/UserScript==
  8.  
  9. (function() {
  10. 'use strict';
  11.  
  12. function enableButton(button) {
  13. if (button && button.classList.contains('disabled')) {
  14. button.classList.remove('disabled');
  15. button.classList.add('active');
  16. button.removeAttribute('aria-disabled');
  17. button.removeAttribute('href');
  18. button.addEventListener('click', handleButtonClick);
  19. button.querySelector('svg').removeAttribute('fill');
  20. button.querySelector('svg').setAttribute('fill', 'url(#linear-gradient-dark-mode)');
  21. button.style.border = '1px solid red';
  22. }
  23. }
  24.  
  25. function handleButtonClick(event) {
  26. event.preventDefault();
  27. // Get the user ID from the button's ID
  28. const userID = event.target.id.replace('button0-profile-', '');
  29. // Redirect to the attack page with the user ID
  30. window.location.href = `https://www.torn.com/loader.php?sid=attack&user2ID=${userID}`;
  31. }
  32.  
  33. const checkButtonAvailability = setInterval(function() {
  34. const buttons = document.querySelectorAll('[id^="button0-profile-"]');
  35. if (buttons.length > 0) {
  36. clearInterval(checkButtonAvailability);
  37. buttons.forEach(enableButton);
  38. }
  39. }, 1000);
  40. })();