Skip to content

Instantly share code, notes, and snippets.

@kopiro
Created October 2, 2011 12:03
Show Gist options
  • Save kopiro/1257388 to your computer and use it in GitHub Desktop.
Save kopiro/1257388 to your computer and use it in GitHub Desktop.
Find your "best friends" on Facebook
javascript:
var friends = {};
var bfriends = [];
var char = 97;
if (!q) var q = document.querySelector("#q");
q.style.color="white";
go = function(){
q.blur();
var charS = String.fromCharCode(char);
char++;
console.log("Testing "+charS);
q.setAttribute("value", charS);
q.setAttribute("placeholder", charS);
q.value = charS;
q.placeholder = charS;
q.focus();
var e = document.createEvent("HTMLEvents");
e.initEvent("click",true,true);
document.querySelector(".uiSearchInput").dispatchEvent(e);
q.dispatchEvent(e);
q.value=charS;
document.querySelector(".uiTypeaheadView").style.display="none !important";
var qf = document.querySelectorAll("li.user");
if (qf.length>0) {
var thisq = qf[0];
qhref = thisq.querySelector("a").getAttribute("href");
if (friends[qhref]) friends[qhref].count++;
else {
friends[qhref] = {};
friends[qhref].node = document.createElement("li");
friends[qhref].node.innerHTML = thisq.innerHTML;
friends[qhref].node.className = "user";
friends[qhref].name = thisq.querySelector("span.text").innerHTML;
friends[qhref].count = 1;
console.log(friends[qhref]);
}
}
if (char<123) setTimeout(function(){go()}, 100);
else {
for (var k in friends)
if (friends[k].count>=friends[k].name.split(" ").length)
bfriends.push(friends[k]);
q.blur();
setInterval(function(){viewbf.apply()},500);
}
};
viewbf = function() {
var sdiv = document.querySelector(".search");
sdiv.innerHTML = '<li class="header"><a href="" rel="ignore" target=""><span class="text">Your best friends</span></a></li>';
for (var i=0; i<bfriends.length; i++)
sdiv.appendChild(bfriends[i].node);
document.querySelector(".uiTypeaheadView").style.display="block !important";
};
go.apply();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment