Skip to content

Instantly share code, notes, and snippets.

@stefanoschrs
Created October 27, 2021 07:48
Show Gist options
  • Save stefanoschrs/ebde3afe10e9efc1cedd06cb20f38668 to your computer and use it in GitHub Desktop.
Save stefanoschrs/ebde3afe10e9efc1cedd06cb20f38668 to your computer and use it in GitHub Desktop.
Remove LinkedIn Ads
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