forked from Aniket-debug/cfairfinder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind.js
74 lines (54 loc) · 2.52 KB
/
find.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
async function find_AIR() {
document.getElementById("out").innerHTML = "Loading..";
let username = document.getElementById("username").value;
username = username.trim();
let contestId = document.getElementById("contest_id").value;
contestId = contestId.trim();
if(username===""){
document.getElementById("out").innerHTML = "Enter valid username";
return;
}
if (contestId.slice(0, 31) != "https://codeforces.com/contest/") {
document.getElementById("out").innerHTML = "Entered Link is not correct";
return;
}
contestId = contestId.slice(31);
let l = 0;
while ('0' <= contestId[l] && contestId[l] <= '9') l++;
contestId = contestId.slice(0, l);
let rank = 0;
for (let i = 1; i <= 10000; i += 600) {
let response = await fetch(`https://codeforces.com/api/contest.standings?contestId=${contestId}&from=${i}&count=600&showUnofficial=false`);
if (!(response.status >= 200 && response.status <= 299)) {
document.getElementById("out").innerHTML = "Error Occured Server is unavailable refresh and try again or try after some time";
return;
}
response = await response.json();
let userinfo = "https://codeforces.com/api/user.info?handles=";
for (let user of response.result.rows)
userinfo += user.party.members[0].handle + ';';
response = await fetch(userinfo);
if (!(response.status >= 200 && response.status <= 299)) {
document.getElementById("out").innerHTML = "Error Occured Server is unavailable refresh and try again or try after some time";
return;
}
response = await response.json();
for (let user of response.result) {
if (user.country === "India") {
rank++;
if (user.handle == username) {
document.getElementById("out").innerHTML = user.handle + " Your AIR is: " + rank;
return;
}
}
if (user.handle == username) {
if (user.country == undefined)
document.getElementById("out").innerHTML = "Username you entered didn't mention his/her country";
else
document.getElementById("out").innerHTML = "Username you entered is not from India";
return;
}
}
}
document.getElementById("out").innerHTML = "Not Found";
}