Skip to content

Instantly share code, notes, and snippets.

@birkholz
Last active July 17, 2017 23:33
Show Gist options
  • Select an option

  • Save birkholz/61f04cf3397a9464a108e9246380dfbe to your computer and use it in GitHub Desktop.

Select an option

Save birkholz/61f04cf3397a9464a108e9246380dfbe to your computer and use it in GitHub Desktop.
A userscript for adding a 1-click approve button to PRs
// ==UserScript==
// @name GitHub 1-click PR Approve
// @namespace https://gist.github.com/birkholz
// @description Adds a 1-click approve button to the sidebar of PRs on GitHub
// @version 2
// @author https://github.com/birkholz
// @match https://github.com/*/*/pull/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function AddButton() {
var approveButton = document.createElement('button');
approveButton.innerText = '1-Click Approve';
approveButton.classList.add('btn', 'btn-md', 'btn-primary');
approveButton.type = 'button';
approveButton.style = 'width:100%;margin-bottom:1em;';
approveButton.onclick = function(e) {
e.preventDefault();
document.querySelector('.tabnav-tabs > a:last-child').click();
window.setTimeout(function() {
var reviewMenu = document.querySelector('.pull-request-review-menu');
reviewMenu.querySelector('input[value=approve]').checked = true;
reviewMenu.querySelector('button[type=submit]').click();
}, 500);
return false;
};
document.querySelector('.discussion-sidebar-item').prepend(approveButton);
}
window.setTimeout(AddButton, 300);
})();
@birkholz

birkholz commented Jul 17, 2017

Copy link
Copy Markdown
Author

screen shot 2017-07-17 at 12 52 35 pm

Adds a "1-Click Approve" button to the sidebar of the PR homepage.

I got tired to going to a PR, clicking "Files changed", "Review changes", "Approve", "Submit". This reduces a 4-click process down to 1.

See this revision for the sidebar button. The latest version has the button in the Files Changed tab.

@birkholz

Copy link
Copy Markdown
Author

Technical notes:

  • The "files changed" tab doesn't exist in the DOM until you click it, so we have to switch tabs before we can submit the review.
  • I hate using timeouts to add content to the DOM. I saw someone listening for pjax events, but that didn't work for me. Maybe GitHub changed their event names.

@birkholz

Copy link
Copy Markdown
Author

The button has been moved to the Files Changed tab:

screen shot 2017-07-17 at 4 21 38 pm

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