Hide LinkedIn Promoted Posts

Hide promoted posts on LinkedIn feed

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         Hide LinkedIn Promoted Posts
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Hide promoted posts on LinkedIn feed
// @author       chtshop
// @match        https://www.linkedin.com/feed/*
// @grant        none
// @run-at       document-end
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function hidePromotedPosts() {
        document.querySelectorAll('span[aria-hidden="true"]').forEach(span => {
            if (span.innerText.trim() === 'Promoted') {

                let parent = span;
                for (let i = 0; i < 12; i++) {
                    if (parent) parent = parent.parentElement;
                }
                if (parent) parent.remove();
            }
        });
    }

    // Run initially and then observe for new elements
    hidePromotedPosts();

    const observer = new MutationObserver(() => hidePromotedPosts());
    observer.observe(document.body, { childList: true, subtree: true });
})();