Skip to content

Instantly share code, notes, and snippets.

@seven1m
Last active August 29, 2015 14:02
Show Gist options
  • Save seven1m/d97081205c0b47be811d to your computer and use it in GitHub Desktop.
Save seven1m/d97081205c0b47be811d to your computer and use it in GitHub Desktop.
GreaseMonkey (or TamperMonkey) script that adds a +1 button to GitHub Pull Requests. (Click "Raw" to install.)
// ==UserScript==
// @name GitHub Pull Request Enhancements
// @namespace http://tannermar.es
// @version 0.2
// @description Add "Plus One" and "Retest" buttons to PR pages. Automatically add and remove "+1", "+2", and "NOT READY!" labels bast on comment contents. Included on all of github because pushState.
// @include https://github.com/*
// @copyright 2014+, @tannermares
// ==/UserScript==
var emojiPlusOnes = function() {
return jQuery(".comment-body:visible:has(.emoji[title=':+1:'])").length;
}
var rawPlusOnes = function() {
return jQuery(".comment-body:visible:contains('+1')").length;
}
var plusOnesReceived = function() {
return emojiPlusOnes() + rawPlusOnes();
}
var isPullRequestPage = function() {
return !!window.location.href.match(/pull\/\d/)
}
var isButtonAlreadyPresent = function() {
return jQuery(".plus-one-button").length > 0;
}
var setupButtons = function() {
if (isButtonAlreadyPresent() || !isPullRequestPage()) {
return;
}
//$("<button type='button' class='btn btn-sm retest-button'><span class='octicon octicon-sync'></span> Retest</button>")
//.prependTo($('.gh-header-actions'))
//.click(function(e) {
// setTimeout(function(){
// console.log('adding comment');
// $('#new_comment_field').val('retest').parents('.js-new-comment-form').find('.primary[type="submit"]').click();
// }, 50);
// setTimeout(function(){
// console.log('removing comment');
// $('div[id^=issuecomment]').last().find('.delete-button').click()
// }, 1000);
//});
$("<button type='button' class='btn btn-sm plus-one-button'><span class='octicon octicon-plus'></span> Plus one</button>")
.prependTo($('.gh-header-actions'))
.click(function(e) {
setTimeout(function(){
$('#new_comment_field').val(':+1:').parents('.js-new-comment-form').find('.btn-primary[type="submit"]').click();
});
});
$("<button type='button' class='btn plus-one-button'><span class='octicon octicon-plus'></span> Plus one</button>")
.appendTo($('#partial-new-comment-form-actions'))
.click(function(e) {
setTimeout(function(){
$('#new_comment_field').val(':+1:').parents('.js-new-comment-form').find('.btn-primary[type="submit"]').click();
});
});
}
jQuery(function(){
jQuery(document).on('ajaxComplete', function(){
window.setTimeout(setupButtons, 50);
});
});
@danott
Copy link

danott commented Jun 2, 2014

👍

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