gavin19

Reddit - Auto-hide post voting.

Sep 19th, 2011
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           Reddit - Up/downvotes hide post
  3. // @author      gavin19
  4. // @description    Hides post upon voting.
  5. // @match          http://*.reddit.com/*
  6. // @include      http://*.reddit.com/*
  7. // @match          https://*.reddit.com/*
  8. // @include      https://*.reddit.com/*
  9. // @version    1.0
  10. // ==/UserScript==
  11. var scoreHidesPost = {
  12.  
  13.     addArrowListeners: function(ele) {
  14.         var clickEvent = document.createEvent("MouseEvents");
  15.         clickEvent.initEvent("click", false, true);
  16.         for (var x = 0, lenx = ele.length; x < lenx; x += 1) {
  17.             ele[x].addEventListener('mouseup', function() {
  18.                 this.parentNode.parentNode.querySelector('.hide-button a').dispatchEvent(clickEvent);
  19.             });
  20.         }
  21.     },
  22.     init: function() {
  23.         var ele, loc = window.location.href;
  24.         if (!(loc.match(/\/comments\//i)) || !(loc.match(/\/user\//i)) || !(loc.match(/\/message\//i))) {
  25.             ele = document.querySelectorAll('.midcol .arrow');
  26.             this.addArrowListeners(ele);
  27.             document.body.addEventListener('DOMNodeInserted', function(event) {
  28.                 if ((event.target.tagName == 'DIV') && (event.target.getAttribute('id') && event.target.getAttribute('id').indexOf('siteTable') != -1)) {
  29.                     ele = event.target.querySelectorAll('.midcol .arrow');
  30.                     scoreHidesPost.addArrowListeners(ele);
  31.                 }
  32.             }, true);
  33.         }
  34.         }
  35.     };
  36.     if (document.body) {
  37.         setTimeout(function() {
  38.             scoreHidesPost.init();
  39.         }, 3000);
  40.     }
  41.     else {
  42.         window.addEventListener("load", function() {
  43.             scoreHidesPost.init();
  44.         }, false);
  45.     }
Add Comment
Please, Sign In to add comment