Forked from GFoley83/LinkedIn - Remove crap posts.js
Last active
April 16, 2020 04:12
Star
You must be signed in to star a gist
Unlike facebook, LinkedIn creates entire posts just for likes and comments which fills up the feed with crap. This snippet removes those posts from the feed. Best used with an Chrome extension like "Custom JavaScript for Websites".
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name LinkedIn - Remove crap posts | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Unlike facebook, LinkedIn creates entire posts just for likes and comments which fills up the feed with crap. This snippet removes those posts from the feed. Best used with an Chrome extension like "Custom JavaScript for Websites". | |
// @author GFoley83 | |
// @author amg1127 | |
// @match https://linkedin.com/feed/ | |
// @match https://*.linkedin.com/feed/ | |
// @run-at document-idle | |
// @grant unsafeWindow | |
// @require https://code.jquery.com/jquery-3.4.1.min.js#sha1=88523924351bac0b5d560fe0c5781e2556e7693d,md5=220afd743d9e9643852e31a135a9f3ae | |
// ==/UserScript== | |
(function(page, $) { | |
'use strict'; | |
$.expr[':'].textEquals = $.expr.createPseudo(arg => { | |
return ((elem) => { | |
return $(elem).text() == arg; | |
}); | |
}); | |
let timer = null; | |
const removeCrap = () => { | |
timer = null; | |
const $crapSelector = $(` | |
span.ember-view > span:textEquals(" likes this"), | |
span.ember-view > span:textEquals(" loves this"), | |
span.ember-view > span:textEquals(" celebrates this"), | |
span.ember-view > span:textEquals(" finds this insightful"), | |
span.ember-view > span:textEquals(" is curious about this"), | |
span.ember-view > span:textEquals(" commented on this"), | |
span.ember-view > span:textEquals("Short course you may like"), | |
div.feed-shared-text-view span:textEquals("Promoted") | |
`, page.document); | |
const crapCount = $crapSelector.length; | |
if(crapCount === 0){ | |
return; | |
} | |
$crapSelector | |
.closest('.relative.ember-view') | |
.filter(`:not(:has(span.ember-view > span:textEquals(" • 1st")))`) | |
// .remove(); // Instantly remove | |
// .css('opacity','0.3'); // Fade out instead of remove | |
.fadeTo (1000, 0.3); // Animated fade out | |
console.log(`Removed ${crapCount} LinkedIn BS posts.`); | |
}; | |
const removeCrapTrigger = (mutationsList, observer) => { | |
for (let mutation of mutationsList) { | |
if (mutation.type === 'childList' && mutation.addedNodes.length > 0) { | |
if (timer === null) { | |
console.log(`removeCrap triggered.`); | |
timer = window.setTimeout (removeCrap, 1000); | |
return; | |
} | |
} | |
} | |
} | |
const targetNode = document.body; | |
const config = { childList: true, subtree: true }; | |
const observer = new MutationObserver (removeCrapTrigger); | |
observer.observe (targetNode, config); | |
}) (unsafeWindow, jQuery.noConflict(true)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment