Skip to content

Instantly share code, notes, and snippets.

@juanca
Last active April 12, 2017 17:20
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 juanca/403d4ef5bbfe826a2cefd3455e4b47c9 to your computer and use it in GitHub Desktop.
Save juanca/403d4ef5bbfe826a2cefd3455e4b47c9 to your computer and use it in GitHub Desktop.
Github PR bookmarklet: button to toggle height on file diff
javascript:
document.querySelectorAll('.file').forEach(function (fileDiff) {
var div, fa;
div = document.createElement('div');
div.className = 'btn btn-sm';
div.textContent = 'TOGGLE';
div.addEventListener('click', function (event) {
const fileActions = event.target.parentElement;
const fileHeader = fileActions.parentElement;
const file = fileHeader.parentElement;
const blobWrapper = file.querySelector('.blob-wrapper');
console.log('Toggle height on', blobWrapper);
blobWrapper.style.height = (blobWrapper.style.height === '' ? '0px' : '');
});
fa = fileDiff.querySelector('.file-actions');
fa.insertBefore(div, fa.children[0]);
});
@juanca
Copy link
Author

juanca commented Mar 9, 2017

Looks like there is a bug where the event handler is cleaned up when switching between PR tabs. :(

@juanca
Copy link
Author

juanca commented Apr 12, 2017

Well well well, looks like github released their own "expand/collapse" button. >:(

... It's probably more performant than my JS.

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