Filter reddit post with certain keywords in the title

Hide elements with specific text content

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Filter reddit post with certain keywords in the title
// @namespace    Filter reddit post
// @version      1.0.1
// @description  Hide elements with specific text content
// @author       ein
// @match        https://new.reddit.com/*
// @license MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function getKeywords() {
        // edit your keywords here
        return /keyword1|keyword2|keyword3/i;
    }

    function hideElements() {
        var elements = document.querySelectorAll('._2FCtq-QzlfuN-SwVMUZMM3');
        var keywords = getKeywords();
        elements.forEach(function(el) {
            if (keywords.test(el.innerText)) {
                var ancestor = el.closest('._1Qs6zz6oqdrQbR7yE_ntfY, ._3xuFbFM3vrCqdGuKGhhhn0').parentElement.parentElement;
                if (ancestor) {
                    ancestor.style.display = 'none';
                }
            }
        });
    }

    hideElements();
    var observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            if (mutation.type === 'childList') {
                hideElements();
            }
        });
    });
    var config = { childList: true, subtree: true };
    observer.observe(document.body, config);
})();