Skip to content

Instantly share code, notes, and snippets.

@larsxschneider
Last active March 24, 2020 19:14
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larsxschneider/c024d7308683eefe2704dffe0b706549 to your computer and use it in GitHub Desktop.
Save larsxschneider/c024d7308683eefe2704dffe0b706549 to your computer and use it in GitHub Desktop.
Bookmarklet - Close all files in PR

Installation

Make a new bookmark in your browser. Set the name to Close all PR files (or something else you like) and set the URL to:

javascript:void((function(d){d.querySelectorAll('div:not(.Details--on) > div.file-header > div.file-actions > button').forEach(function(x){x.click()});})(document));

Usage

Click the bookmark to close all files in your PR.

Credit

Based on ideas from @yardensachs and @benjamincharity.

@eanhuddleston
Copy link

Nice, thanks for sharing.

@boris-meerovich-sp
Copy link

+1

@alex-equities
Copy link

Thanks

@M-Dahab
Copy link

M-Dahab commented Jun 10, 2018

Thanks a ton.

@pravsingh
Copy link

very helpful. thanks Lars.

btw do you know if there exists a reverse of this bookmarklet?
I'm interested in expanding all files and look out for any comments left out which was not addressed in new commits.
It can be very helpful in code reviews and checking all the comments.

@aejay-rs
Copy link

aejay-rs commented Aug 23, 2018

This bookmarklet runs fairly slow for me, especially if I'm dealing with a lot of files to look through. I wrote this one up, trying to align it with how they collapse the sections internally. If they end up changing classes around, this could break one day, but for now it runs very quickly for me because it avoids having to run all the other on click event listeners registered on the page. Hope it helps others.

Here's one that collapses all:

javascript:void((function(d){d.querySelectorAll('.js-file.js-details-container').forEach(function(i){i.classList.remove("open"); i.classList.remove("Details--on");});})(document));

Here's one that expands all (but doesn't load large diffs):

javascript:void((function(d){d.querySelectorAll('.js-file.js-details-container').forEach(function(i){i.classList.add("open"); i.classList.add("Details--on");});})(document));

And here's one that expands all and should try to load large diffs, too:

javascript:void((function(d, w){d.querySelectorAll('.js-file.js-details-container').forEach(function(i){i.classList.add("open"); i.classList.add("Details--on");}); d.querySelectorAll('.js-diff-entry-loader').forEach(function(x){ x.src = new URL(x.getAttribute('data-fragment-url'), w.location.origin).toString() });})(document, window));

@iamveritas
Copy link

This bookmarklet runs fairly slow for me, especially if I'm dealing with a lot of files to look through. I wrote this one up, trying to align it with how they collapse the sections internally. If they end up changing classes around, this could break one day, but for now it runs very quickly for me because it avoids having to run all the other on click event listeners registered on the page. Hope it helps others.

Here's one that collapses all:

javascript:void((function(d){d.querySelectorAll('.js-file.js-details-container').forEach(function(i){i.classList.remove("open"); i.classList.remove("Details--on");});})(document));

Here's one that expands all (but doesn't load large diffs):

javascript:void((function(d){d.querySelectorAll('.js-file.js-details-container').forEach(function(i){i.classList.add("open"); i.classList.add("Details--on");});})(document));

And here's one that expands all and should try to load large diffs, too:

javascript:void((function(d, w){d.querySelectorAll('.js-file.js-details-container').forEach(function(i){i.classList.add("open"); i.classList.add("Details--on");}); d.querySelectorAll('.js-diff-entry-loader').forEach(function(x){ x.src = new URL(x.getAttribute('data-fragment-url'), w.location.origin).toString() });})(document, window));

this works very well, thank you!

@ClintEsteMadera
Copy link

As of 2020, @aejay-rs solutions worked for me while the original on this gist did not.

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