Skip to content

Instantly share code, notes, and snippets.

@issa-tseng
Last active November 9, 2016 03:22
Show Gist options
  • Save issa-tseng/0c9e79f2dde907417535cf3518149a44 to your computer and use it in GitHub Desktop.
Save issa-tseng/0c9e79f2dde907417535cf3518149a44 to your computer and use it in GitHub Desktop.
fivethirtyeight election sorter
// press cmd+option+i (or right-click and select inspect element), go to the console, and paste this in:
(function() {
var value = function(elem) { return ((elem.className.indexOf('close') > 0) ? 1000 : ((elem.className.indexOf('call') > 0) ? -1000 : ((elem.className.indexOf('watch') > 0) ? 1000 : 0))) - $(elem).attr('data-state').charCodeAt(0); };
var dim = function(elem) { if (elem.className.indexOf('call') > 0) $(elem).css('opacity', 0.3); }
var go = function() { var states = $('.sparklines .state').get(); states.sort(function(a, b) { return value(b) - value(a); }); var container = $('.sparklines'); states.forEach(function(elem) { container.append(elem); dim(elem); }); };
window.setInterval(go, 30000);
$('.switch-toggle').click(function() { window.setTimeout(go, 0); });
go();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment