Skip to content

Instantly share code, notes, and snippets.

@fortserious
Last active March 14, 2016 00:34
Show Gist options
  • Save fortserious/a24f85eda7c73e3860d6 to your computer and use it in GitHub Desktop.
Save fortserious/a24f85eda7c73e3860d6 to your computer and use it in GitHub Desktop.
facebook keyword blocker
// ==UserScript==
// @name fb keyword blocker
// @namespace www.rossdoran.com
// @version 0.1
// @description ignorance is literally necessary in order to make the internet bearable
// @match https://www.facebook.com/
// @match https://www.facebook.com/?*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @copyright ross doran 2016
// ==/UserScript==
// BLOCK ALL FACEBOOK POSTS WITH THESE WORDS:
// Example:
var blocked = ["Bernie Sanders","Donald Trump","Hillary Clinton","Ted Cruz","Marco Rubio"];
var hidden = 0;
var hiddenDiv = document.createElement("div");
hiddenDiv.setAttribute("id","rosshidden");
hiddenDiv.setAttribute("class","rosshide");
$("#pagelet_bluebar").append(hiddenDiv);
rowHeader = document.createElement("div");
linkHTML = "<table style='font-weight:bold;color: #3b5998;'><tr><td>Name</td><td><a href = '#' target='_blank'>URL</a></td><td>Keywords matched</td></tr></table>";
rowHeader.innerHTML = linkHTML;
$("#rosshidden").append(rowHeader)
$("#rosshidden").css({"background":"rgba(255,255,255,.98)","padding-top":"5px","background-color":"#fff","border":"1px solid rgba(100, 100, 100, .4)","box-shadow":"0 3px 8px rgba(0, 0, 0, .25)",
"overflow-y":"auto","position":"fixed","top":"38px","left":"0px","width":"372px","height":"200px","z-index":5})
$("<style type='text/css'>#rosshidden td { width: 130px; } .rosshide{ display:none !important;} .rossbtn { background-color: #4e69a2; border-color: #435a8b #3c5488 #334c83; border: 1px solid; border-radius: 2px; color: white; font-family: helvetica, arial, sans-serif; font-weight: bold;} </style>").appendTo("head");
var hiddenIcon = document.createElement("i");
hiddenIcon.setAttribute("id","rosshiddenimg");
hiddenIcon.innerHTML = 0;
$("#pagelet_bluebar").append(hiddenIcon);
$("#rosshiddenimg").css({"text-indent":"40px","cursor":"pointer","font-style":"normal","font-family":"arial","font-weight":"bold","font-size":"21pt","color":"whitesmoke","position":"fixed","left":"0px","top":"5px","z-index":1000,"opacity":.5,"background-position":"-41px -100px","background-image":"url(/rsrc.php/v2/y2/r/kyu0iQo2VOb.png)","background-size":"auto","background-repeat":"no-repeat","display":"inline-block","height":"36px","width":"72px"})
$("#rosshiddenimg").css({"-webkit-filter":"brightness(0) invert(1)","filter":"brightness(0) invert(1)"})
$('#rosshiddenimg').click(function(){
$("#rosshidden").toggleClass('rosshide')
});
blockIndex = "";
for (var i = 0; i < blocked.length; i++)
{
blockIndex += '.userContent p:contains("' + blocked[i] + '")' + ',.mtm:contains("' + blocked[i] + '")';
if (i < blocked.length - 1)
blockIndex += ",";
}
jQuery.expr[':'].Contains = function(a, i, m) {
return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase()) >= 0;
};
function destroyFCG(me)
{
myParents = me.parents(".userContentWrapper")
if (!(myParents.hasClass("rosshid")))
{
myParents.addClass("rosshid")
var rowItem = document.createElement("div");
var prefix = "https://facebook.com";
var link = myParents.find(".fcg a._5pcq").attr("href")
person = myParents.find(".fwb").children().first().text()
// console.log(myParents);
myParents.remove()
var txt = me.text();
var keyword = "";
for (var i=0; i < blocked.length; i++)
{
if (txt.search(blocked[i]) > -1)
keyword += blocked[i] + ",";
}
if (keyword.charAt(keyword.length - 1) == ",")
keyword = keyword.substring(0,keyword.length - 1);
linkHTML = "<table><tr><td style='color: #3b5998;'>" + person + "</td><td><a href = '" + prefix + link + "' target='_blank'>Link to post</a></td><td>" + keyword + "</td></tr></table>";
rowItem.innerHTML = linkHTML;
$("#rosshidden").append(rowItem)
hidden++;
$("#rosshiddenimg").text(hidden)
}
}
waitForKeyElements(".userContent", function() { // wait for a span with content to appear
$(blockIndex).each(function()
{
// console.log($(this));
// alert($(this).text());
destroyFCG($(this));
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment