Show Mutual Friends on Tumblr

By cxx Last update May 9, 2009 — Installed 3,860 times. Daily Installs: 9, 7, 12, 6, 7, 6, 9, 3, 16, 8, 6, 26, 6, 12, 9, 9, 9, 10, 10, 6, 13, 13, 6, 12, 11, 13, 7, 8, 3, 2, 2, 3

There are 2 previous versions of this script.

// ==UserScript==
// @name           Show Mutual Friends on Tumblr
// @namespace      http://cxx.tumblr.com/
// @include        http://www.tumblr.com/following
// @include        http://www.tumblr.com/followers
// @include        http://www.tumblr.com/tumblelog/*/followers
// @include        http://www.tumblr.com/activity
// @require        http://gist.github.com/3242.txt
// @version        0.3.0.20090509
// ==/UserScript==

function parseUsers(context){
	return $X(followingXPath, context).map(function(i){
		var name = $X(nameXPath, i)[0].textContent;
		return { name: name, node: i };
	}).sort(function(a, b){
		if (a.name < b.name) return -1;
		if (a.name > b.name) return 1;
		return 0;
	});
}

function storeUsers(users, name){
	GM_setValue(loginUser + name, users.map(function(i){ return i.name; }).join());
	GM_setValue(loginUser + name + 'Count', users.length);
}

function showMutualFriends(self, other) {
	var users = parseUsers(document);
	var beCompared = GM_getValue(loginUser + other, '').split(',');
	users.forEach(function(i){
		while (i.name > beCompared[0])
			beCompared.shift();
		if (i.name == beCompared[0])
			i.node.style.backgroundColor = '#ccffcc';
	});
  if (self)
    storeUsers(users, self);
}

var t = $X('id("search_box")//input[@name="t"]')[0];
if (!t) return;
var loginUser = t.value + '_';
var followingXPath = 'id("following")/li';
var nameXPath = './/a[@class="username"]';

if (location.pathname == '/following')
	showMutualFriends('following', 'followers');
else if (location.pathname.indexOf('/followers') != -1)
	showMutualFriends('followers', 'following');
else if (location.pathname == '/activity') {
  followingXPath = '//div[@class="follower"]';
  nameXPath = './/div[@class="name"]/a';
  showMutualFriends(null, 'following');
}