Skip to content

Instantly share code, notes, and snippets.

@rjp
Created July 8, 2011 15:04
Show Gist options
  • Save rjp/1072035 to your computer and use it in GitHub Desktop.
Save rjp/1072035 to your computer and use it in GitHub Desktop.
Replace twitter avatars with robohash robots
// ==UserScript==
// @name RoboHash Your Twitters
// @namespace rjp
// @description Replace twitter avatars with RoboHash avatars
// @include http://twitter.com/
// ==/UserScript==
// linkifyContainer idea gratefully and wholly stolen from
// http://arantius.com/misc/greasemonkey/linkify-plus.user.js#
// with minor reformatting by me to make a nicer gist
linkifyContainer(document.body);
document.body.addEventListener('DOMNodeInserted', function(event) {
linkifyContainer(event.target);
}, false);
function linkifyContainer(container) {
if (container.className.match(/\brobohashed\b/)) return;
var xpathResult = document.evaluate(
".//div[@class='tweet-image']", container, null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
var i = 0;
function continuation() {
var node = null, counter = 0;
while (node = xpathResult.snapshotItem(i++)) {
var parent = node.parentNode;
linkifyTextNode(node, parent);
if (++counter > 50) { return setTimeout(continuation, 0); }
}
}
setTimeout(continuation, 0);
}
function linkifyTextNode(node, parent) {
var f = parent.getAttribute('data-screen-name');
node.innerHTML = "<img src='http://robohash.org/"+f+".png?size=48x48'>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment