Skip to content

Instantly share code, notes, and snippets.

@juanca
Created March 2, 2017 18:42
Show Gist options
  • Select an option

  • Save juanca/5fd799c5b094e3e4f8b709cd101d7403 to your computer and use it in GitHub Desktop.

Select an option

Save juanca/5fd799c5b094e3e4f8b709cd101d7403 to your computer and use it in GitHub Desktop.
Github PR bookmarklet: Load all file diffs
javascript:
document.querySelectorAll('.load-diff-button').forEach(node => node.click())
@melfa

melfa commented Mar 29, 2019

Copy link
Copy Markdown

Load first 50 files with only "Load Diff" button, without reason (this exclude large files, deleted files and so on):
Array.from(document.querySelectorAll('.js-diff-load-button-container')).filter(container => !container.querySelector('.hidden-diff-reason')).slice(0, 50).forEach(container => container.querySelector('.load-diff-button').click())

@uttamraj-pando

Copy link
Copy Markdown

awesome.would have received lot of upvotes in stackoverflow

@ElectricRCAircraftGuy

Copy link
Copy Markdown

@juanca

juanca commented Oct 9, 2020

Copy link
Copy Markdown
Author

oh, if you're keeping a collection around. here is another i use pretty regularly:

https://gist.github.com/juanca/669c59f15a17e20022b8bd78b12889e6

@s0undt3ch

Copy link
Copy Markdown

Only click on files which are not yet marked as reviewed.

Array.from(document.querySelectorAll('.file')).filter(container => !container.querySelector('input.js-reviewed-checkbox:checked')).filter(container => container.querySelector('.load-diff-button')).forEach(node => node.click())

@s0undt3ch

Copy link
Copy Markdown

Nope, that doesn't work :/

@s0undt3ch

Copy link
Copy Markdown

Ah ha!

Array.from(document.querySelectorAll('.file')).filter(container => !container.querySelector('input.js-reviewed-checkbox:checked')).forEach(pnode => pnode.querySelectorAll('.load-diff-button').forEach(node => node.click()))

@AronNovak

Copy link
Copy Markdown

image
Well, use it carefully for large pull requests, you can easily end up with being blocked.

@s0undt3ch

s0undt3ch commented May 4, 2021

Copy link
Copy Markdown

Well, that really must be a massive PR.
Mine was ~1.6k files changed and I never hit that...

@AronNovak

Copy link
Copy Markdown

image
I was blocked for such a PR. But the block only took for a few minutes, not hours fortunately.

@juanca

juanca commented May 12, 2021

Copy link
Copy Markdown
Author

Woah, I guess we could batch the requests for x files at a time? Might seem a bit excessive for a bookmark though. Up to anyone else if they want to improve on the script.

@mcoberly2

Copy link
Copy Markdown

Thanks! I just put the Javascript in my browser URI field and voila!

@ScriptAutomate

Copy link
Copy Markdown

I had to modify a little:

Array.from(document.getElementsByClassName('load-diff-button')).map(button => button.click())`

https://gist.github.com/ScriptAutomate/a3240e8767f0e8e70644ebf3ca4b74fb#github-reviewing-prs-with-tons-of-modified-files-and-load-diff-buttons

@ryan-walsh-forte

Copy link
Copy Markdown

The original from 2017 above seems to work for me. Thanks!

@JetUni

JetUni commented Nov 17, 2023

Copy link
Copy Markdown

This didn't work for me on a PR with 1200 files changed, so I came up with this code that I ran from the console. I ran it with up to 50 files at a time (in the slice and splice) with great success!

// Find all files in the PR
let files = Array.from(document.querySelectorAll('.file'));
// Filter by the files that aren't reviewed already
let filteredFiles = files.filter(file => !file.querySelector('.js-reviewed-checkbox').checked);

// Load the next 10 files
filteredFiles.slice(0, 10).forEach(file => file.querySelector('.load-diff-button').click());

// After reviewing all 10 files, run these commands to mark them as reviewed
// and delete them from the filtered array
filteredFiles.slice(0, 10).forEach(file => file.querySelector('.js-reviewed-checkbox').click());
filteredFiles.splice(0, 10);

@HappyRashair

Copy link
Copy Markdown

Niiice :) It worked for 600 files / 3k lines changed

@DavidMelnychuk

Copy link
Copy Markdown

This is fantastic, thank you

@bri12415

bri12415 commented Sep 3, 2024

Copy link
Copy Markdown

Thanks for this!

@nabilfreeman

Copy link
Copy Markdown

Here's another useful one that de-renders the viewed blocks to improve page performance (viewed diffs are still rendered in the background, and even if you filter out viewed files in the contextual menu, their diffs are puzzlingly still rendered invisibly, massively slowing down everything)

// Removes all viewed diffs from the DOM (refresh the page to get them back)
Array.from(document.querySelectorAll('.file')).filter(container => container.querySelector('input.js-reviewed-checkbox:checked')).forEach(node => node.remove())

@mfn

mfn commented Nov 21, 2025

Copy link
Copy Markdown

I've used this bookmarklet for years!

Note: for me it does not work for the new Files Changed experience, but this one does:

javascript:document.querySelectorAll('button').forEach(button=>{if(button.textContent.includes('Load Diff'))button.click()});

HTH

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