Created
December 1, 2012 19:12
-
-
Save Haraguroicha/4184200 to your computer and use it in GitHub Desktop.
Get Facebook's friends order list by Haraguroicha
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
/*********************************** | |
* Title: Get Facebook's friends order list (EdgeRank) | |
* Author: Haraguroicha | |
* Date: 2012/12/3 | |
* Version: 0.7 | |
* See also: http://edgerank.net/ | |
* http://unwire.hk/2012/12/02/fb-friend-rank/news/ | |
* http://garylai1990.tumblr.com/post/36953217144/facebook | |
* | |
* NOTE: You can just run this in your browser's console tab to using latest version of this script | |
document.body.appendChild((function(){ var s = document.createElement("script"); s.src = "https://raw.github.com/gist/4184200"; return s; })()); | |
*********************************** | |
0.7 mark which user is not in firend list | |
0.6 orderIndex change to percent of ER(EdgeRank) | |
0.5 change method to EdgeRank | |
0.4 fix list output order not correct | |
0.3 improve performance | |
0.2 add list amount limit | |
0.1 initial version | |
*/ | |
String.prototype.repeat = function repeat(q) { | |
var s = ""; | |
for(var n = 0; n < q; n++) | |
s += this.toString(); | |
return s; | |
} | |
Array.prototype.existUID = function existUID(uid) { | |
var obj = this; | |
for(var index = 0; index < obj.length; index++) | |
if(obj[index].i == uid) | |
return true; | |
return false; | |
} | |
var orderByDecreasing = false; //if this is true, the list will list in decreasing order, other wise will in increasing | |
if(location.origin.match(/facebook\.com/) != null) { | |
var urlFriends = location.origin.match(/https?:\/\//)[0] + "www.facebook.com/ajax/typeahead_friends.php?__a=1&u=" + Env.user; | |
var urlER = location.origin.match(/https?:\/\//)[0] + "www.facebook.com/ajax/typeahead/search/bootstrap.php?__a=1&filter[0]=user&lazy=0&token=v7&stale_ok=0&viewer=" + Env.user; | |
var xhr = new XMLHttpRequest(); | |
xhr.open("GET", urlFriends, false); | |
xhr.onreadystatechange = function() { | |
if(xhr.readyState == 4) | |
if (xhr.status == 200) | |
friendList = JSON.parse(xhr.responseText.substring(xhr.responseText.indexOf('{'))).payload.friends; | |
} | |
xhr.send(null); | |
xhr.open("GET", urlER, false); | |
xhr.onreadystatechange = function() { | |
if(xhr.readyState == 4) | |
if (xhr.status == 200) | |
listFriendsList(JSON.parse(xhr.responseText.substring(xhr.responseText.indexOf('{')))); | |
} | |
xhr.send(null); | |
} else { | |
alert('This script is only can run in the facebook pages/tabs'); | |
} | |
function listFriendsList(list) { | |
var result = ""; | |
var friends = list.payload.entries; | |
console.group("Frients Order List (" + ((orderByDecreasing) ? "Decreasing" : "Increasing") + " Order)"); | |
console.log("Total " + friends.length + " friends in list (Your friend amount is " + friendList.length + ")"); | |
var gp = ""; | |
var gpe = ""; | |
for(var i = ((orderByDecreasing) ? friends.length - 1 : 0); ((orderByDecreasing) ? i >= 0 : i < friends.length); i += ((orderByDecreasing) ? -1 : 1)) { | |
var orderIndex = ((orderByDecreasing) ? 0 : -2); | |
if(gp != "" && gpe == (i + 2 + orderIndex).toString()) { | |
console.groupEnd(); | |
gp = ""; | |
} | |
if(gp == "") { | |
if(orderByDecreasing) { | |
gp = (i + 1).toString(); | |
gpe = (Math.floor((gp - 1) / 100) * 100) + 1; | |
console.groupCollapsed(gpe + " ~ " + gp); | |
} else { | |
gp = (i + 1).toString(); | |
gpe = (Math.floor((gp - 0) / 100) * 100) + 100; | |
if(gpe > friends.length) | |
gpe = friends.length.toString(); | |
console.groupCollapsed(gp + " ~ " + gpe); | |
} | |
} | |
var obj = friends[i]; | |
var space = " ".repeat(friends.length.toString().length - (i + 1).toString().length); | |
var s = + space + (i + 1) + ":\t\"" + obj.text + "\", ER=" + (Math.floor(obj.index * -10000) / 10000) + "%, id=" + obj.uid + ", link=" + location.origin + obj.path; | |
result += ((result.length > 0) ? "\n" : "") + s; | |
if(obj.type != "user" || !friendList.existUID(obj.uid)) | |
console.warn("Not in friend list or not an user:\n" + s); | |
else | |
console.log(s); | |
} | |
console.groupEnd(); | |
console.groupEnd(); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment