-
Notifications
You must be signed in to change notification settings - Fork 0
/
contentscript.js
36 lines (31 loc) · 1.58 KB
/
contentscript.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
$(function() {
var wufooUrl = 'https://hudl.wufoo.com/forms/dev-sensei-nomination/def/field13=' + encodeURI(window.location.href);
var usersApiUrl = 'https://api.github.com/users/'
var nominateButtonHtml = '<button type="button" class="btn btn-sm nominate-button">Nominate!</button>';
var nominateSidebarHtml = ' \
<div class="discussion-sidebar-item sidebar-nominate"> \
<h3 class="discussion-sidebar-heading">Dev Sensei Nomination</h3>' +
nominateButtonHtml +
'</div>';
var currentUser = $('#user-links').find('.name').text().trim();
$.get(usersApiUrl + currentUser, function(user) {
wufooUrl += '&field1=' + encodeURIComponent(user.email);
});
$('.discussion-sidebar').prepend(nominateSidebarHtml);
$('.timeline-comment:not(.timeline-comment-current-user):not(.timeline-comment-) .timeline-comment-actions').prepend(nominateButtonHtml);
$('.nominate-button').click(function() {
var parents = $(this).parents('.timeline-comment-header');
if (parents && parents.length) {
var nominee = parents.first().find('.author').text().trim();
$.get(usersApiUrl + nominee, function(user) {
if (user.email) {
wufooUrl += '&field2=' + encodeURIComponent(user.email);
}
}).always(function() {
window.location.assign(wufooUrl);
});
} else {
window.location.assign(wufooUrl);
}
});
});