Hide Promotion Advertisement at Reddit Site

Hide links with rel="noopener nofollow sponsored"

// ==UserScript==
// @name         Hide Promotion Advertisement at Reddit Site
// @namespace    http://tampermonkey.net/
// @version      1.0.1
// @description  Hide links with rel="noopener nofollow sponsored"
// @author       aspen138
// @match        *://*.reddit.com/
// @icon         https://www.redditstatic.com/shreddit/assets/favicon/192x192.png
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to hide elements with a specific rel attribute value
    function hideElementsWithRel() {
        // Select all <a> elements on the page
        const links = document.querySelectorAll('a');

        // Iterate through all links
        links.forEach(link => {
            // Check if the rel attribute matches "noopener nofollow sponsored"
            if (link.getAttribute('rel') === "noopener nofollow sponsored") {
                // Hide the element
                link.style.display = 'none';
            }
        });
    }

    // Run the function on page load
    hideElementsWithRel();

    // Optional: If the page dynamically loads content, you may need to run the function again.
    // This can be achieved by setting an interval or using MutationObserver for a more advanced solution.
})();