Last active
June 27, 2020 03:01
-
-
Save michaelfagan/438db4456fc5d63d3951ee71aa089185 to your computer and use it in GitHub Desktop.
when run on a facebook friends list, outputs a list of families
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
var by_name = {}; | |
function url2names(u) { | |
var url_name = u.match(/\.com\/[^?#\\.]+\.([^?#\/]+)/) | |
if (!url_name || url_name[1] === 'php') { | |
return []; | |
} | |
return url_name[1].replace(/\d/g, '').replace(/\.$/, '').replace(/-/g, '.').split('.'); | |
} | |
function add(display_name, names) { | |
names.forEach(function(name){ | |
if (name.length > 1) { | |
if (typeof by_name[name] === 'undefined') { | |
by_name[name] = []; | |
} | |
by_name[name].push(display_name); | |
} | |
}); | |
} | |
add(document.querySelector('#fb-timeline-cover-name a').textContent, url2names(location.href)); | |
var people = document.querySelectorAll('._3i9')[0].querySelectorAll('.fcb a'); | |
for (var i = 0; i < people.length; i++) { | |
var display_name = people[i].textContent; | |
var names = url2names(people[i].getAttribute('href')); | |
display_name.toLowerCase().replace(/^.+ /, '').replace(/-/g, ' ').split(' ').forEach(function(name){ | |
if (names.indexOf(name) === -1){ | |
names.push(name); | |
} | |
}); | |
add(display_name, names); | |
} | |
var sorted = []; | |
for (var name in by_name) { | |
if (by_name[name].length > 1) { | |
sorted.push([name, by_name[name]]); | |
} | |
} | |
sorted.sort(function(a, b){ | |
return a[1].length - b[1].length; | |
}); | |
sorted.forEach(function(set){ | |
console.log(set[0] + ' (' + set[1].length + '): ' + set[1].join(', ')); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment