LinkedIn unsponsored

Block sponsored posts in the LinkedIn feed

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         LinkedIn unsponsored
// @namespace    https://jacobbundgaard.dk
// @version      1.3
// @description  Block sponsored posts in the LinkedIn feed
// @match        https://www.linkedin.com/feed/*
// @grant        none
// @inject-into  content
// ==/UserScript==

(function() {
    'use strict';

    // Selectors
    const storySelector = '.feed-shared-update-v2';
    const descriptionSelector = '.feed-shared-actor__description, .feed-shared-actor__sub-description';

    // Search strings
    const searchStrings = {
        'da': ['Promoveret'],
        'en': ['Promoted'],
        'es': ['Promocionado'],
        'fr': ['Post sponsorisé']
    };
  
    const language = searchStrings.hasOwnProperty(document.documentElement.lang) ? document.documentElement.lang : 'en';

    function blockSponsoredPosts() {
        const stories = document.querySelectorAll(storySelector);
        for (const story of stories) {
            if (story.style.display == 'none') {
              continue;
            }

            const descriptions = story.querySelectorAll(descriptionSelector);
            for (const description of descriptions) {

                const descriptionContent = description.innerText.trim();
                if (searchStrings[language].find(searchString => searchString == descriptionContent)) {

                    console.debug('Blocked sponsored story', story);
                    story.style.display = 'none';
                }
            }
        }
    }

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