Last active
July 19, 2022 03:20
-
-
Save CricketofLocusts/6109689af6c78b5e2ee23258970eaffa to your computer and use it in GitHub Desktop.
A Tampermonkey script to remove Sponsored posts from your newsfeed on Facebook.
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
// ==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