Skip to content

Instantly share code, notes, and snippets.

@alecgorge
Created December 4, 2010 19:33
Show Gist options
  • Save alecgorge/728414 to your computer and use it in GitHub Desktop.
Save alecgorge/728414 to your computer and use it in GitHub Desktop.
Gets the phone numbers of your Facebook friends and gives CSV and JSON output.
/**
* Run this script in the console on http://www.facebook.com/friends/edit/?sk=phonebook
*/
(function () {
function getScript(url, success) {
var script = document.createElement('script');
script.src = url;
var head = document.getElementsByTagName('head')[0],
done = false;
script.onload = script.onreadystatechange = function () {
if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
done = true;
success();
script.onload = script.onreadystatechange = null;
head.removeChild(script);
}
};
head.appendChild(script);
}
if (typeof jQuery == 'undefined') {
getScript('http://code.jquery.com/jquery-latest.min.js', function () {go();});
}
else {
go();
}
function go() {
var dict = {};
var lastName = "";
jQuery(".fsl").each(function (k,v) {
v = jQuery(v);
if(v.hasClass("fwb")) {
lastName = v.find("a").text();
dict[lastName] = {};
}
else {
var span = v.find("span").text();
var number = v.text().substring(0,v.text().length-span.length);
dict[lastName][span.toLowerCase()] = number;
}
});
for(var k in dict) {
var v = dict[k];
for(var i in v) {
if(v[i].length == 0) {
delete dict[k][i];
}
var count = 0;
for(var q in v) {
count++;
}
if(count == 0) {
delete dict[k];
}
}
for(var i in v) {
var num = v[i];
if(!num.match(/1 [0-9]+\.[0-9]+\.[0-9]+/)) {
dict[k][i] = "1 317."+num.substr(0,3)+"."+num.substr(3,4);
}
}
}
var csv = "name,Mobile Phone,Home Phone\n";
for(var k in dict) {
var v = dict[k];
var name = k;
var mobile = (v["mobile"] ? v["mobile"] : "");
var home = (v["land"] ? v["land"] : "");
csv += name+","+mobile+","+home+"\n";
}
console.log(JSON.stringify(dict));
console.log(csv);
}
}());
@ajfabian
Copy link

ajfabian commented Sep 8, 2019

Hi, I try to run the script but got this error:

ReferenceError: jQuery is not defined
debugger eval code:27:2
Loading failed for the <script> with source “http://code.jquery.com/jquery-latest.min.js”. contacts:1:1
Content Security Policy: The page’s settings blocked the loading of a resource at http://code.jquery.com/jquery-latest.min.js (“script-src”).
Source map error: TypeError: NetworkError when attempting to fetch resource.
Resource URL: moz-extension://7d82c51b-b833-4719-9801-505bbbff7c40/js/content.js
Source Map URL: pdf.js.map

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment