Skip to content

Instantly share code, notes, and snippets.

@ibrahima
Created November 29, 2012 09:02
Show Gist options
  • Select an option

  • Save ibrahima/4167712 to your computer and use it in GitHub Desktop.

Select an option

Save ibrahima/4167712 to your computer and use it in GitHub Desktop.
Bookmarklet for embedding diff views into Github commit log pages.
(function(){
// template from http://coding.smashingmagazine.com/2010/05/23/make-your-own-bookmarklets-with-jquery/
// the minimum version of jQuery we want
var v = "1.7.0";
// check prior inclusion and version
if (window.jQuery === undefined || window.jQuery.fn.jquery < v) {
var done = false;
var script = document.createElement("script");
script.src = "http://ajax.googleapis.com/ajax/libs/jquery/" + v + "/jquery.min.js";
script.onload = script.onreadystatechange = function(){
if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
done = true;
initMyBookmarklet();
}
};
document.getElementsByTagName("head")[0].appendChild(script);
} else {
if(window.githubInlineDiff === undefined){
initMyBookmarklet();
}
}
function initMyBookmarklet() {
(window.githubInlineDiff = function() {
// your JavaScript code goes here!
$('<button class="inline-diff-toggle gobutton sha" >Diff</a>').insertAfter($('a.gobutton'));
$('button.inline-diff-toggle').on('click', function(event){
$elem = $(event.target);
$link = $elem.prev('a.gobutton');
parent=$elem.closest('li.commit');
existingDiff = parent.children('div.diff-view');
if (existingDiff.length == 0){
url=$link.attr('href');
$.get(url, function(data, textStatus, jqXHR){
diffView=$(data).find('div.diff-view#files');
// Not changing ID for now because otherwise the styling is bad. Might be a way to work around it
// diffView.attr('id', 'inline-diff-'+url.substr(url.lastIndexOf('/')+1));
parent.append(diffView);
}
);
} else{
existingDiff.toggle();
}
}
);
})();
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment