gavin19

Reddit - Click score to hide post

Oct 2nd, 2011
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           Reddit - Click score to hide post
  3. // @namespace      gavin19
  4. // @description    Clicking in between the up/down arrows hides the post.
  5. // @match          http://*.reddit.com/*
  6. // @include        http://*.reddit.com/*
  7. // @version    1.02
  8. // ==/UserScript==
  9.  
  10. var hidePost = {
  11.  
  12.     addScoreListeners: function(ele) {
  13.         var clickEvent = document.createEvent("MouseEvents");
  14.         clickEvent.initEvent("click", false, true);
  15.         for (var i = 0, lens = ele.length; i < lens; i += 1) {
  16.             ele[i].addEventListener('mouseover', function() {
  17.                 this.setAttribute('style', 'cursor:crosshair');
  18.             });
  19.         }
  20.         for (var x = 0, lenx = ele.length; x < lenx; x += 1) {
  21.             ele[x].addEventListener('click', function() {
  22.                 this.parentNode.parentNode.querySelector('.hide-button a').dispatchEvent(clickEvent);
  23.             });
  24.         }
  25.     },
  26.     init: function() {
  27.         var ele, loc = window.location.href;
  28.         if (!(loc.match(/\/comments\//i) || loc.match(/\/user\//i))) {
  29.             ele = document.querySelectorAll('.midcol .score');
  30.             this.addScoreListeners(ele);
  31.             document.body.addEventListener('DOMNodeInserted', function(event) {
  32.                 if ((event.target.tagName == 'DIV') && (event.target.getAttribute('id') && event.target.getAttribute('id').indexOf('siteTable') != -1)) {
  33.                     ele = event.target.querySelectorAll('.midcol .score');
  34.                     hidePost.addScoreListeners(ele);
  35.                 }
  36.             }, true);
  37.         }
  38.     }
  39. };
  40. if (document.body) setTimeout(function() {
  41.     hidePost.init();
  42. }, 3000);
  43. else window.addEventListener("load", function() {
  44.     hidePost.init();
  45. }, false);
Add Comment
Please, Sign In to add comment