Skip to content

Instantly share code, notes, and snippets.

@Yukaii
Last active October 12, 2024 12:12
Show Gist options
  • Save Yukaii/a79890678bacac181e4b66a1e22f3a2d to your computer and use it in GitHub Desktop.
Save Yukaii/a79890678bacac181e4b66a1e22f3a2d to your computer and use it in GitHub Desktop.
Hide reddit promoted post

Hide Reddit Promoted Posts

A Tampermonkey user script that automatically hides promoted (advertisement) posts on Reddit. By targeting specific CSS classes used for promoted content, this script removes those posts from view, providing a cleaner browsing experience.

Features

  • Automatically hides promoted posts on Reddit.
  • Detects dynamically loaded posts using MutationObserver.
  • Works seamlessly on page load and as you scroll.

Installation

To install the script, follow these steps:

  1. Install Tampermonkey (or another user script manager) for your browser.
  2. Click the link below to install the script:

How it Works

This script scans for Reddit's promoted posts using specific CSS class names and hides them by setting their display property to none. It continues to monitor the page for any newly loaded promoted content and hides those as well.

License

This project is open-source and available under the MIT License.

// ==UserScript==
// @name Hide Reddit Promoted Posts
// @namespace http://tampermonkey.net/
// @version 1.0.1
// @description Hide promoted posts on Reddit
// @author Yukai Huang
// @match *://www.reddit.com/*
// @grant none
// @downloadURL https://gist.github.com/Yukaii/a79890678bacac181e4b66a1e22f3a2d/raw/hide-reddit-promoted-posts.user.js
// @updateURL https://gist.github.com/Yukaii/a79890678bacac181e4b66a1e22f3a2d/raw/hide-reddit-promoted-posts.user.js
// ==/UserScript==
(function() {
'use strict';
// Function to hide promoted posts
function hidePromotedPosts() {
let promotedPosts = document.querySelectorAll('.promotedlink.block.relative');
promotedPosts.forEach(post => {
post.style.display = 'none';
});
}
// Run the function when the page loads
window.addEventListener('load', hidePromotedPosts);
// Also observe DOM changes to catch dynamically loaded posts
let observer = new MutationObserver(hidePromotedPosts);
observer.observe(document.body, { childList: true, subtree: true });
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment