forked from FdelMazo/contribution-mural
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
69 lines (59 loc) · 1.94 KB
/
index.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var link_default = "<a href='https://github.com/FdelMazo/contribution-mural'>"
var texto_default = "<img class='img-icon' src='favicon.ico'> Visiten el repo para contribuir! <img class='img-icon' src='favicon.ico'>"
var API = "https://api.github.com/repos/fdelmazo/contribution-mural/pulls?state=all"
$(document).ready(function(){
hit_API()
var clicked = false
var commit = document.getElementById("commit");
commit.innerHTML = link_default + texto_default;
content.forEach(function(img) {
jQuery('<img/>', {
src: img.src,
'data-author': img.data_author,
alt: img.alt,
mouseover: function(ev) {
if(clicked) return
update_msg(ev)
},
click: function(ev) {
update_msg(ev);
clicked = !clicked
},
mouseleave: function() {
if(clicked) return;
clean_msg();
}
}).appendTo('body');
});
function update_msg(evt){
var imagen = evt.target
var msg = imagen.alt;
var author = $(imagen).data('author')
var author_link = "<a href='https://github.com/"+author+"'>" + '@' + author + '</a>'
commit.innerHTML = author_link + ' dice: ' + msg;
}
function clean_msg(){
commit.innerHTML = link_default + texto_default;
}
function hit_API(){
$.ajax({
url: API,
method: 'GET',
success: function(data) {
update_PRs(data)
}
})
}
function update_PRs(data){
var open = $('#pr-open')
var closed = $('#pr-closed')
var open_count = 0
var closed_count = 0
data.forEach(pr => {
if (pr.state == "closed") closed_count++
else if (pr.state == "open") open_count++
})
open.text(open_count)
closed.text(closed_count)
}
})