gavin19

Reddit - Hide Posts

Aug 26th, 2011
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name          Reddit - Hide posts
  3. // @namespace     null
  4. // @description   Hide posts based on user prefs.
  5. // @match         http://reddit.com/*
  6. // @match         https://reddit.com/*
  7. // @match         http://*.reddit.com/*
  8. // @match         https://*.reddit.com/*
  9. // @include        http://reddit.com/*
  10. // @include        https://reddit.com/*
  11. // @include        http://*.reddit.com/*
  12. // @include        https://*.reddit.com/*
  13. // @version       1.00
  14. // ==/UserScript==
  15.  
  16. // Add subreddits which this script will run on followed by a comma (except the last entry).
  17. var subs = [
  18.   "gameswap"
  19. ];
  20.  
  21. // Check to see if URL matches chosen subs. If so then proceed.
  22. function init() {
  23.   var loc = window.location.href;
  24.   for(var i=0;i<=subs.length-1;i++){
  25.     if(loc.match(subs[i])){
  26.         hidePosts();
  27.     }
  28.   }
  29. }
  30.  
  31. // Hide posts which match 'Includes' but not 'Excludes'.
  32. function hidePosts() {
  33.  
  34. var matches = [];
  35.  
  36. // Grab all instances of posts.
  37. var s = document.querySelectorAll('div#siteTable div.entry a.title');
  38.  
  39. // Add words to look for in the title to hide.
  40. var matchIncludes = [
  41. /360/i
  42. ];
  43.  
  44. // Add words to look for in the title NOT to hide if they also appear with 'Includes'.
  45. var matchExcludes = [
  46. /PS3/i,
  47. /Playstation 3/i
  48. ];
  49.  
  50. // Loop through all the posts to search for a match and hide that post.
  51. for(var i=0;i<=s.length-1;i++) {
  52.     for(j=0,len=matchIncludes.length;j<=len-1;j++){
  53.         if(s[i].innerHTML.match(matchIncludes[j])){
  54.             matches.push(s[i]);
  55.             }
  56.         }
  57. }
  58.  
  59. for(var t=0;t<=matchExcludes.length-1;t++){
  60.     for(var n in matches){
  61.         if(matches[n].innerHTML.match(matchExcludes[t])){
  62.             matches[n].parentNode.parentNode.parentNode.setAttribute('style', 'display:none !important');
  63.         }
  64.     }
  65. }
  66.  
  67. }
  68.  
  69. init();
Add Comment
Please, Sign In to add comment