Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Remove names from Facebook posts and comments allow them to be screenshotted and posted to internet forums without exposing user identities.
(function() {
var hash = {};
var anonymise = function() {
// Handle links to user profiles, e.g. those shown when someone likes a post
Array.prototype.forEach.call(document.querySelectorAll('[data-hovercard*="user.php"], [data-hovercard*="hovercard.php"]'), function(hovercardLink) {
if (!hovercardLink.dataset.hovercard) return;
var id = /id=(\d+)/.exec(hovercardLink.dataset.hovercard)[1];
var hue = hash[id] = hash[id] || (Math.random() * 360);
hovercardLink.style.background = 'hsl(' + hue + ',55%,60%)';
hovercardLink.style.color = 'hsl(' + hue + ',55%,60%)';
var img;
if(img = hovercardLink.querySelector('img')) {
img.style.visibility = 'hidden';
}
});
// Handle comment containers by hiding the 'Write a comment' entry and handle each comment avatar/name
Array.prototype.forEach.call(document.querySelectorAll('.UFIContainer'), function(container) {
var addComment = container.querySelector('.UFIAddComment');
var lastComment = container.querySelector('.UFILastComment');
if (addComment) {
addComment.style.display = 'none';
lastComment && lastComment.classList.add('UFILastComponent');
}
Array.prototype.forEach.call(container.querySelectorAll('.UFIComment'), function(comment) {
var imageBlock = comment.querySelector('.UFIImageBlockImage');
var actorName = comment.querySelector('.UFICommentActorName');
if (!imageBlock.dataset.hovercard) return;
var id = /id=(\d+)/.exec(imageBlock.dataset.hovercard)[1];
var hue = hash[id] = hash[id] || (Math.random() * 360);
imageBlock.querySelector('img').style.visibility = 'hidden';
imageBlock.style.background = 'hsl(' + hue + ',55%,60%)';
actorName.style.background = 'hsl(' + hue + ',55%,60%)';
actorName.style.color = 'hsl(' + hue + ',55%,60%)';
});
});
};
var observer = new MutationObserver(anonymise);
observer.observe(document.body, { childList: true });
anonymise();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.