Skip to content

Instantly share code, notes, and snippets.

@CricketofLocusts
Last active July 19, 2022 03:20
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CricketofLocusts/6109689af6c78b5e2ee23258970eaffa to your computer and use it in GitHub Desktop.
Save CricketofLocusts/6109689af6c78b5e2ee23258970eaffa to your computer and use it in GitHub Desktop.
A Tampermonkey script to remove Sponsored posts from your newsfeed on Facebook.
// ==UserScript==
// @name Remove FB Sponsored Posts
// @namespace https://gist.github.com/CricketofLocusts/6109689af6c78b5e2ee23258970eaffa.js
// @description A Tampermonkey script to remove Sponsored posts from your newsfeed on Facebook.
// @version 1.21
// @author Cricket
// @include https://www.facebook.com/?ref=tn_tnmn
// @include https://www.facebook.com
// @require http://code.jquery.com/jquery-latest.min.js
// ==/UserScript==
function CheckForADPosts()
{
RemovePost( "span:contains('Suggested Post')" );
RemovePost( "a:contains('Sponsored')" );
setTimeout(CheckForADPosts, 100);
}
function RemovePost(subquery)
{
var query = "div[id*='substream_']";
var len = $(query).find(subquery).length;
for (var i=0; i<len; i++)
{
var elem = $(query).find(subquery).get(i);
if (!elem)
continue;
while(elem)
{
if (typeof $(elem).attr('id') !== typeof undefined && !$(elem).attr('id').includes('substream_'))
break;
elem = $(elem).parent().get(0);
}
if (elem)
$(elem).remove();
}
}
setTimeout(CheckForADPosts, 500);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment