Skip to content

Instantly share code, notes, and snippets.

@iMerica
Last active October 3, 2015 17:39
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 iMerica/ce77d6ab5ccabcb973f1 to your computer and use it in GitHub Desktop.
Save iMerica/ce77d6ab5ccabcb973f1 to your computer and use it in GitHub Desktop.
Facebook Filter
// ==UserScript==
// @name Facebook filter
// @namespace iMerica
// @description Hides Facebook posts you don't want to see.
// @include http://www.facebook.com/*
// @include https://www.facebook.com/*
// ==/UserScript==
// Install:
// Step 1: Install TamperMonkey
// Step 2: In Chrome, go to chrome://extensions/
// Step 3: Click on TamperMonkey options
// Step 4: Go to new user script tab.
// Step 5: Paste this script into it and save.
// Notes:
// To add more keywords to the blacklist, simply add
// more elements to the blacklist array at the bottom of
// this script.
// ToDo:
// - Convert this into a crx file that can be used by dragging into chrome.
// - Add a GUI
// - Make contains() case insensitve.
function contains(arr, value) {
for (var i = arr.length - 1; i >= 0; i--) {
if (value.search(arr[i]) >= 0) {
return true;
}
}
return false;
}
function hidePostsByKeywords(black_list) {
var posts = document.getElementsByClassName('userContentWrapper');
for (var i = posts.length - 1; i >= 0; i--) {
if (contains(black_list, posts[i].innerText)) {
posts[i].style.display = 'none';
}
}
}
window.addEventListener("load", function() { hidePostsByKeywords(); }, false); }, false);
window.addEventListener("DOMNodeInserted", function() { hidePostsByKeywords(['Guns', 'Vaccines', 'Trump', 'Facebook Privacy', 'Global Warming']); }, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment