public
Last active

Who Likes Mitt?

  • Download Gist
wholikesmitt.html
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
<html>
<head>
<title>Who Likes Mitt?</title>
<style>
pre#output {
height: 12em;
width: 500px;
overflow: auto;
}
</style>
</head>
<body>
<h1>Who likes Mitt?</h1>
<p>Here's a real-time look at the total number of likes on <a href="http://facebook.com/mittromney" target="_blank">Mitt Romney on Facebook</a>. Mmm, sweet tasty schadenfreude!</p>
<pre id="output"></pre>
<p id="start"></p>
<p>The number in parentheses at the end of each line is the difference since you first loaded the page. We're polling every ten seconds, to be nice to Facebook's API.</p>
<p>Source code, such as it is, is <a target="_blank" href="https://gist.github.com/4053356">up on GitHub</a>. Enjoy!</p>
 
<script>
 
var output = document.getElementById('output');
var likes = 0;
var pong = function (r) {
if (!likes) {
var p = document.getElementById('start');
p.innerHTML = r.likes + ' likes as of ' + new Date().toGMTString();
likes = r.likes;
}
var t = new Date().toGMTString();
var diff = '';
if (likes - r.likes !== 0) {
diff = ' (' + (0 - (likes - r.likes)) + ')';
}
output.innerHTML = t + ': ' + r.likes + diff + '\n' + output.innerHTML;
var apiCall = document.getElementById('apiCall');
if (apiCall && apiCall.parentNode) {
apiCall.parentNode.removeChild(apiCall);
}
};
 
var ping = function () {
var s = document.createElement('SCRIPT');
s.src = 'https://graph.facebook.com/mittromney?callback=pong';
s.id = 'apiCall';
s.type = 'text/javascript';
document.body.appendChild(s);
window.setTimeout( function () { ping(); }, 10000);
};
 
ping();
 
</script>
</body>
</html>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.