Skip to content

Instantly share code, notes, and snippets.

@miglen
Last active July 4, 2022 12:19
Show Gist options
  • 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 http://miglen.com/
// @version 0.5
// @description News Feed Eradicator for LinkedIn
// @author Miglen Evlogiev (hi@miglen.com)
// @match https://www.linkedin.com/*
// @grant none
// @downloadURL https://gist.github.com/miglen/4f1bccf15b63944675d34149dff0bc3d/raw/news-feeds-eradicator-linkedin.user.js#.user.js
// @updateURL https://gist.github.com/miglen/4f1bccf15b63944675d34149dff0bc3d/raw/news-feeds-eradicator-linkedin.user.js#.user.js
// ==/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: https://tampermonkey.net
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 {
style.appendChild(document.createTextNode(css));
}
head.appendChild(style);
}
// 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>
<br>
<ul>
<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>
</ul>
<br>
<h4>Whatever you do, don't "work harder." It's pretty much never the answer. Work smarter!<h4>
</div>`;
// 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
applicationContentMutation();
// Hook into the news feed mutations
const applicationContentObserver = new MutationObserver(function(mutations) {
mutations.forEach(applicationContentMutation);
});
applicationContentObserver.observe(core_rail, {
childList: true
});
})();
@mthurmond
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.

https://github.com/mthurmond/distraction-free-for-linkedin

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