Skip to content

Instantly share code, notes, and snippets.

@pedroreys
Created July 12, 2012 01:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pedroreys/3095097 to your computer and use it in GitHub Desktop.
Save pedroreys/3095097 to your computer and use it in GitHub Desktop.
function stringContainsAnyOfElements(string, elements){
string = string.toLowerCase();
for(var i = 0; i < elements.length; i++) {
if(string.indexOf(elements[i]) != -1) {
return true;
}
}
return false;
}
var namesBlackListedWords = ["não", "nao", "piada", "riso", "rindo", "risada", "risadas", "fail", " em ", "apenas", "só", "frase", " e ", "mundo", " do ", " rir", " rir", " para ", " da ", "suado", " o ", " u ", " na ", " nas ", " nos ", "face", "humor", "meme", "intender", "fodace"];
var postBlackListedWords = ["9gag", "copie e cole", "compartilhe", "no seu mural", "BBB", "Big Brother", "meme", "risos"];
var postWhiteListedWords = ["facetrash", "face trash"];
var elementsToSearchForNames = [".uiStreamPassive", ".translationEligibleUserAttachmentMessage"];
function runFaceTrash() {
alert("foo");
if(document.URL.indexOf("facebook.com") == -1) {
alert("Desculpe, o FaceTrash só funciona no Facebook.com.");
} else {
var postsToRemove = new Array();
$(".uiUnifiedStory").each(function(){
var post = $(this);
if(post && !stringContainsAnyOfElements(post.html(), postWhiteListedWords)) {
if(stringContainsAnyOfElements(post.html(), postBlackListedWords)) {
postsToRemove.push(post);
post.css("background-color", "red");
} else {
for(var i = 0; i < elementsToSearchForNames.length; i++) {
$(this).find(elementsToSearchForNames[i]).children().each(function(){
var text = $(this).text();
if(stringContainsAnyOfElements(text, namesBlackListedWords) && !stringContainsAnyOfElements(text, ["other friends"])) {
postsToRemove.push(post);
post.css("background-color", "red");
}
});
}
}
}
});
$('#globalContainer').prepend('<div id="scrollingDiv" style="font-size: 14px; position:absolute;z-index:100;background-color:#EFEFEF;" align="center"><b>FaceTrash by <a href="http://www.pedrofranceschi.com/" target="_blank">Pedro Franceschi</a><br/>(<a href="http://twitter.com/pedroh96" target="_blank">@pedroh96</a>)</b><br/>Posts marcados: ' + postsToRemove.length + ' (em vermelho)<br/><a id="faceTrashEraseLink">Apagar</a> | <a id="faceTrashCancelLink">Cancelar</a</div>');
var $sidebar = $("#scrollingDiv"),
$window = $(window),
offset = $sidebar.offset(),
topPadding = $window.height()/2;
$window.scroll(function() {
if ($window.scrollTop() > offset.top) {
$sidebar.stop().animate({
marginTop: $window.scrollTop() - offset.top + topPadding
});
} else {
$sidebar.stop().animate({
marginTop: 0
});
}
});
$('#faceTrashEraseLink').live("click", function(){
for(var i = 0; i < postsToRemove.length; i++) {
postsToRemove[i].remove();
}
$("#scrollingDiv").remove();
});
$('#faceTrashCancelLink').live("click", function(){
for(var i = 0; i < postsToRemove.length; i++) {
postsToRemove[i].css("background-color", "white");
}
$("#scrollingDiv").remove();
});
}
};
if (typeof jQuery == 'undefined') {
var jQ = document.createElement('script');
jQ.type = 'text/javascript';
jQ.onload=runFaceTrash;
jQ.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';
document.body.appendChild(jQ);
} else {
runFaceTrash();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment