Created
December 2, 2012 01:34
-
-
Save cgspicer/4186445 to your computer and use it in GitHub Desktop.
A silly little thing that takes the first ten peeps from an object on the Facebook view and displays them in a little box in the lower left corner.
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
javascript:(function()%7Bfunction%20p()%7Bo.setAttribute(%22id%22%2C%22top-friends-wrapper%22)%3Bo.setAttribute(%22style%22%2C%22display%3Ablock%3Boverflow%3Ahidden%3Bposition%3Afixed%3Bbottom%3A20px%3Bleft%3A20px%3Bborder%3A1px%20solid%20black%3Bbackground%3Awhite%3B%22)%3Bvar%20e%3Ddocument.createElement(%22h3%22)%3Be.setAttribute(%22style%22%2C%22padding%3A3px%3Bbackground-color%3A%233b5998%3Bcolor%3Awhite%3B%22)%3Be.innerHTML%3D%22Top%20Ten%20Friends%22%3Bo.appendChild(e)%3Bs%3D0%3Bv()%7Dfunction%20d(e)%7Bdocument.body.appendChild(e)%7Dfunction%20v()%7Bif(s%3Ct.length)%7Bm(s)%3Bs%2B%2B%7D%7Dfunction%20m(e)%7Bvar%20n%3Dnew%20XMLHttpRequest%3Bn.open(%22GET%22%2C%22http%3A%2F%2Fgraph.facebook.com%2F%22%2Bt%5Be%5D%2Ctrue)%3Bn.onreadystatechange%3Dfunction()%7Bif(n.readyState%3D%3D4%26%26n.status%3D%3D200)%7Bvar%20i%3DJSON.parse(n.responseText)%3Br.push(i)%3Bn.abort()%3Bif(e%3D%3Dt.length-1)%7Be%3Dnull%3Bg()%7Delse%7Bv()%7D%7D%7D%3Bn.send()%7Dfunction%20g()%7Bfor(n%3D0%3Bn%3Cr.length%3Bn%2B%2B)%7Bvar%20e%3Dr%5Bn%5D%3Bvar%20t%3D%22http%3A%2F%2Fwww.facebook.com%2F%22%2Be.id%3Bvar%20i%3De.name%3Bvar%20s%3Ddocument.createElement(%22a%22)%3Bs.setAttribute(%22style%22%2C%22display%3Ablock%3Bpadding%3A3px%2010px%3B%22)%3Bs.setAttribute(%22href%22%2Ct)%3Bs.innerHTML%3Di%3Bo.appendChild(s)%7Dd(o)%7Dvar%20e%3Ddocument.getElementsByTagName(%22script%22)%3Bvar%20t%3D%5B%5D%3Bvar%20r%3D%5B%5D%3Bvar%20s%3Bvar%20o%3Ddocument.createElement(%22div%22)%3Bfor(i%3D0%3Bi%3Ce.length%3Bi%2B%2B)%7Bvar%20u%3De%5Bi%5D.innerHTML%3Bif(u.indexOf(%22OrderedFriendsListInitialData%22)%3E0)%7Bvar%20a%3Du.indexOf(%22%7B%22)%3Bvar%20f%3Du.lastIndexOf(%22%7D%22)%3Bu%3Du.slice(a%2Cf%2B1)%3Bvar%20l%3DJSON.parse(u)%3Bvar%20c%3Dl.jsmods.define%3Bvar%20h%3Dc%5Bc.length-1%5D%3Bt%3Dh%5B2%5D%3Bt%3Dt.list%3Bt%3Dt.slice(0%2C10)%3Bp()%7D%7D%7D)() |
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
javascript:(function(){ | |
var scriptTags = document.getElementsByTagName('script'); | |
var friends = []; | |
var friendsData = []; | |
var count; | |
var wrapperDiv = document.createElement('div'); | |
for ( i=0; i<scriptTags.length; i++ ) { | |
var scriptContent = scriptTags[i].innerHTML; | |
if ( scriptContent.indexOf( 'OrderedFriendsListInitialData' ) > 0 ) { | |
var firstCurly = scriptContent.indexOf('{'); | |
var lastCurly = scriptContent.lastIndexOf('}'); | |
scriptContent = scriptContent.slice(firstCurly,lastCurly+1); | |
var obj = JSON.parse( scriptContent ); | |
var define = obj.jsmods.define; | |
var orderedFriends = define[ define.length -1 ]; | |
friends = orderedFriends[2]; | |
friends = friends.list; | |
friends = friends.slice(0,10); | |
showTopFriends(); | |
} | |
} | |
function showTopFriends(){ | |
wrapperDiv.setAttribute('id','top-friends-wrapper'); | |
wrapperDiv.setAttribute('style','display:block;overflow:hidden;position:fixed;bottom:20px;left:20px;border:1px solid black;background:white;'); | |
var title = document.createElement( 'h3' ); | |
title.setAttribute('style', 'padding:3px;background-color:#3b5998;color:white;') | |
title.innerHTML = 'Top Ten Friends'; | |
wrapperDiv.appendChild( title ); | |
count=0; | |
getNextFriend(); | |
} | |
function addToDOM( element ){ | |
document.body.appendChild(element); | |
} | |
function getNextFriend() { | |
if ( count < friends.length ) { | |
getOGData(count); | |
count++; | |
} | |
} | |
function getOGData( count ) { | |
var request = new XMLHttpRequest(); | |
request.open("GET","http://graph.facebook.com/"+friends[count],true); | |
request.onreadystatechange = function() { | |
if(request.readyState == 4 && request.status == 200) { | |
var friendData = JSON.parse( request.responseText ); | |
friendsData.push( friendData ); | |
request.abort(); | |
if ( count == friends.length - 1 ) { | |
count=null; | |
createAnchors(); | |
} else { getNextFriend(); } | |
} | |
} | |
request.send(); | |
} | |
function createAnchors() { | |
for ( n=0;n<friendsData.length;n++) { | |
var friendData = friendsData[n]; | |
var friendURL = "http://www.facebook.com/" + friendData.id; | |
var friendName = friendData.name; | |
var friendA = document.createElement( 'a' ); | |
friendA.setAttribute('style','display:block;padding:3px 10px;'); | |
friendA.setAttribute('href',friendURL); | |
friendA.innerHTML = friendName; | |
wrapperDiv.appendChild( friendA ); | |
} | |
addToDOM( wrapperDiv ); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment