Greasy Fork

Greasy Fork is available in English.

Suppress Suggested & Promoted Posts on LinkedIn

Remove LinkedIn posts labeled as "Suggested" and dynamically observe for new ones

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Suppress Suggested & Promoted Posts on LinkedIn
// @namespace    https://example.com/
// @version      1.5
// @description  Remove LinkedIn posts labeled as "Suggested" and dynamically observe for new ones
// @author       JH
// @match        https://www.linkedin.com/*
// @include      http://*linkedin.com/*
// @include      https://*linkedin.com/*
// @grant        none
// @license     MIT
// ==/UserScript==

(function() {
    'use strict';

  const divTemplate = [
        'div[data-id^="urn:li:activity:"]', // Classic
        'article[data-activity-urn^="urn:li:activity:"]' // iOS Safari
  ];
    
  // Function to hide divs with data-id starting with 'urn:li:activity:' containing spans with 'Promoted' or 'Suggested'
  function hidePromotedPosts() {

      
      divTemplate.forEach(function(template) {
          const divs = document.querySelectorAll(template); 
      
          divs.forEach(div => {
              const spans = div.querySelectorAll('span, p'); // Look for spans within these divs
              spans.forEach(span => {
                  if (span.textContent.trim() === 'Promoted' || span.textContent.trim() === 'Suggested') {
                      div.style.display = 'none'; // Hide the entire div
                  }
              });
          });
      });
  }
  
  // Call the function to hide the promoted and suggested posts
  hidePromotedPosts();
  
  // Run the function when new posts are loaded (using a MutationObserver)
  const observer = new MutationObserver(hidePromotedPosts);
  observer.observe(document.body, { childList: true, subtree: true });

})();