Add new user script in the Greasemonkey:
![]() |
Add new user script. |
![]() |
Fill-up. |
This file contains 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
// ==UserScript== | |
// @name SortBy | |
// @namespace http://autosysprogs.blogspot.com/ | |
// @description Sort by most mutual friends | |
// @include http://www.facebook.com/find-friends/* | |
// @author Mkrtich Soghomonyan | |
// ==/UserScript== | |
window.addEventListener( | |
'load', | |
function() { | |
// ---------------------------------------- | |
// ---------------------------------------- | |
// Add sort function | |
var scriptElement = document.createElement('script'); | |
scriptElement.type = 'text/javascript'; | |
scriptElement.innerHTML ='function sortByNum(a, b) { return b.num - a.num; } \ | |
function sortPeopleByMostMutualFriends() { \ | |
var allDivs, thisDiv, firstDiv, changeDiv; \ | |
allDivs = document.evaluate("//div[@class=\'friendBrowserUnit\']", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); \ | |
var people = new Array(); \ | |
for (var j = 0; j < allDivs.snapshotLength; j++) { \ | |
var mutual = allDivs.snapshotItem(j).innerHTML.replace(/([0-9]*) mutual friend.*/g, "===========$1").replace(/^.*===========/, ""); \ | |
if (!mutual.match(/^[0-9]*$/)) { mutual = 0; }\ | |
people.push({num: mutual, val: allDivs.snapshotItem(j).cloneNode(true)}); \ | |
} \ | |
people.sort(sortByNum); \ | |
var parent = new Array(); \ | |
for (var i = 0; i < allDivs.snapshotLength; i++) { \ | |
thisDiv = allDivs.snapshotItem(i); \ | |
changeDiv = document.getElementById(thisDiv.id); \ | |
if (changeDiv) { \ | |
parent.push(changeDiv.parentNode); \ | |
changeDiv.parentNode.removeChild(changeDiv); \ | |
} \ | |
} \ | |
for (var i = 0; i < allDivs.snapshotLength; i++) { \ | |
parent[i].appendChild(people[i].val);\ | |
} \ | |
}'; | |
document.getElementsByTagName("head")[0].appendChild(scriptElement); | |
// ---------------------------------------- | |
// ---------------------------------------- | |
// Add sort button above the hometown check boxes. | |
// Get the hometown table. | |
var targetDiv = document.getElementById('checkboxes_hometown'); | |
if (null == targetDiv) { | |
// Current page is different from find-friends page. | |
return; | |
} | |
// Create a div to surround the sort button. | |
var newDiv = document.createElement('div'); | |
newDiv.setAttribute('id', 'sortPeopleByMostMutualFriends'); | |
// Create the button and set its attributes. | |
var sortButton = document.createElement('input'); | |
sortButton.name = 'sortButton'; | |
sortButton.type = 'button'; | |
sortButton.value = 'Sort by mutual friends'; | |
sortButton.setAttribute("onclick", "sortPeopleByMostMutualFriends();"); | |
// Append the button to the div. | |
newDiv.appendChild(sortButton); | |
// Append before hometown table. | |
targetDiv.parentNode.insertBefore(newDiv, targetDiv); | |
}, | |
true); |
In the Facebook's Find Friends page now you can see a button near the hometown filter.
Click it and it will sort people by number of mutual friends.
That's all.
For Chrome you add:
ReplyDelete// @match http://facebook.com/*
// @match http://*.facebook.com/*
// @match https://facebook.com/*
// @match https://*.facebook.com/*
But then.. it only "sorts" by first 2 results.
That would be a great script but it doesn't work right now as facebook changed in late july the way the persons appear on the page. Could you be so kind to update it, i think it will be very very useful.
ReplyDeleteThank you,
Babis
awesome dude, i gotta message you sometime i just joined this website but us fellow computer geeks gotta stick together!!!!!!! i will definately be in touch
ReplyDeleteLater
Billy maize