Skip to content

Instantly share code, notes, and snippets.

@fprochazka
Forked from juzna/01-choose.png
Created January 24, 2012 17:28
Show Gist options
  • Save fprochazka/1671348 to your computer and use it in GitHub Desktop.
Save fprochazka/1671348 to your computer and use it in GitHub Desktop.
GitHub Play
(function() {
var commits = [], repo = document.location.href.match(/github\.com\/([^\/]+\/[^\/]+)\//)[1];
// Play for all commits
$('.commit-group .commit-links')
.append($('<a href="#" class="browse-button github-play-select">Play</a>'));
// show next commit
var nextCommit = function () {
$('.site .container').load(commits.shift() + ' #.site .container', function () {
$('span.sha').each(function () {
var sha = $(this).html();
$(this).replaceWith($('<a class="sha" href="/' + repo + '/commit/'+ sha + '">' + sha + '</a>'));
});
$('html, body').animate({scrollTop:0}, 'fast');
});
if (commits.length < 1) $('#next-commit').hide();
return false;
}
// When commit play-ed
$('.site .container').on('click', '.github-play-select', function(ev) {
$('#play-spinner').css({'left' : ev.pageX + 15, 'top' : ev.pageY + 15}).show();
var x, href = $(ev.target).closest('li.commit').find('a.gobutton')[0].href;
if(!(x = href.match(/commit\/([0-9a-f]+)/))) return false; // something must have gone wrong
var fromCommit = x[1]; //TODO: make diff from parent of this commit
$.get('https://github.com/' + repo + '/compare/' + fromCommit.toString() +'...HEAD', function(compare) {
$(compare).find('table.commits tr').each(function () {
commits.push($(this).find('td:first a').attr('href'));
});
var spinner = $('#play-spinner')
.css({'position':'relative', 'left':'0', 'top':'0'});
// next commit link
$('#next-commit').click(nextCommit).show()
.prepend(spinner).click();
});
return false;
});
// next commit link
$('<a href="#" id="next-commit">Next commit</a>').css({
'right':'20px', 'bottom':'20px', 'position':'fixed', // position
'font-size':'20px', 'font-weight':'bold', 'display':'none', 'z-index':'1000' // style
}).appendTo('body');
// spinner
$('<img id="play-spinner" />')
.attr('src', GitHub.Ajax.spinner)
.css({'position':'absolute', 'display':'none', 'z-index':'1000'})
.appendTo('body');
$('#play-spinner')
.ajaxStart(function() { $(this).show(); })
.ajaxStop(function() { $(this).hide(); });
})()

GitHub Play

RePlay a set of commits as they happened

Overview

GitHub Play is a scriptlet, which allows you to replay commits as they happened. Usage:

  1. Go to commits history
  2. Run the play.js script (e.g. in WebInspector/FireBug or as bookmarklet)
  3. Select the commit, which you've seen as the last
  4. Hit Play on the right - it'll start Play mode and show you history between those two selected commits
  5. Hit Next commit to see the newer one

Example

Open https://github.com/nette/nette/commits and run

javascript:$('head').append('<script src="https://raw.github.com/gist/1671348/play.js" />')
@juzna
Copy link

juzna commented Jan 24, 2012

Very nice!

@JanTvrdik
Copy link

Feature request: link to previous commit and keyboard shortcuts (j / k?)

@fprochazka
Copy link
Author

Kdybych tam chtěl dávat i předchozí commit, tak se dostanu jenom na ty, které vytáhnu z toho diffu, což je divné, že. Tak jsem to tam ani nedával. Kdyby se ti chtělo, tak fork ;)

Ale klávesové zkratky jsou dobrý nápad :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment