gavin19

Click score hides post

Jul 6th, 2017
106
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      http://userscripts.org/scripts/show/115446
  4. // @author         gavin19
  5. // @description    Clicking in between the up/down arrows hides the post.
  6. // @match          http://*.reddit.com/*
  7. // @include        http://*.reddit.com/*
  8. // @match          https://*.reddit.com/*
  9. // @include        https://*.reddit.com/*
  10. // @version        1.04f
  11. // ==/UserScript==
  12. (function () {
  13.     'use strict';
  14.     var hidePost = {
  15.         addScoreListeners: function (ele) {
  16.             var i, len;
  17.             for (i = 0, len = ele.length; i < len; i += 1) {
  18.                 ele[i].addEventListener('mouseover', hidePost.changeCursor, false);
  19.                 ele[i].addEventListener('click', hidePost.hideThis, false);
  20.             }
  21.         },
  22.         changeCursor: function (e) {
  23.             e = e || window.event;
  24.             var target = e.target || e.srcElement;
  25.             target.setAttribute('style', 'cursor:crosshair');
  26.         },
  27.         hideThis: function (e) {
  28.             e = e || window.event;
  29.             var target = e.target || e.srcElement;
  30.             var clickEvent = document.createEvent("MouseEvents");
  31.             clickEvent.initEvent("click", false, true);
  32.             target.parentNode.parentNode.querySelector('.hide-button a').dispatchEvent(clickEvent);
  33.         },
  34.         init: function () {
  35.             var t;
  36.             document.body.addEventListener('DOMNodeInserted', function (e) {
  37.                 t = e.target;
  38.                 if (t.localName === 'div' && t.id && t.id.indexOf('siteTable') !== -1) {
  39.                     hidePost.addScoreListeners(t.querySelectorAll('.link:not(.promoted) .midcol .score'));
  40.                 }
  41.             }, true);
  42.             hidePost.addScoreListeners(document.querySelectorAll('.link:not(.promoted) .midcol .score'));
  43.         }
  44.     };
  45.     if (document.body && document.querySelector('.listing-page.loggedin:not(.profile-page)')) {
  46.         setTimeout(function () {
  47.             hidePost.init();
  48.         }, 500);
  49.     }
  50. }());
Add Comment
Please, Sign In to add comment