Skip to content

Instantly share code, notes, and snippets.

@jakebellacera
Last active November 3, 2021 16:50
Show Gist options
  • Save jakebellacera/d9d06dd047db759542f9b6ef7ec238ce to your computer and use it in GitHub Desktop.
Save jakebellacera/d9d06dd047db759542f9b6ef7ec238ce to your computer and use it in GitHub Desktop.
Quickly review files in Github pull requests by pressing spacebar on your keyboard with this userscript.
// ==UserScript==
// @name Github Pull Request Autofocus
// @description Helps you quickly review files in Github pull requests.
// @author Jake Bellacera
// @match https://github.com/*/pull/*/files
// ==/UserScript==
// HOW TO USE
// ==========
// 1. Open a Github pull request.
// 2. Navigate to the "Files changed" tab.
// 3. Click on one of the "Viewed" checkboxes on top of any file to mark it as viewed and collapse
// the diff. At this point the next file's "Viewed" checkbox will be focused.
// 4. View the changes on the next file, then press your space bar key to check the file's "Viewed"
// checkbox.
// 5. Repeat these steps for each file.
//
// TROUBLESHOOTING
// ===============
// Github dynamically loads pages onto the screen, so your userscript extension may not notice that
// you navigated to the "Files changed" page. If the script isn't working just reload the page.
(function () {
"use strict";
const checkboxSelector = ".js-reviewed-checkbox";
const focusNextCheckbox = () => {
const allCheckboxes = Array.prototype.slice.call(
document.querySelectorAll(checkboxSelector)
);
const nextCheckbox = allCheckboxes.find((checkbox) => !checkbox.checked);
if (nextCheckbox) {
nextCheckbox.focus();
}
};
document.addEventListener("change", (e) => {
if (e.target.matches(checkboxSelector)) {
if (e.target.checked === true) {
focusNextCheckbox();
}
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment