TweetDeck Clear and Remove Buttons

Adds "Clear" button to each column.

  1. // ==UserScript==
  2. // @name TweetDeck Clear and Remove Buttons
  3. // @namespace guebosch
  4. // @author guebosch, https://github.com/gregorb/TweetDeckClearButtons
  5. // @description Adds "Clear" button to each column.
  6. // @match https://tweetdeck.twitter.com/*
  7. // @match https://x.com/*
  8. // @version 2025-01-19
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. const debug = false;
  13.  
  14. const timer = window.setInterval( function() {
  15. // keep checking for new/updated columns every few seconds
  16.  
  17. if (debug) console.log("GB's TweetDeck Helper: Checking.");
  18.  
  19. // list all columns that don't have our "Clear" button yet
  20. const columnsToUpdate = document.querySelectorAll("div.column-header-links > a:not(.gb)");
  21. if (columnsToUpdate && columnsToUpdate.length) {
  22.  
  23. if (debug) console.log("GB's TweetDeck Helper: " + columnsToUpdate.length );
  24.  
  25. columnsToUpdate.forEach(function(value) {
  26. // value = options button
  27.  
  28. // tag it, so we know we've already been here
  29. value.className += " gb";
  30.  
  31. // an extra button may cause the original one to word-wrap out of view; this prevents that from happening
  32. value.parentNode.style.whiteSpace = 'nowrap';
  33.  
  34. const a = document.createElement("a");
  35. a.className = "js-action-header-button column-header-link gb";
  36. a.href = "#";
  37. a.innerHTML = '<i class="icon icon-clear-timeline"></i>';
  38. a.setAttribute("data-action", "clear");
  39. a.style.left = "200px";
  40. value.parentNode.insertBefore(a, value);
  41.  
  42. const b = document.createElement("a");
  43. b.className = "js-action-header-button column-header-link gb";
  44. b.href = "#";
  45. b.innerHTML = '<i class="icon icon-close"></i>';
  46. b.setAttribute("data-action", "remove");
  47. b.style.left = "200px";
  48. value.parentNode.insertBefore(b, value);
  49.  
  50. a.addEventListener("click", function(){
  51. value.click(); // open settings panel
  52. window.setTimeout(function(){
  53.  
  54. // find the root element of our column
  55. let clrButton = value;
  56. while ( clrButton && !clrButton.classList.contains('column-holder') )
  57. clrButton = clrButton.parentNode;
  58. if (!clrButton) {
  59. console.log("GB's TweetDeck Helper: column't root element not recognised; class-name changed?");
  60. return;
  61. }
  62.  
  63. // now find our column's "clear" button
  64. clrButton = clrButton.querySelector("button[data-action='clear']");
  65. if (!clrButton) {
  66. console.log("GB's TweetDeck Helper: column't 'Clear' button not found; class-name changed?");
  67. return;
  68. }
  69.  
  70. clrButton.click(); // click on original "clear" button
  71. value.click(); // close settings panel
  72.  
  73. }, 1000);
  74.  
  75. });
  76.  
  77. b.addEventListener("click", function(){
  78. value.click(); // open settings panel
  79. window.setTimeout(function(){
  80.  
  81. // find the root element of our column
  82. let clrButton = value;
  83. while ( clrButton && !clrButton.classList.contains('column-holder') )
  84. clrButton = clrButton.parentNode;
  85. if (!clrButton) {
  86. console.log("GB's TweetDeck Helper: column't root element not recognised; class-name changed?");
  87. return;
  88. }
  89.  
  90. // now find our column's "remove" button
  91. clrButton = clrButton.querySelector("button[data-action='remove']");
  92. if (!clrButton) {
  93. console.log("GB's TweetDeck Helper: column't 'Remove' button not found; class-name changed?");
  94. return;
  95. }
  96.  
  97. clrButton.click(); // click on original "remove" button
  98. value.click(); // close settings panel
  99.  
  100. }, 1000);
  101.  
  102. });
  103.  
  104. });
  105.  
  106. }
  107.  
  108. }, 3000 );
  109.