Discord/Shapes - < > Hider

Hide elements enclosed by < > in Discord

  1. // ==UserScript==
  2. // @name Discord/Shapes - < > Hider
  3. // @namespace https://discord.com/
  4. // @version 1.3
  5. // @description Hide elements enclosed by < > in Discord
  6. // @author Vishanka
  7. // @match https://discord.com/channels/*
  8. // @grant none
  9. // @run-at document-idle
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14.  
  15. function hideEnclosedEntries() {
  16. const messageItems = document.querySelectorAll('li[class^="messageListItem_"]');
  17.  
  18. messageItems.forEach(messageItem => {
  19. const spans = messageItem.querySelectorAll('div[class*="messageContent_"] span');
  20.  
  21. let isHiding = false;
  22. spans.forEach(span => {
  23. const text = span.textContent.trim();
  24.  
  25. // Start hiding when encountering '<'
  26. if (text.startsWith('<') && !isHiding) {
  27. isHiding = true;
  28. }
  29.  
  30. // Apply hiding style if within an enclosed entry
  31. if (isHiding) {
  32. span.style.opacity = '0'; // Make it invisible
  33. span.style.position = 'absolute'; // Remove it from the document flow
  34. }
  35.  
  36. // Stop hiding when encountering '>'
  37. if (text.endsWith('>') && isHiding) {
  38. isHiding = false;
  39. }
  40. });
  41. });
  42. }
  43.  
  44. // Observe for new messages being added to the DOM
  45. const observer = new MutationObserver(mutations => {
  46. mutations.forEach(() => {
  47. hideEnclosedEntries();
  48. });
  49. });
  50.  
  51. // Start observing the entire document body for changes
  52. observer.observe(document.body, { childList: true, subtree: true });
  53.  
  54. // Initial run
  55. hideEnclosedEntries();
  56. })();