-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcodeevent.js
160 lines (125 loc) · 6.29 KB
/
codeevent.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
152
153
154
155
156
157
158
159
160
const rowclick = document.querySelector('.row');
const id = [1,2,12,35,63,73];
const idcount = [0,0,0,0,0,0];
const idname = ['Codeforces', 'Codechef', 'Topcoder', 'Google-code-comp', 'Hackerrank', 'Hackerearth'];
const logo = ['https://cdn.aelieve.com/toptere/Codeforces.jpg', 'https://www.improgrammer.net/wp-content/uploads/2016/01/Codechef-logo.png', 'https://www.theindianwire.com/wp-content/uploads/2018/06/Topcoder-logo.jpg', 'https://cdn-images-1.medium.com/max/1600/1*FHJTiIW9_enNj4RWSQ3NEQ.png', 'http://www.iamwire.com/wp-content/uploads/2014/06/hackerrank_g7yq8.png', 'https://verticalplatform.kr/wp-content/uploads/2014/03/hackerearth-logo.png']
let count = 0;
//for input bar
const input = document.querySelector(".form-control");
const addButton = document.querySelector("#fake-button");
const addTask = text => {
let numbers = text.split(':');
console.log(numbers[1]);
const modaltitle = document.querySelector(`#modal-title`);
console.log(modaltitle);
const modalbody = document.querySelector(`#modal-body-code`);
modaltitle.innerHTML = "";
modalbody.innerHTML = "";
let obj = {};
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if(xhr.readyState == 4) {
if(xhr.status == 200) {
obj = JSON.parse(xhr.responseText);
console.log(obj.result);
const img = document.createElement('div');
img.style.width = '18rem';
img.innerHTML = `<img class="card-img-top mx-auto" src="${logo[0]}" alt="Card image cap">`;
modaltitle.appendChild(img);
const ul = document.createElement('ul');
obj.result.forEach( (elements) => {
const li = document.createElement('li');
li.innerHTML = `<b>Contest ID : ${elements.contestId}</b><i>Contest Name</i>${elements.contestName} and <i> and handle is</i> ${elements.handle} and the newrating is <b>${elements.newRating}</b> and oldrating is <b>${elements.oldRating}</b> while rank is ${elements.rank}.`;
ul.appendChild(li);
});
modalbody.appendChild(ul);
document.querySelector(`#real-button`).click();
}
else {
console.log("file not found");
}
}
}
xhr.open('get',`https://codeforces.com/api/user.rating?handle=${numbers[1]}`,true) ;
xhr.send();
}
addButton.addEventListener("click", () => addTask(input.value));
const onclick = async (index_no) => {
console.log(`id is equal to ${id[index_no]}`);
const response = await fetch(`https://clist.by/api/v1/contest/?username=amu629&api_key=cfdcf7a003520eb7deadb0d84875aa5c87ce75c2&resource__id=${id[index_no]}&start__gt=2019-12-15T03:07:43&order__by=start&limit=10&utf-8&application/json`);
const responseJson = await response.json();
console.log(responseJson.objects);
if(idcount[index_no] === 0){
const modaltitle = document.querySelector(`#modal-title-${index_no}`);
console.log(modaltitle);
const img = document.createElement('div');
img.style.width = '18rem';
img.innerHTML = `<img class="card-img-top mx-auto" src="${logo[index_no]}" alt="Card image cap">`;
modaltitle.appendChild(img);
const modalbody = document.querySelector(`#modal-body-${index_no}`);
const ul = document.createElement('ul');
responseJson.objects.forEach( (elements) => {
const li = document.createElement('li');
li.innerHTML = `<b>${elements.event} : </b><i>Starts from </i>${elements.start} and <i>Ends at </i> ${elements.end} and the link of the contest is <a href = "${elements.href}">${elements.href}</a>`;
ul.appendChild(li);
});
modalbody.appendChild(ul);
idcount[index_no]++;
}
document.querySelector(`#real-${index_no}`).click();
}
const whenClickButton = async (e) => {
console.log(e.target.id);
let numbers = e.target.id.split('-');
console.log(numbers[1]);
const btn = document.querySelector(`#${e.target.id}`);
console.log(btn);
if(numbers[0] !== 'real'){
onclick(numbers[1]);
}
}
const fetchallsamplecard = () => {
id.forEach( (value,index) => {
const cards = document.createElement('div');
cards.classList.add('col-sm-4');
cards.innerHTML = `<!-- Sample card 1-->
<div class="card" style="margin-bottom: 20px;">
<div class="card-body">
<h3 class="card-title">${idname[index]}</h3>
<p class="card-text">
Get all upcoming events/rounds on ${idname[index]} .
</p>
<!-- Button trigger modal -->
<!-- Button = api call-->
<button id = "btn-${index}" type="button" class="btn btn-primary">See Events</button>
<button style = "display : none" id = "real-${index}" type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalLong-${index}">See Events</button>
<!-- Modal -->
<div class="modal fade" id="exampleModalLong-${index}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">
<div id = "modal-title-${index}"><b>${idname[index]}</b></div></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div id="modal-body-${index}">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- Button trigger modal -->
</div>
</div>
</div>
<!-- Sample card -->`
rowclick.appendChild(cards);
});
}
rowclick.addEventListener('click', whenClickButton);