-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcc.js
47 lines (45 loc) · 1.93 KB
/
cc.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
const myForm = document.querySelector('#my-form');
const nameInput = document.querySelector('#name');
const msg = document.querySelector('.msg');
const output = document.querySelector('#output');
myForm.addEventListener('submit', onSubmit);
function onSubmit(e) {
e.preventDefault();
output.classList.add('result');
output.innerHTML = '<p>loading...</p>';
fetch(`https://competitive-coding-api.herokuapp.com/api/codechef/${nameInput.value}`)
.then((response) => response.json())
.then((data) => {
if (data['status'] == "Failed") {
output.classList.remove('result');
output.innerHTML = '';
msg.classList.add('error');
msg.innerHTML = 'Enter valid id';
setTimeout(() => {
msg.classList.remove('error');
msg.innerHTML = '';
}, 2000);
}
else {
output.innerHTML = ``;
const rating = data['rating'];
const stars = data['stars'];
const maxRating = data['highest_rating'];
const noofcontest = data['contest_ratings'].length;
const solved = data['fully_solved']['count'];
const psolved = data['partially_solved']['count'];
const username = data['user_details']['username'];
output.innerHTML = `
<h3><a href="https://www.codechef.com/users/${username}" target="_blank">${username}</a></h3>
<p>Rating: ${rating} (${stars})</p>
<p>Highest rating: ${maxRating} </p>
<p>No. of contests given: ${noofcontest} </p>
<p>Problems Solved: ${solved} + ${psolved} [full+partial]</p>
`;
}
})
.catch((err) => {
alert('Error, please try again');
});
nameInput.value = '';
}