-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
151 lines (126 loc) · 4.44 KB
/
main.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
$(document).ready(function () {
let typingTimer;
let doneTypingInterval = 2000;
$('#user1').on('keyup', function (e) {
clearTimeout(typingTimer);
typingTimer = setTimeout(doneTyping, doneTypingInterval);
$('#versus').html("<br><br><br><center><h1>v/s</h1></center>");
let username1 = e.target.value;
//AJAX request
$.ajax({
url: 'https://api.github.com/users/' + username1,
data: {
client_id: 'b71c2c1c952382dc0aab',
client_secret: '579729a9a22a970009b5b8afaed90a1cc13675c3'
}
}).done(function (response) {
$.ajax({
url: 'https://api.github.com/users/' + username1 + '/repos',
data: {
client_id: 'b71c2c1c952382dc0aab',
client_secret: '579729a9a22a970009b5b8afaed90a1cc13675c3',
sort: 'created : asc',
per_page: 5
}
})
$('#avatar1').html(`
<div id="winner1"></div>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">${response.name}</h3>
</div>
<div class="panel-body">
<center><img class="thumbnail" style="height:200px; width:200px;" src="${response.avatar_url}">
</center>
</div>
</div>
`);
});
});
$('#user2').on('keyup', function (e) {
clearTimeout(typingTimer);
typingTimer = setTimeout(doneTyping, doneTypingInterval);
let username2 = e.target.value;
$('#versus').html("<br><br><center><h1>v/s</h1></center>");
//AJAX request
$.ajax({
url: 'https://api.github.com/users/' + username2,
data: {
client_id: 'b71c2c1c952382dc0aab',
client_secret: '579729a9a22a970009b5b8afaed90a1cc13675c3'
}
}).done(function (response) {
$.ajax({
url: 'https://api.github.com/users/' + username2 + '/repos',
data: {
client_id: 'b71c2c1c952382dc0aab',
client_secret: '579729a9a22a970009b5b8afaed90a1cc13675c3',
sort: 'created : asc',
per_page: 5
}
})
$('#avatar2').html(`
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">${response.name}</h3>
</div>
<div class="panel-body">
<center><img class="thumbnail" style="height:200px; width:200px;" src="${response.avatar_url}">
</center>
</div>
</div>
`);
});
});
//on keydown, clear the countdown
$('#user1', '#user2').on('keydown', function () {
clearTimeout(typingTimer);
});
//user is "finished typing," do something
function doneTyping() {
$('#compare').show();
}
$('#compare').on('click', function () {
if (document.getElementById('user1').value == document.getElementById('user2').value) {
alert("Please compare two different users!");
return false;
}
let username1 = document.getElementById('user1').value;
$.ajax({
url: 'https://api.github.com/users/' + username1,
data: {
client_id: 'b71c2c1c952382dc0aab',
client_secret: '579729a9a22a970009b5b8afaed90a1cc13675c3'
}
}).done(function (response) {
var noOfPublicRepos = response.public_repos;
var noOfPublicGists = response.public_gists;
var followers = response.followers;
var following = response.following;
var score1 = (4 * noOfPublicRepos + 3 * noOfPublicGists + 7 * followers + (-0.5) * following) / 10;
$('#score1').html(`<h3>Your Score is ${score1}</h3>`);
let username2 = document.getElementById('user2').value;
$.ajax({
url: 'https://api.github.com/users/' + username2,
data: {
client_id: 'b71c2c1c952382dc0aab',
client_secret: '579729a9a22a970009b5b8afaed90a1cc13675c3'
}
}).done(function (response) {
var noOfPublicRepos = response.public_repos;
var noOfPublicGists = response.public_gists;
var followers = response.followers;
var following = response.following;
var score2 = (4 * noOfPublicRepos + 3 * noOfPublicGists + 7 * followers + (-0.5) * following) / 10;
$('#score2').html(`<h3>Your Score is ${score2}</h3>`);
// clear the winner flag if neccessary
$('.arrow_box').remove();
if (score1 > score2) {
$('#winner1').append(`<div class="arrow_box">Winner!</div>`);
} else {
$('#winner2').append(`<div class="arrow_box">Winner!</div>`);
}
});
});
});
});