Skip to content

Instantly share code, notes, and snippets.

@kentbrew
Created November 11, 2012 02:00
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kentbrew/4053356 to your computer and use it in GitHub Desktop.
Save kentbrew/4053356 to your computer and use it in GitHub Desktop.
Who Likes Mitt?
<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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment