Last active
August 29, 2015 14:05
-
-
Save inversion/2545842bc080d24e4fe1 to your computer and use it in GitHub Desktop.
Hide Facebook News feed entries which are random posts from friends' liked pages. They are matched by looking for the 'Like Page' button within a news feed entry. Instructions for adding user scripts to Chrome here: http://stackoverflow.com/questions/5258989/manually-adding-a-userscript-to-google-chrome or for Firefox use Greasemonkey. It's prob…
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 Hide Facebook 'Like' News | |
// @namespace uk.me.amoss | |
// @include /https?://www.facebook.com/.*/ | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
// Configurable | |
var indicateInsteadOfHiding = false; | |
var newsItemAddedObserver = null; | |
window.onload = function() { | |
if( newsItemAddedObserver !== null ) { | |
return; | |
} | |
var newsDivSelection = document.evaluate('//div[starts-with(@id, "topnews_main_stream")]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); | |
if( newsDivSelection.snapshotLength === 0 ) { | |
console.log('No news stream div found.'); | |
} else if( newsDivSelection.snapshotLength > 1 ) { | |
console.log('Multiple news stream divs found.'); | |
} else { | |
newsItemAddedObserver = new MutationObserver(function(mutations) { | |
mutations.forEach(function(mutation) { | |
for( var i = 0; i < mutation.addedNodes.length; i++ ) { | |
var addedNode = mutation.addedNodes[i]; | |
if( addedNode.id.indexOf('jsonp') > -1 ) { | |
hideMatchingDivs(addedNode); | |
} | |
} | |
}); | |
}); | |
newsItemAddedObserver.observe(newsDivSelection.snapshotItem(0), { subtree: true, childList: true }); | |
hideMatchingDivs(document); | |
} | |
function hideMatchingDivs(element) { | |
var spamDivs = document.evaluate('//div[contains(@id, "jsonp") and .//button[contains(text(), "Like Page")]]', element, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); | |
console.log('Detected ' + spamDivs.snapshotLength + ' matching divs.'); | |
for( var i = 0; i < spamDivs.snapshotLength; i++ ) { | |
if( indicateInsteadOfHiding ) { | |
spamDivs.snapshotItem(i).style.border = '3px solid red'; | |
} else { | |
spamDivs.snapshotItem(i).style.display = 'none'; | |
} | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment