Guest User

Reddit chat icon hide userscript

a guest
Mar 21st, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name     Reddit chat icon hide
  3. // @version  1
  4. // @grant    none
  5. // @match https://www.reddit.com/*
  6. // ==/UserScript==
  7.  
  8.  
  9. // initial 'display: none' of chat icon and separator following it
  10. document.getElementById('chat').style.display = 'none'; // chat icon
  11. document.getElementById('chat').nextSibling.style.display = 'none'; // separator which follows chat section of navbar
  12.  
  13.  
  14. // Mutation Observer to cancel out the dynamic change in the DOM and keep the chat section of navbar hidden *for good*
  15. const observer = new MutationObserver(function(mutations) {
  16.     mutations.forEach(function(mutation) {
  17.         mutation.addedNodes[0].style.display = 'none'; // number of messages
  18.     mutation.previousSibling.style.display = 'none'; // chat icon
  19.     mutation.nextSibling.style.display = 'none'; // separator which follows chat section of navbar
  20.     });    
  21. });
  22.  
  23. const config = {
  24.     childList: true
  25. };
  26.  
  27. const targetNode = document.getElementById('header-bottom-right');
  28.  
  29. observer.observe(targetNode, config);
Add Comment
Please, Sign In to add comment