Remove annoying users from StackOverflow

Masks out the comments and the names of users you don't like on StackOverflow

  1. // ==UserScript==
  2. // @namespace https://trajano.net
  3. // @name Remove annoying users from StackOverflow
  4. // @description Masks out the comments and the names of users you don't like on StackOverflow
  5. // @version 1
  6. // @include https://stackoverflow.com/*
  7. // @grant none
  8. // @license EPL-2.0
  9. // ==/UserScript==
  10. (function() {
  11. 'use strict';
  12.  
  13. const ids = [-1, 1507691, 216691, 3001761, 4216641];
  14. const selector = ids.map(( id ) => `[data-comment-owner-id="${id}"]`);
  15. const styles = `
  16. ${selector.map( s => `${s} .comment-copy > *`)},
  17. ${selector.map( s => `${s} .comment-date > *`)} {
  18. color: transparent;
  19. background: rgba(0, 0, 0, 0.15);
  20. }
  21. ${selector.map( s => `${s} div a.comment-user`)} {
  22. display: none;
  23. }
  24. `;
  25.  
  26. document.head.appendChild(
  27. document.createElement("style")
  28. ).innerHTML = styles;
  29.  
  30. function maskComments () {
  31. document.querySelectorAll(selector.join(',')).forEach(createMask);
  32. }
  33.  
  34. function createMask ( element ) {
  35. const commentCopy = element.querySelector(".comment-copy");
  36. for ( const child of commentCopy.childNodes ) {
  37. if ( child.nodeName === "#text" && child.nodeValue !== " " ) {
  38. const fragment = document.createDocumentFragment();
  39. for ( const token of child.nodeValue.split(" ") ) {
  40. const span = document.createElement("span");
  41. span.textContent = token;
  42. fragment.append(span, " ");
  43. }
  44. commentCopy.replaceChild( fragment, child );
  45. }
  46. }
  47. }
  48.  
  49. maskComments();
  50.  
  51. })();