Hide Active Trades

Adds a button that toggles visibility of active trades

  1. // ==UserScript==
  2. // @name Hide Active Trades
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Adds a button that toggles visibility of active trades
  6. // @author You
  7. // @match https://www.chickensmoothie.com/trades/tradingcenter.php*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=chickensmoothie.com
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Find the target div with id="csbody"
  16. const csbodyDiv = document.getElementById("csbody");
  17.  
  18. // Check if the target div exists
  19. if (csbodyDiv) {
  20. // Find all h2 elements inside the csbody div
  21. const h2Elements = csbodyDiv.querySelectorAll("h2");
  22.  
  23. // Check if there are at least two h2 elements
  24. if (h2Elements.length >= 2) {
  25. // Create the button
  26. let button = document.createElement("button");
  27. button.innerHTML = "Hide Active Trades";
  28.  
  29. // Add event listener for button click
  30. button.addEventListener("click", function() {
  31. // Find the table with id="active-trades" and toggle its visibility
  32. let activeTradesTable = document.querySelector('#active-trades');
  33. if (activeTradesTable) {
  34. activeTradesTable.style.display = (activeTradesTable.style.display === 'none' ? 'table' : 'none');
  35. }
  36. });
  37.  
  38. // Style the button to be inline with the h2 element
  39. button.style.display = 'inline-block';
  40. button.style.marginLeft = '10px'; // Optional: Add some space between h2 and button
  41.  
  42. // Insert the button next to the second h2 element (inline)
  43. h2Elements[1].appendChild(button);
  44. } else {
  45. console.error("There are less than two <h2> elements inside #csbody.");
  46. }
  47. } else {
  48. console.error("csbody div not found.");
  49. }
  50. })();