Reddit /r/all Filter by Keywords (Robust)

Hide Reddit posts on /r/all if they match specific keywords in the title (supports infinite scroll)

  1. // ==UserScript==
  2. // @name Reddit /r/all Filter by Keywords (Robust)
  3. // @namespace http://tampermonkey.net/
  4. // @version 6.0
  5. // @description Hide Reddit posts on /r/all if they match specific keywords in the title (supports infinite scroll)
  6. // @match https://www.reddit.com/r/all*
  7. // @grant none
  8. // @run-at document-idle
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. 'use strict';
  13.  
  14. // ADD YOUR BLOCKED POST KEYWORDS HERE
  15. const blockedKeywords = [
  16. 'trump',
  17. 'kardashian',
  18. 'elon',
  19. 'crypto',
  20. 'taylor swift'
  21. ];
  22.  
  23. function filterPosts() {
  24. const titles = document.querySelectorAll('faceplate-screen-reader-content');
  25.  
  26. titles.forEach(titleEl => {
  27. const text = titleEl.textContent.toLowerCase().trim();
  28. const post = titleEl.closest('shreddit-post');
  29. if (!post || post.dataset.filtered === 'true') return;
  30.  
  31. if (blockedKeywords.some(keyword => text.includes(keyword))) {
  32. post.style.display = 'none';
  33. post.dataset.filtered = 'true';
  34. console.log(`[Filtered]: ${text}`);
  35. }
  36. });
  37. }
  38.  
  39. // Observe DOM mutations for endless scroll
  40. const observer = new MutationObserver(filterPosts);
  41. observer.observe(document.body, { childList: true, subtree: true });
  42.  
  43. // Fallback for missed posts
  44. setInterval(filterPosts, 1500);
  45.  
  46. // Initial run
  47. window.addEventListener('load', filterPosts);
  48. })();