Skip to content

Instantly share code, notes, and snippets.

@larsxschneider
Last active October 10, 2024 16:49
Show Gist options
  • 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.

@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