Created
October 27, 2021 07:48
-
-
Save stefanoschrs/ebde3afe10e9efc1cedd06cb20f38668 to your computer and use it in GitHub Desktop.
Remove LinkedIn Ads
This file contains hidden or 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
function watchAndRemoveAds () { | |
const MutationObserver = window.MutationObserver || window.WebKitMutationObserver | |
const mo = new MutationObserver(debounce(onMutation, 500)) | |
mo.observe(document.querySelector('main#main'), { childList: true, subtree: true }) | |
function debounce (fun, timeout) { | |
let timer | |
return (...args) => { | |
clearTimeout(timer) | |
timer = setTimeout(() => fun.apply(this, args), timeout) | |
} | |
} | |
function onMutation () { | |
const promotedPosts = [...document.querySelectorAll('.feed-shared-actor__description:last-of-type')] | |
promotedPosts | |
.map((e) => e.closest('[data-id^="urn:li:activity"]')) | |
.forEach((e) => e.parentNode.removeChild(e)) | |
} | |
} | |
watchAndRemoveAds() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment