-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
308 lines (256 loc) · 9.77 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Facebook Friend Name Analyzer</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- Le styles -->
<link href="../assets/css/bootstrap.css" rel="stylesheet">
<link href="../assets/css/bootstrap-responsive.css" rel="stylesheet">
<link href="../assets/css/bootstrap-arrows.css" rel="stylesheet">
<style type="text/css">
body {
padding-top: 60px;
}
</style>
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="../assets/js/html5shiv.js"></script>
<![endif]-->
<!-- Fav and touch icons -->
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="../assets/ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="../assets/ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="../assets/ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="../assets/ico/apple-touch-icon-57-precomposed.png">
<link rel="shortcut icon" href="../assets/ico/favicon.png">
</head>
<body>
<div id="fb-root"></div>
<script>
// Additional JS functions here
window.fbAsyncInit = function() {
FB.init({
appId : '159049770927427', // App ID
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
document.getElementById('data').style.display = 'block';
document.getElementById('login').style.display = 'none';
generateIntroText();
generateStats();
}
else {
document.getElementById('data').style.display = 'none';
document.getElementById('login').style.display = 'block';
}
});
FB.Event.subscribe('auth.login', function(response){
window.location.reload();
});
};
function generateIntroText(){
//generate the intro text
FB.api('/me', function(response) {
var name=response.name;
var profile_pic = "http://graph.facebook.com/"+response.id+"/picture?type=large";
var el = document.getElementById('intro');
var htmlString="";
htmlString+='<h3>Your name is '+name+'.<h3>';
htmlString+='<img src="'+profile_pic+'"></img>';
htmlString+='<small> *This person is awesome.</small><br>';
el.innerHTML = htmlString;
});
}
function generateStats(){
FB.api('fql', { q: 'SELECT uid, first_name, last_name, sex, friend_count, mutual_friend_count, name from user where uid IN (SELECT uid1 FROM friend WHERE uid2 = me())' }, function (response)
{
var htmlString="";
var el = document.getElementById('stats');
var fullNames=new Array();
var firstNames=new Array();
var lastNames=new Array();
var palindromes=new Array();
var palinIds=new Array();
var numMale=0;
var numFemale=0;
var mostFriends=0;
var mostMutFriends=0;
for(var i = 0; i<response.data.length; i++){
var friendInfo=response.data[i];
if (friendInfo.sex=='male'){
numMale++;
}
else{
numFemale++;
}
friendId=friendInfo.uid;
fullName=friendInfo.name;
fullNames.push(fullName);
firstName=friendInfo.first_name;
firstNames.push(firstName);
lastName=friendInfo.last_name;
lastNames.push(lastName);
numFriends=friendInfo.friend_count;
if (numFriends>response.data[mostFriends].friend_count){
mostFriends=i;
}
mutFriends=friendInfo.mutual_friend_count;
if (mutFriends>response.data[mostMutFriends].mutual_friend_count){
mostMutFriends=i;
}
//lowercase the first name for palindrome check
firstName=firstName.toLowerCase();
revFirstName=firstName.split("").reverse().join("");
if (revFirstName==firstName){
palindromes.push(fullName);
palinIds.push(friendId);
}
}
//figure out longest, shortest
var longest = 0;
var shortest = 0;
var mostVowels=0;
var leastVowels=0;
for(var i = 0; i < fullNames.length; i++){
if(fullNames[i].length > fullNames[longest].length){
longest = i;
}
if(fullNames[i].length < fullNames[shortest].length){
shortest = i;
}
if (countVowels(fullNames[i])>countVowels(fullNames[mostVowels])){
mostVowels=i;
}
if (countVowels(fullNames[i])<countVowels(fullNames[leastVowels])){
leastVowels=i;
}
}
htmlString+="Number of friends: "+fullNames.length+"<br>";
htmlString+="Number male: "+numMale+"<br>";
htmlString+="Number female: "+numFemale+"<br>";
htmlString+="Longest name: "+fullNames[longest]+" ("+fullNames[longest].length+")<br>";
htmlString+="Shortest name: "+fullNames[shortest]+" ("+fullNames[shortest].length+")<br>";
htmlString+="Most vowels: "+fullNames[mostVowels]+" ("+countVowels(fullNames[mostVowels])+")<br>";
htmlString+="Least vowels: "+fullNames[leastVowels]+" ("+countVowels(fullNames[leastVowels])+")<br>";
htmlString+="Most common first name: "+mode(firstNames)[0]+" ("+mode(firstNames)[1]+")<br>";
htmlString+="Most common last name: "+mode(lastNames)[0]+" ("+mode(lastNames)[1]+")<br>";
htmlString+="Most friends: "+fullNames[mostFriends]+" ("+response.data[mostFriends].friend_count+")<br>";
htmlString+="Most mutual friends: "+fullNames[mostMutFriends]+" ("+response.data[mostMutFriends].mutual_friend_count+")<br>";
//sort last, it breaks other variables
fullNames.sort()
htmlString+="First friend alphabetically: "+fullNames[0]+"<br>";
htmlString+="Last friend alphabetically: "+fullNames[fullNames.length-1]+"<br>";
htmlString+="<br>";
htmlString+="<p>You've got "+palindromes.length+" friends with palindromic first names:</p>";
for (var i=0;i<palindromes.length;i++){
profile_pic = "http://graph.facebook.com/"+palinIds[i]+"/picture";
htmlString+='<a href="http://facebook.com/'+palinIds[i]+'">';
htmlString+='<img src="'+profile_pic + '"/> ';
htmlString+=palindromes[i];
htmlString+="</a><br>";
}
el.innerHTML = htmlString;
});
}
function countVowels(str) {
var count = 0;
for (var i = 0; i < str.length; i++) {
if (str.charAt(i).match(/[a-zA-Z]/) != null) {
// findVowels
if (str.charAt(i).match(/[aeiouAEIOU]/))
{
count++;
}
}
}
return count;
}
function mode(array)
{
if(array.length == 0)
return null;
var modeMap = {};
var maxEl = array[0], maxCount = 1;
for(var i = 0; i < array.length; i++)
{
var el = array[i];
if(modeMap[el] == null)
modeMap[el] = 1;
else
modeMap[el]++;
if(modeMap[el] > maxCount)
{
maxEl = el;
maxCount = modeMap[el];
}
}
return new Array(maxEl, modeMap[maxEl]);
}
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a href"/" class="brand">Facebook Friend Name Analyzer, by Howard Chung</a>
</div>
</div>
</div>
<div class="container">
<p class="lead">
A variety of mostly pointless stats about your friends' names.<br>
Written in JavaScript, with CSS and jQuery on the frontend. (formerly PHP, but PHP kind of sucks)<br>
Some of your friends won't show up here because they aren't opted into Facebook's API. Boo.<br>
<a class="btn btn-primary" href="https://github.com/howardc93/nameanalyzer">Get the source on Github</a>
</p>
<div class="fb-like" data-send="false" data-width="450" data-show-faces="true"></div>
<div class="hero-unit">
<div id="data">
<div id="intro">
</div>
<div id="stats" class="lead">
</div>
</div>
<div id="login">
<h2>Log in to Facebook to begin.</h2>
<div class="fb-login-button" data-show-faces="true" data-width="200" data-max-rows="1"></div>
</div>
</div> <!-- hero unit -->
</div> <!-- /container -->
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="../assets/js/jquery.js"></script>
<script src="../assets/js/bootstrap-transition.js"></script>
<script src="../assets/js/bootstrap-alert.js"></script>
<script src="../assets/js/bootstrap-modal.js"></script>
<script src="../assets/js/bootstrap-dropdown.js"></script>
<script src="../assets/js/bootstrap-scrollspy.js"></script>
<script src="../assets/js/bootstrap-tab.js"></script>
<script src="../assets/js/bootstrap-tooltip.js"></script>
<script src="../assets/js/bootstrap-popover.js"></script>
<script src="../assets/js/bootstrap-button.js"></script>
<script src="../assets/js/bootstrap-collapse.js"></script>
<script src="../assets/js/bootstrap-carousel.js"></script>
<script src="../assets/js/bootstrap-typeahead.js"></script>
<script src="../assets/js/bootstrap-arrows.js"> </script>
<script src="../assets/js/bootstrap.js"> </script>
<script type="text/javascript">
$(function () {
// Bootstrap Arrows
$('.arrow, [class^=arrow-]').bootstrapArrows();
});
</script>
</body>
</html>