Last active
July 17, 2017 23:33
-
-
Save birkholz/61f04cf3397a9464a108e9246380dfbe to your computer and use it in GitHub Desktop.
A userscript for adding a 1-click approve button to PRs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name GitHub 1-click PR Approve | |
// @namespace https://gist.github.com/birkholz | |
// @description Adds a 1-click approve button to Pull Requests | |
// @version 3 | |
// @author https://github.com/birkholz | |
// @match https://github.com/*/*/pull/*/files | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function AddButton() { | |
var reviewMenu = document.querySelector('.pull-request-review-menu'); | |
if (reviewMenu.querySelector('input[value=approve]').disabled) return; | |
var approveButton = document.createElement('button'); | |
approveButton.innerText = 'Approve'; | |
approveButton.classList.add('btn', 'btn-sm', 'btn-primary'); | |
approveButton.type = 'button'; | |
approveButton.style = 'margin-left:20px;'; | |
approveButton.onclick = function(e) { | |
e.preventDefault(); | |
reviewMenu.querySelector('input[value=approve]').checked = true; | |
reviewMenu.querySelector('button[type=submit]').click(); | |
return false; | |
}; | |
document.querySelector('.pr-review-tools').append(approveButton); | |
var reviewButton = document.querySelector('.js-reviews-container > button'); | |
reviewButton.classList.remove('btn-primary'); | |
} | |
window.setTimeout(AddButton, 300); | |
})(); |
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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.