Skip to content

Instantly share code, notes, and snippets.

@bumi
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bumi/9323651 to your computer and use it in GitHub Desktop.
Save bumi/9323651 to your computer and use it in GitHub Desktop.
This bookmarklet reorders the diff files in a github diff view. It tries to display the spec/test files directly after the actual code files. Add a new bookmark with the content of the bookmarklet.js file
javascript:(function(){$.each($('#files .js-details-container'), function(i, element) {var path = $(element).children('.meta').data('path'); if(!path.match(/_spec\.*$/)) { var extension_match = path.match(/\..*$/); if(extension_match) { var extension = extension_match[0]; var filename_match = path.match(/.*(\/.*)\..*$/); if(filename_match) { var filename = path.match(/.*(\/.*)\..*$/)[1]; var spec_path = filename + '_spec' + extension; var spec_dom = $('.meta[data-path$="' + spec_path + '"]').parent(); if(spec_dom.length > 0) { spec_dom.detach(); spec_dom.insertAfter(element); } } } }});})();
// jquery hacking... omg :)
// iterationg over all files, searching for the spec file and inserting that dom element after the actual file
$.each($('#files .js-details-container'), function(i, element) {
var path = $(element).children('.meta').data('path');
if(!path.match(/_spec\.*$/)) {
var extension_match = path.match(/\..*$/);
if(extension_match) {
var extension = extension_match[0];
var filename_match = path.match(/.*(\/.*)\..*$/);
if(filename_match) {
var filename = path.match(/.*(\/.*)\..*$/)[1];
var spec_path = filename + '_spec' + extension;
var spec_dom = $('.meta[data-path$="' + spec_path + '"]').parent();
if(spec_dom.length > 0) {
spec_dom.detach();
spec_dom.insertAfter(element);
}
}
}
}
})
@paulkoegel
Copy link

missing semicolon on line 6.

@paulkoegel
Copy link

bookmarklet doesn't work in firefox :(
http://monosnap.com/image/rnloUkL6BAmUUNjgV2Vu1KyvBWdEST.png
have to run the code manually via the JS console.

@bumi
Copy link
Author

bumi commented Mar 20, 2014

an idea how to fix it?

@kangguru
Copy link

not using FF? :trollface:

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