Skip to content

Instantly share code, notes, and snippets.

Last active July 4, 2022 12:19
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save miglen/4f1bccf15b63944675d34149dff0bc3d to your computer and use it in GitHub Desktop.
Save miglen/4f1bccf15b63944675d34149dff0bc3d to your computer and use it in GitHub Desktop.
News Feed Eradicator for LinkedIn
// ==UserScript==
// @name News Feed Eradicator for LinkedIn
// @namespace
// @version 0.5
// @description News Feed Eradicator for LinkedIn
// @author Miglen Evlogiev (
// @match*
// @grant none
// @downloadURL
// @updateURL
// ==/UserScript==
Similiar to the News Feed Eradicator for LinkedIn it's just not
a separate extention but a Grease Monkey Script.
Installation instructions:
1. Install the latest version of Tamper Monkey:
2. Click on Raw on the current file, your browser should
detect the script and allow you to install it,
otherwise copy the download url above and paste in your browser.
(function() {
'use strict';
// Set the main div containing the news feeds
var core_rail = document.getElementById('main');
function addCss(css) {
var head = document.head || document.getElementsByTagName('head')[0],
style = document.createElement('style');
style.type = 'text/css';
if (style.styleSheet) {
// This is required for IE8 and below.
style.styleSheet.cssText = css;
} else {
// Hide a css selector element
function hideElement(css_selector) {
addCss(`${css_selector} {display:none;visibility:hidden;}`);
function applicationContentMutation(mutation) {
if (!window.location.pathname.startsWith("/feed")) {
return true;
// Placeholder text, change it to whatever you want
var div = `
<div style="padding:30px;">
<h3>Don't "work harder." Instead:</h3>
<li>Cut away distractions. Use social media intentionally.</li>
<li>Stop doing fake work and being busy, focus on the results.</li>
<li>Ask for help & engage your mentors.</li>
<li>Solicit criticism.</li>
<li>Automate what can be automated in tools and processes.</li>
<li>Exercise & Get more sleep. Take care of your self!</li>
<h4>Whatever you do, don't "work harder." It's pretty much never the answer. Work smarter!<h4>
// Replace the news feeds with the placeholder text
core_rail.lastElementChild.innerHTML = div;
// Various css selectors of elements to be hidden
var css_selectors = [
'div[data-id^="urn:li:activity:"]', // feed activity
'#feed-nav-item .nav-item__badge--doughnut', // feed notifications
'div.feed-shared-update-v2', // Ads in the feed
'.ad-banner-container', // Ads container
'.feed-shared-navigation-module', // Discover More container
'.feed-shared-navigation-module--v2', // Discover More container
'.feed-follows-module', // Add to your feed container
'.sort-dropdown__dropdown-trigger', // Sort dropdown trigger
'.feed-shared-news-module' //Shared news module
// Hide all elements
hideElement(css_selectors.join(', '))
// Set the placeholder text initially
// Hook into the news feed mutations
const applicationContentObserver = new MutationObserver(function(mutations) {
applicationContentObserver.observe(core_rail, {
childList: true
Copy link

jsabra1 commented Dec 8, 2018

Awesome stuff! really good work. thanks dude!

Copy link

miglen commented Dec 13, 2018

Glad that you like it @Jawads 👍

Copy link

Thank you so much!

Copy link

moebg commented Jan 13, 2019

This is great! Thank You so much! If you can get the time, would you be able to update the script to get rid of these elements as well? At least the hashtags, and some stuff that's irrelevant. Thanks! :)

Copy link

miglen commented Jan 17, 2019

Thanks for your suggestions @moebg I have updated it with them. Also, I was using it on top of uBlock Origin, which was hiding most of the ads, so I've added that as well. Let me know if you see any bugs so I can fix them accordingly.

Copy link

miglen commented Jan 28, 2019

Revision 0.4 - Updated sort dropdown trigger and added & added Matt T. suggestion for Suggested news stories

Copy link

Thank you - this works great!
I am free of Linkedin spam.

Copy link

Thanks again for this excellent script!

Copy link

miglen commented Oct 28, 2019

Thanks again for this excellent script!

Glad it makes people happy and hopefully productive.

Copy link

Helped me a lot, thanks!

Copy link

MadManMoon commented Jun 29, 2022

Hey, I can see that the CSS stuff works, but I don't think that the mutationObserver is actually doing anything.

I've slipped the following under the if !window.location:
console.log("no-one here but us chickenz!");

It doesn't fire at all which suggests to me that it's not actually doing anything with elements that come in ... just hiding everything in the CSS (which is great, by the way).

I'm not trying to be on your case, by the way ... I've been struggling to find a way to make mutationObserver do anything on the LinkedIn feed, and I've been losing ... but I'm a real newb.


To be clear, I was trying to use your script to enable me to have a feed, but it's just actual activity from contacts that matters (comments, or posts, basically) ... and I couldn't get the mutation observer to fire.

So now that I have this, I'll hopefully find a way to make it much more efficient. Might publish and then ask for help on stack.

Anyway ... this feels really inefficient, but it works ... I'd love to find a way that's a bit more selective.

(function () { 
$("div.scaffold-finite-scroll__content").filter("div a[href^=''][data-control-name='actor_container']").remove();

(function () { 
var targetNodes = $( document );
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
var myObserver = new MutationObserver(mutationHandler);
var obsConfig = {
  childList: true,
  characterData: true,
  attributes: true,
  subtree: true

//--- Add a target node to the observer. Can only add one node at a time.
targetNodes.each(function() {
  myObserver.observe(this, obsConfig);

function mutationHandler(mutationRecords) {"mutationHandler:");

  mutationRecords.forEach(function(mutation) {
    //console.log("this was a "+mutation.type);
    //console.log("yallseedis: "+mutation);

    if (typeof mutation.addedNodes == "object") {

I couldn't get it to run on #main or the actual container that updates (2 divs in) which is div.scaffold-finite-scroll__content ... plus I also have to ensure that I include the entire minified jquery, because apparently the include doesn't work, and I also have to inject it ... but it works ... no more companies in my feed! (so far)

@miglen do you think there's anything that can be done to trim this? Does it need all the config options that it has? I'm thinking of replacing the add-on which I'm using with this, as it's quite effective on the company part. I could perhaps easily include checks on containing "commented on" or "loves this", etc.

Copy link

This script inspired me to write a chrome extension that allows you to show or hide your newsfeed, among other things. It's free and open source. Feel free to pull any of the logic into this script, or visa-versa.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment