Last active
December 11, 2015 22:29
-
-
Save riaf/4670169 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 PR counter | |
// @namespace jp.riaf.github.pull-counter | |
// @description GitHub pull request review counter | |
// @author Keisuke SATO <[email protected]> | |
// @run-at document-end | |
// @match https://github.com/*/pull/* | |
// @version 1.0 | |
// ==/UserScript== | |
(function (d, func) { | |
var h = d.getElementsByTagName('head')[0]; | |
var s1 = d.createElement('script'); | |
s1.setAttribute('src', 'https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js'); | |
s1.addEventListener('load', function() { | |
var s2 = d.createElement('script'); | |
s2.textContent = 'jQuery.noConflict();(' + func.toString() + ')(jQuery);'; | |
h.appendChild(s2); | |
}, false); | |
h.appendChild(s1); | |
})(document, function($) { | |
var count_positive = 0 | |
, count_negative = 0 | |
, $counter = $('<span />').addClass('pull-number') | |
, counter_refresh = function() { | |
$counter.text('+' + count_positive + ' / -' + count_negative); | |
}; | |
$(function() { | |
counter_refresh(); | |
$('.pull-head-meta').append($counter); | |
$('.comment-content .comment-body').each(function(){ | |
var $self = $(this) | |
, text = $self.text(); | |
// string | |
count_positive += (text.match(/\+1/g) || []).length; | |
count_negative += (text.match(/\-1/g) || []).length; | |
// emoji | |
count_positive += $('.emoji[title=":+1:"]', $self).length; | |
count_negative += $('.emoji[title=":-1:"]', $self).length; | |
counter_refresh(); | |
}); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment