Skip to content

Instantly share code, notes, and snippets.

@nathanhammond
Created June 12, 2017 17:36
Show Gist options
  • Save nathanhammond/255f14cafc2267a454e8df434aba0f17 to your computer and use it in GitHub Desktop.
Save nathanhammond/255f14cafc2267a454e8df434aba0f17 to your computer and use it in GitHub Desktop.
Hide Post, See Less
/**
* You can navigate the Facebook feed interface using `j` and `k`.
* This script allows you to use the `x` key once focused on a story
* to hide a post and see less from its author to train Facebook's model
* as to whether you'll be interested in a particular piece of content.
* Install it as either a UserScript or bookmarklet.
*
* License: MIT
*/
function seeLess() {
var feedItem = document.activeElement;
var dropdownButton = feedItem.querySelector('*[data-testid="post_chevron_button"]');
dropdownButton.addEventListener('click', function() {
setTimeout(function() {
var popovers = document.querySelectorAll('.uiContextualLayerPositioner');
var popover = popovers[popovers.length-1];
var hidePostObserver = new MutationObserver(function(mutations) {
popover.querySelector('a[data-feed-option-name="NFXHideUnitAction"]').click();
hidePostObserver.disconnect();
});
hidePostObserver.observe(popover, { childList: true, subtree: true });
}, 100);
});
var seeLessObserver = new MutationObserver(function(mutations) {
var seeLessButton = feedItem.querySelector('[ajaxify^="/ajax/feed/filter_action/dialog_direct_action"]');
if (seeLessButton) {
seeLessButton.click();
}
var closeButton = feedItem.querySelector('button[title="Close"]');
if (closeButton) {
closeButton.click();
seeLessObserver.disconnect();
}
});
seeLessObserver.observe(feedItem, { childList: true, subtree: true });
dropdownButton.click();
}
document.body.addEventListener('keydown', function(event) {
if (event.which === 88) {
seeLess();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment