Skip to content

Instantly share code, notes, and snippets.

@aseemk
Created May 9, 2012 23:34
Show Gist options
  • Save aseemk/2649767 to your computer and use it in GitHub Desktop.
Save aseemk/2649767 to your computer and use it in GitHub Desktop.
dotjs script for GitHub: account for whitespace in commit diffs!
// if this is a commit page, properly account for whitespace in diffs!
// XXX this works by adding ?w=1 to the URL, which requires a page reload. =/
// to prevent this behavior, change the URL to ?w. (?w=0 and ?w= don't work!)
// TODO consider changing this behavior to add a link/button instead?
// TODO is the .page-commit-show class the right thing to base this on?
if ($(document.body).hasClass('page-commit-show')) {
// XXX this'll overwrite any other query params, but good enough for now?
// also note that setting location.search -- even to whatever it already
// is -- causes a page change, so only set it if to a different value!
// TODO use location.replace() instead to prevent new history entry, but
// that's a bit tricky to do while preserving all other parts of the URL.
if (location.search.indexOf('?w') < 0) {
location.search = '?w=1';
}
}
// and update all links to commits to do the same!
// XXX requires a regex, feels a bit hacky, but okay?
// btw: https://developer.mozilla.org/en/CSS/Attribute_selectors
$('a[href*="/commit/"]').each(function (i, a) {
var $a = $(a);
// XXX is this too lax? do we need to robustify somehow?
$a.attr('href', $a.attr('href') + '?w=1');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment