-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodeforces.js
More file actions
38 lines (36 loc) · 1.38 KB
/
codeforces.js
File metadata and controls
38 lines (36 loc) · 1.38 KB
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
export function codeforcesContests(element) {
// codechef url
const CODEFORCES_URL = 'https://codeforces.com/api/contest.list'
async function fetchCodeforcesContests(){
const response = await fetch(CODEFORCES_URL);
return response.json();
}
// durationSeconds, frozen, id, name, phase, relativeTimeSeconds, startTimeSeconds, type
const codeforces_contests = Promise.resolve(fetchCodeforcesContests());
codeforces_contests.then((val)=>{
var rows = `
<tr>
<th>CODE</th><th>NAME</th><th>START</th><th>DURATION</th>
</tr>
`
let length = val.result.length
for(let i = 0; i < length; i++){
if(val.result[i].phase=="BEFORE"){
var obj = new Date(val.result[i].startTimeSeconds*1000);
var row = `
<tr>
<td>${val.result[i].id}</td>
<td>${val.result[i].name}</td>
<td>${formatTS(obj)}</td>
<td>${(val.result[i].durationSeconds/60)} mins</td>
</tr>
`
rows = rows+row
}
}
element.innerHTML = "<table>"+rows+"</table>"
})
}
function formatTS(timestamp){
return timestamp.toLocaleDateString()+" "+timestamp.toLocaleTimeString()
}