Chrome Extension to Block News Feed Posts on Facebook

Today, North Carolina is voting on a Constitutional Ban of same-sex marriage and civil unions. While I am opposed to the amendment, my Facebook news feed has become quite cluttered lately full of other people’s opinions on the matter. I have created a chrome extension to make it easy to block these News Feed stories and easily unfriend the pesky poster…

changes to:

The Extension

Here is the Chrome extension that will block every post with the word “amendment” in it and allow you to easily unfriend the poster:

amendment_none.crx

The Code

The Chrome Extension consists of one file that listens on all facebook.com pages.  It monitors the DOM for a news story containing the word “amendment”.  Once it finds a news story, it uses regular expressions to replace the content of the story with link to unfriend the poster.

function hide_amendments()
{
	if ($(".storyContent").length==0)
	{
		setTimeout("hide_amendments()",50);
	}
	else
	{
		$('.storyContent').filter(function()
        {
            if($(this).html().match(/amendment/i))
            {
                var link=$(this).find(".uiStreamHeadline").html();
                var name=link.replace(/.+\?id=([0-9]+)\"\>([a-zA-Z]+).+/,'$2');
                link=link.replace(/.+\?id=([0-9]+)\"\>([a-zA-Z]+).+/,'<a rel="async" ajaxify="/ajax/profile/removefriendconfirm.php?uid=$1" href="#">unfriend $2</a>');
                $(this).find(".messageBody").html(name+" is cluttering your news feed with posts about politics.  "+link);
                $(this).find(".mainWrapper").children(":not(h6)").hide();
            }
        });
        setTimeout("hide_amendments()",2000);
	}
}

today = new Date();
if ( (today.getFullYear()==2012) && ((today.getMonth()<=4) || ((today.getMonth()<=5) && (today.getDate()<=7))) )
{
	hide_amendments();
}