Convert your Facebook friend contacts to CSV.

sygeek

Technomancer
Source Code By Vytautas Jakutis .

To execute this JavaScript code, you need to open the friends list from your own profile. Also, do not forget to scroll down, until all friends are loaded.

When the script is finished, a pop up window with a filled text field is opened. You need to select all text, copy it to a text editor and save it with csv file extension.

Sadly, the forum won't let me insert the javascript into a link. You guys have to either copy all the code and paste into the URL address or just create a bookmark manally with the code provided below.

The source code:
Code:
javascript:(function(){var%20screenNamesAndEmailsAndWebsites,getContacts,screenNames,fillBorn,iframe,IframeSeries,fieldsToExport,log,txt,getData,fillData,ready,warn,except,fillCityCountry,multi,contactsToCSV,fill;fieldsToExport=["First%20name","Last%20name","Second%20name","Birthday%20date","Home%20address","Home%20city","Home%20country","Home%20phone","Home%20phone%202","Home%20phone%203","Home%20phone%204","Cell%20phone","Cell%20phone%202","Cell%20phone%203","Cell%20phone%204","E-Mail","E-Mail%202","E-Mail%203","E-Mail%204","WWW","WWW%202","WWW%203","WWW%204","IM%20Skype","IM%20AOL","Additional%20info"];log=function(){};ask=function(a){var%20b;b=window.confirm(a);log("ask",a,b);return%20b};except=function(a){log("except",a);throw%20a};warn=function(a){log("warn",a);window.alert(a)};txt=function(a){if(a.childNodes.length===0){return""}if(typeof%20a.textContent!=="undefined"){return%20a.textContent}if(typeof%20a.innerText!=="undefined"){return%20a.innerText}log(a);throw"cannot%20get%20text%20from%20node"};getData=function(f){var%20a,g,d;try{if(f.nodeType===3){return%20f.data}if(f.classList.contains("url")){return%20f.href}if(f.classList.contains("fsm")||f.classList.contains("mediaRowWrapper")){f=f.firstChild}if(f.classList.contains("uiList")){if(f.firstChild.lastChild.nodeType===1&&f.firstChild.lastChild.classList.contains("pls")&&f.firstChild.lastChild.classList.contains("inlineLabel")){a={};for(d=0,c=f.childNodes;c[d];d++){g=c[d].lastChild.firstChild;if(typeof%20a[g.data]==="undefined"){a[g.data]=[]}if(c[d].firstChild.nodeType===3){a[g.data].push(c[d].firstChild.data)}else{a[g.data].push(txt(c[d].firstChild))}}}else{a=[];for(d=0,c=f.childNodes;c[d];d++){if(c[d].firstChild.nodeType===3){a.push(c[d].firstChild.data)}else{a.push(txt(c[d]))}}}return%20a}}catch(b){except("failed%20at"+txt(f))}return%20txt(f)};ready=function(a){return%20a.document.querySelectorAll("td.data").length>0};fillData=function(f,a){var%20d,e,b;e=a.document.querySelectorAll("td.data");b=a.document.querySelectorAll("th.label");if(e.length!==b.length){throw"data%20length%20does%20not%20equal%20label%20length"}for(d=0;e[d];d++){if(b[d].firstChild!==null){f[b[d].firstChild.data]=getData(e[d].firstChild)}}};iframe=function(a,d){var%20b;b=window.document.createElement("iframe");b.src=a;b.onload=function(){d(b.contentWindow,function(){window.document.body.removeChild(b)})};b.height=1;b.width=1;b.style.opacity=0;window.document.body.appendChild(b)};IframeSeries={el:window.document.createElement("iframe"),load:function(a,d){var%20b=this;this.el.onload=function(){d(b.el.contentWindow)};this.el.src=a}};window.document.body.appendChild(IframeSeries.el);fillBorn=function(d,a){var%20f,b,g,e,h;b=d.document.querySelectorAll(".fbProfileBylineFragment");g="Born%20on";e=null;for(f=0;b[f];f++){h=b[f].childNodes[1].data;if(h.indexOf(g)===0){h=h.substr(g.length);if(!Date.parse(h)){h+=",2010"}a.born=new%20Date(h);return}}};fillCityCountry=function(e,b){var%20d;d=e.split(",");if(d.length>2){throw"unexpectedly%20many%20comma-separated%20values%20in%20address"}else{if(d.length===1){b["Home%20country"]=d[0]}else{b["Home%20city"]=d[0];b["Home%20country"]=d[1]}}};multi=function(b,d,a,e){if(typeof%20a[e]==="undefined"){log("no",e);return}a[e].forEach(function(g,f){d[b+(f>0?(""+(f+1)):"")]=g});delete%20a[e]};screenNames=function(a,d,b){Object.keys(b).forEach(function(e){if(typeof%20a[d]["("+e+")"]!=="undefined"){if(e==="Google%20Talk"){a.Email.push(a[d]["("+e+")"][0])}if(e==="Twitter"){a.Website.push("*twitter.com/"+a[d]["(Twitter)"][0])}else{var%20f=0;if(typeof%20a["IM"+b[e]]==="undefined"){f++;a["IM"+b[e]]=a[d]["("+e+")"][0]}a[d]["("+e+")"].slice(f).forEach(function(g){a["Additional%20info"]+="IM"+b[e]+":"+g+";"})}delete%20a[d]["("+e+")"]}});if(Object.keys(a[d]).length>0){throw"too%20many"+d+"defined:"+JSON.stringify(a[d])}delete%20a[d]};screenNamesAndEmailsAndWebsites=function(a,b){if(typeof%20a.Email==="undefined"){a.Email=[]}if(typeof%20a.Website==="undefined"){a.Website=[]}a["Additional%20info"]+="Facebook%20profile:"+a.url[0]+";";delete%20a.url;a.Website=a.Website.filter(function(d){if(d.substr(0,4)!=="http"){log("unknown%20website",d);return%20false}return%20true});if(typeof%20a["Screen%20Name"]!=="undefined"){screenNames(a,"Screen%20Name",b)}if(typeof%20a["Screen%20Names"]!=="undefined"){screenNames(a,"Screen%20Names",b)}multi("E-Mail",a,a,"Email");multi("WWW",a,a,"Website")};fill=function(n,f){var%20b,k,h,m,a,o,l;try{o=false;for(b=0,c=n.document.querySelectorAll("script");c[b];b++){a=txt(c[b]).indexOf("navigation.php?id=");if(a>=0){o=true;f["Additional%20info"]="Facebook%20ID:"+txt(c[b]).substring(a+"navigation.php?id=".length,txt(c[b]).indexOf("\\",a))+";"}}if(!o){throw"could%20not%20find%20Facebook%20ID"}fillData(f,n);l=f.fullName.split("");f["First%20name"]=l[0];f["Last%20name"]=l[l.length-1];if(l.length>2){f["Second%20name"]=l[1]}delete%20f.fullName;if(typeof%20f.Address!=="undefined"){if(f.Address.length>2){throw"unexpectedly%20long%20address:"+f.Address}else{if(f.Address.length===1){fillCityCountry(f.Address[0],f);delete%20f.Address}else{f["Home%20address"]=f.Address[0];fillCityCountry(f.Address[1],f);delete%20f.Address}}}if(typeof%20f.Phone!=="undefined"){b=0;if(typeof%20f.Phone.Mobile!=="undefined"){b++;multi("Cell%20phone",f,f.Phone,"Mobile")}if(typeof%20f.Phone.Home!=="undefined"){b++;multi("Home%20phone",f,f.Phone,"Home")}if(Object.keys(f.Phone).length!==0){throw"too%20many%20phones%20defined:"+JSON.stringify(f.Phone)+","+Object.keys(f.Phone)}delete%20f.Phone}screenNamesAndEmailsAndWebsites(f,{Skype:"Skype",Twitter:"Twitter",AIM:"AOL","Google%20Talk":"Jabber","Windows%20Live%20Messenger":"MSN","Yahoo!Messenger":"Yahoo","Gadu-Gadu":"Gadu-Gadu",ICQ:"ICQ"});fillBorn(n,f);if(typeof%20f.born!=="undefined"){k=f.born;h=k.getUTCMonth()+1;m=k.getUTCDate()+1;f["Birthday%20date"]=(h<10?("0"+h):String(h))+"/"+(m<10?("0"+m):String(m))+"/"+k.getUTCFullYear();delete%20f.born}for(b%20in%20f){if(Object.prototype.hasOwnProperty.call(f,b)&&fieldsToExport.indexOf(b)<0){f["Additional%20info"]+=b+":"+f[b]+";";delete%20f[b]}}}catch(g){warn("Contact%20was%20not%20fully%20read:"+JSON.stringify(f))}};contactsToCSV=function(d){var%20b,e,a;e=fieldsToExport;a=e.join(",")+"\n";log("header",a);d.forEach(function(g){var%20f;f=[];e.forEach(function(h){if(typeof%20g[h]==="undefined"||g[h]===""){f.push("")}else{f.push('"'+g[h].replace(new%20RegExp('"',"g"),'""')+'"')}});a+=f.join(",")+"\n"});b=window.open();b.document.write("<textarea>"+a+"</textarea>")};getContacts=function(d){var%20b,e,a,f;b=document.querySelectorAll(".fwb");e=[];for(a=0;b[a];a++){if(b[a].classList.contains("fsl")){f={};f.url=[b[a].firstChild.href];f.fullName=b[a].firstChild.firstChild.data;e.push(f)}}d(e)};getContacts(function(f){var%20b,a,d,e;a=0;d=500;e=20;window.contacts=f;b=function(){log(a,f.length);if(a===f.length){contactsToCSV(f)}else{log("extracting",f[a].fullName,f[a].url[0]);IframeSeries.load(f[a].url[0]+(f[a].url[0].indexOf("profile.php")<0?"?":"&")+"sk=info",function(g){var%20h,i;h=0;i=function(){if(h===e){if(ask('Failing%20to%20find%20data%20of"'+f[a].fullName+'".Keep%20trying?')){h=0}else{fill(g,f[a]);a++;b();return}}setTimeout(function(){log("poll");if(ready(g)){fill(g,f[a]);a++;b();log("extracted",f[a])}else{h++;i()}},d)};i()})}};b()});})()
 
Last edited:
Top Bottom