Skip to content

Instantly share code, notes, and snippets.

@khlam
Created January 29, 2022 10:03
Show Gist options
  • Select an option

  • Save khlam/7fd08d16edbb5777770055350a53125c to your computer and use it in GitHub Desktop.

Select an option

Save khlam/7fd08d16edbb5777770055350a53125c to your computer and use it in GitHub Desktop.
userscript / greasemonkey / violentmonkey script to hide all posts from a subreddit by name (not case sensitive) or by regex
// ==UserScript==
// @name subreddit_blocker
// @description Hides all posts from subreddits by name (not case sensitive) or by regex.
// @author khlam
// @match http://*.reddit.com/*
// @match https://*.reddit.com/*
// @version 0.0
// ==/UserScript==
const regex = [] // your regex block here, comma seperated.
//const regex = [/news/, /memes/] // <--- will block /r/worldnews, /r/news, /r/meme, and /r/memes
const blacklisted_subs = [ // specific subreddits to never show posts from, comma separated
"worldnews" // <--- will block /r/worldnews, not case sensitive
]
let blacklisted_subs_lower = blacklisted_subs.map(e => { return e.toLowerCase() }) // all blacklisted subreddits to lowercase
let all_threads = document.querySelectorAll("[data-subreddit]")
all_threads.forEach(thread => {
let this_sub = thread.getAttribute('data-subreddit').toLowerCase() // post's subreddit to lowercase
// if subreddit is in blacklist or if subreddit matches regex then hide it
if ((blacklisted_subs_lower.includes(this_sub) === true) || regex.some(function(r) { return r.test(this_sub)}) === true) {
console.log("HIDING", thread)
//thread.innerHTML = `Content from ${this_sub} hidden.`
thread.style.display = "none"
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment