Torn Remove RR Acts of Courage

Removes the x2 and x3 'Acts of Courage' from Russian Roulette games, and adds a 'x2' button to the RR link menu to toggle visibility

  1. // ==UserScript==
  2. // @name Torn Remove RR Acts of Courage
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description Removes the x2 and x3 'Acts of Courage' from Russian Roulette games, and adds a 'x2' button to the RR link menu to toggle visibility
  6. // @author pawl [1821105]
  7. // @match https://www.torn.com/page.php?sid=russianRoulette*
  8. // @icon https://www.google.com/s2/favicons?domain=torn.com
  9. // @grant GM_addStyle
  10.  
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. console.log("Torn Remove RR Acts of Courage started");
  17.  
  18. function toggleButtonVisibility(targetButtons) {
  19. targetButtons.forEach(button => {
  20. if (button.style.display === 'none' || button.style.display === '') {
  21. button.style.setProperty('display', 'inline-block', 'important');
  22. } else {
  23. button.style.setProperty('display', 'none', 'important');
  24. }
  25. });
  26. }
  27.  
  28. window.addEventListener('load', () => {
  29. const container = document.querySelector('.linksContainer___LiOTN');
  30.  
  31. if (!container) return;
  32.  
  33. const toggleButton = document.createElement('button');
  34. toggleButton.textContent = 'x2';
  35.  
  36. toggleButton.style.fontWeight = '700';
  37. toggleButton.style.fontSize = '12px';
  38. toggleButton.style.color = 'var(--appheader-links-color)';
  39. toggleButton.style.textShadow = 'var(--appheader-links-text-shadow-color)';
  40.  
  41. container.insertBefore(toggleButton, container.firstChild);
  42.  
  43. GM_addStyle(`
  44. button[data-id='2'],
  45. button[data-id='3'] {
  46. display: none !important;
  47. }
  48. `);
  49.  
  50. function getTargetButtons() {
  51. return Array.from(document.querySelectorAll('button[data-id="2"], button[data-id="3"]'));
  52. }
  53.  
  54. toggleButton.addEventListener('click', () => {
  55. const targetButtons = getTargetButtons();
  56. toggleButtonVisibility(targetButtons);
  57. });
  58.  
  59. });
  60. })();