Hide & seek with Sponsored content in our Feeds

A single Sponsored text against an ad on Facebook, rendered as obfuscated collection of SPANs containing random characters absolutely positioned out of the view.

<span aria-labelledby="jsc_c_12" aria-label="label" class="gpro0wi8 j1lvzwm4 stjgntxs ni8dbmo4 q9uorilb">

<span id="jsc_c_13">Sponsored</span>

sp = document.evaluate("//span[contains(.,'Sponsored')]", document)


nodes = [...document.querySelectorAll("div[data-testid='Keycommand_wrapper_feed_story'")]

ads = nodes.filter((n) => n.querySelectorAll("[aria-labelledby='jsc_c_12']").length > 0)

Having said that, it may sound simple, however the feed is rendered only within the viewport. The posts are rendered and hidden continuously while we scroll, thereby anything that was previously hidden will come back. To make this effective, we could attach this snippet to the window scroll event to continuously hide ads as they show up within the viewport.

[…document.querySelectorAll(“div[class~=Post]”)].filter((n) => document.evaluate(“.//span[contains(.,’promoted’)]”, n).iterateNext() !== null).forEach((d) => d.remove());

[…document.querySelectorAll(“div[data-id^=’urn:li:activity:’]”)].filter((n) => document.evaluate(“.//span[contains(.,’Promoted’)]”, n).iterateNext() !== null).forEach((d) => d.remove());



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store