-
-
Save psawaya/aaecb214988ed15c79ccb3dbb800ed88 to your computer and use it in GitHub Desktop.
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
function creator(o, data, node) { | |
var content = document.createElement(node); | |
content.cellspacing = "3" | |
var cell = document.createTextNode(data); | |
content.appendChild(cell); | |
o.appendChild(content); | |
} | |
function displayData(arr) { | |
var table = document.createElement('table'); | |
var thead = document.createElement('thead'); | |
table.appendChild(thead); | |
var row = document.createElement('tr'); | |
creator(row, 'Name', 'th'); | |
creator(row, 'FB ID', 'th'); | |
creator(row, 'Type', 'th'); | |
creator(row, 'Score', 'th'); | |
thead.appendChild(row); | |
var tbody = document.createElement('tbody'); | |
table.appendChild(tbody); | |
for(i=0; i < arr.length; i++){ | |
var type = arr[i].type; | |
var row = document.createElement('tr'); | |
creator(row, arr[i]["text"], 'td'); | |
creator(row, arr[i]["uid"], 'td'); | |
creator(row, Object.keys(arr[i]["grammar_costs"])[0].slice(0,-1).substring(1), 'td'); | |
creator(row, arr[i]["grammar_costs"][Object.keys(arr[i]["grammar_costs"])[0]], 'td'); | |
tbody.appendChild(row); | |
} | |
document.body.innerHTML = ""; | |
document.body.appendChild(table); | |
} | |
function bakeJSONData(arr) { | |
var out = arr | |
.filter(function (x) { | |
return x.is_connected && x.type === 'user'; | |
}) | |
.map(function(x) { | |
return { | |
name: x.text, | |
uid: x.uid, | |
score: x["grammar_costs"][Object.keys(x["grammar_costs"])[0]] | |
}; | |
}); | |
var a = document.createElement('a'); | |
a.href = "data:text/json," + JSON.stringify(out); | |
a.download = 'fbdump.json'; | |
document.body.appendChild(a); | |
a.click(); | |
a.parentNode.removeChild(a); | |
} | |
//need to find user's unique id. Trying each of the below until succeeds. | |
//facebook keeps changing their variables and keys | |
// https://www.facebook.com/ajax/typeahead/search/facebar/bootstrap/?viewer=1372650009&__a=1 | |
id = require("CurrentUserInitialData")["USER_ID"] || require("CurrentUserInitialData")["ACCOUNT_ID"] || require("Env").user || require("CurrentUserInitialData")["id"]; | |
url = "//www.facebook.com/ajax/typeahead/search/facebar/bootstrap/?viewer=" + id + "&__a=1"; | |
x = new XMLHttpRequest(); | |
x.onreadystatechange=function(){ | |
if (x.readyState==4 && x .status==200){ | |
srr=JSON.parse(x.responseText.substring(9)).payload.entries; | |
bakeJSONData(srr); | |
} | |
} | |
x.open("GET",url,true); | |
x.send(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment