gavin19

Reddit - Collapse [deleted] comments

Oct 22nd, 2011
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           Reddit - Collapsed deleted comments
  3. // @author         gavin19
  4. // @description    Collapse deleted comments.
  5. // @match          http://*.reddit.com/*/*/comments/*
  6. // @include        http://*.reddit.com/*/*/comments/*
  7. // @version        1.0
  8. // ==/UserScript==
  9.  
  10. var collapseComments = {
  11.  
  12.     hideDeleted: function(x) {
  13.         for (var i = 0, lenx = x.length; i < lenx; i++) {
  14.             if (x[i]) {
  15.                 x[i].parentNode.setAttribute('style', 'display:none !important');
  16.             }
  17.         }
  18.     },
  19.     init: function() {
  20.         var x;
  21.         document.body.addEventListener('DOMNodeInserted', function(event) {
  22.             if ((event.target.tagName == 'DIV') && (/comment/ig.test(event.target.getAttribute('class')))) {
  23.                 x = event.target.querySelectorAll('.content .grayed');
  24.                 collapseComments.hideDeleted(x);
  25.             }
  26.         }, false);
  27.         x = document.querySelectorAll('.content .grayed');
  28.         this.hideDeleted(x);
  29.     }
  30. }
  31. if (document.body) setTimeout(function() {
  32.     collapseComments.init();
  33. }, 3000);
  34. else window.addEventListener("load", function() {
  35.     collapseComments.init();
  36. }, false);
Add Comment
Please, Sign In to add comment