Last active
May 22, 2017 11:46
-
-
Save campbellwmorgan/81a38106f3e5e65257e1210d4cdde432 to your computer and use it in GitHub Desktop.
Filter UK/US Politics from facebook
This file contains 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 Facebook Politics Filter | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Remove As Many politics posts as possible from your facebook feed | |
// @author Campbell Morgan @camsmorgan | |
// @match https://www.facebook.com/ | |
// @grant none | |
// ==/UserScript== | |
/** | |
* To use install TamperMonkey chrome extension | |
* https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo?hl=en | |
* And paste this as a userscript | |
*/ | |
(function() { | |
'use strict'; | |
var filters = [ | |
'corbyn', | |
'theresa', | |
'labour', | |
'conservatives', | |
'momentum', | |
'tories', | |
'tory', | |
'race', | |
'lib dems', | |
'politics', | |
'elections', | |
'nhs', | |
'politic', | |
'vote', | |
'healthcare', | |
'parliament', | |
'pence', | |
'trump', | |
'clinton', | |
'senate', | |
'congress', | |
'queen', | |
'israel', | |
'palestine', | |
'iran', | |
'protest', | |
'syria', | |
'demonstration', | |
]; | |
const filter = (nodes) => { | |
if (!nodes) return console.info('No nodes'); | |
nodes.forEach((node) => { | |
if (node.dataset && node.dataset.filtered) return; | |
console.info('Filtering node'); | |
node.dataset.filtered = true; | |
var text = node.textContent.toLowerCase(); | |
var canShow = filters.reduce((show, keyword) => { | |
if (!show) return show; | |
if (text.includes(keyword)) return false; | |
return show; | |
}, true); | |
if (!canShow) node.style.display = 'none'; | |
}); | |
}; | |
var obsrv = new MutationObserver((mutations) => { | |
mutations.forEach((mutation) => { | |
if (!mutation.addedNodes) return console.info('no changes', mutation); | |
filter(document.querySelectorAll('.fbUserContent')); | |
}); | |
}); | |
obsrv.observe(document.getElementById('contentCol'), { | |
childList: true, | |
subtree: true, | |
attributes: false, | |
characterData: false, | |
}); | |
console.info('Loading FB Politics Filter'); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment