Last active
August 29, 2015 14:06
-
-
Save adammw/f7663e73db6e0ce4dc55 to your computer and use it in GitHub Desktop.
Remove names from Facebook posts and comments allow them to be screenshotted and posted to internet forums without exposing user identities.
This file contains hidden or 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
(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