-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
270 lines (232 loc) · 7.93 KB
/
app.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
// Problem class : represents a particular problem
let i =1;
// let problems;
class Problem{
constructor(no,platform,problem,link,prio){
this.no=no;
this.platform=platform;
this.problem=problem;
this.link=link;
this.prio=prio;
}
}
// UI class : handles ui tasks
class ui{
static displayProblems(){
const ProblemList=Store.getProblem();
const ProblemLists=ProblemList
ProblemLists.forEach((curr)=>ui.addToLists(curr));
}
static addToLists(Ques){
const list=document.querySelector('#problem-list');
const row=document.createElement('tr');
row.innerHTML=`
<td style="color: white;">${Ques.no}</td>
<td style="color: white;">${Ques.platform}</td>
<td ><a href='${Ques.link}' target="_blank" style="color:white;
">${Ques.problem}</a></td>
<td style="color: white;">${Ques.prio}</td>
<td style="color: white;"><a href='#' class="btn btn-danger btn-sm delete">X</a></td>
`;
list.appendChild(row);
}
static clearFields(){
// document.querySelector('#platform').value='';
document.querySelector('#link').value='';
document.querySelector('#prio').value='';
document.querySelector('#problem').value='';
}
static showAlert(message,className){
const div=document.createElement('div');
div.className=`alert alert-${className}`;
div.appendChild(document.createTextNode(message));
const container=document.querySelector('.container');
const form=document.querySelector('#form')
container.insertBefore(div,form);
setTimeout(()=>document.querySelector('.alert').remove(),3000)
}
static delete(ele){
if(ele.classList.contains('delete')){
ele.parentElement.parentElement.remove();
}
}
}
// Store class : handles local Storage
class Store{
static getProblem(){
let problems;
if(localStorage.getItem('problems')===null){
problems=[];
}
else{
problems=JSON.parse(localStorage.getItem('problems'));
}
// console.log(problems);
return problems;
}
static addProblem(problem){
const problems=Store.getProblem();
problems.push(problem);
localStorage.setItem('problems',JSON.stringify(problems));
}
static removeProblem(no){
const problems=Store.getProblem();
problems.forEach((problem,ind)=>{
if(problem.no === no){
problems.splice(ind,1);
}
})
localStorage.setItem('problems',JSON.stringify(problems));
}
}
// Event 1 : Display Problems
document.addEventListener('DOMContentLoaded',ui.displayProblems)
// Event 2 : Add Problem to list of Problems
document.querySelector('#form').addEventListener('submit',(e)=>{
//prevent actual default
e.preventDefault();
//Get values
// const no=parseInt(document.querySelector('#no').value,10);
const no=i++;
const link=document.querySelector('#link').value;
function getPlatform(){
let tmp=link;
if(tmp.search("codeforces")!=-1){
return "codeforces"
}
else if(tmp.search("leetcode")!=-1){
return "leetcode"
}
else if(tmp.search("codechef")!=-1){
return "codechef"
}
}
const platform=getPlatform()
const prio=document.querySelector('#prio').value;
const problem_n=document.querySelector('#problem').value;
if(no==='' || platform==='' || link==='' || problem_n==='' || prio===''){
ui.showAlert('Some inputs are empty','danger')
}
else{
// Instantiate Problem
const problemObj=new Problem(no,platform,problem_n,link,prio);
// console.log(problemObj);
// Add to List
ui.addToLists(problemObj);
ui.showAlert('Problem Added','success')
ui.clearFields();
Store.addProblem(problemObj);
}
})
// Event 3 : Remove Problem from list of Problems
document.querySelector('#problem-list').addEventListener('click',(e)=>{
ui.delete(e.target);
// ui.showAlert('Problem Solved','success')
Store.removeProblem(e.target.parentElement.previousElementSibling.textContent);
ui.showAlert('Problem Solved','success')
});
let constestList;
function openNav() {
document.getElementById("mySidenav").style.width = "100vw";
// Fetch the data from the API
fetch("https://kontests.net/api/v1/codeforces")
.then((response) => response.json())
.then((data) => {
// Create the table header
const tableHeader = "<tr><th>Name</th><th>Start Time</th><th>Duration</th></tr>";
// Create the table body
let tableBody = "";
data.forEach((contest) => {
const name = contest.name;
const url = contest.url;
const startTime = contest.start_time || "-";
const duration = contest.duration || "-";
const status = contest.status;
console.log(typeof(startTime))
const tableRow = `<tr><td style="font-size:2px;"><a href=${url}>${name}</a></td><td>${startTime}</td><td>${duration}</td></tr>`;
tableBody += tableRow;
});
// Create the complete table
const table = `<table>${tableHeader}${tableBody}</table>`;
// Append the table to an element in the HTML document
document.getElementById("table-container-cf").innerHTML = table;
})
.catch((error) => {
console.error("Error:", error);
});
fetch("https://kontests.net/api/v1/leet_code")
.then((response) => response.json())
.then((data) => {
// Create the table header
const tableHeader = "<tr><th>Name</th><th>Start Time</th><th>Duration</th></tr>";
// Create the table body
let tableBody = "";
data.forEach((contest) => {
const name = contest.name;
const url = contest.url;
const startTime = contest.start_time || "-";
const duration = contest.duration || "-";
const status = contest.status;
console.log(typeof(startTime))
const tableRow = `<tr><td style="font-size:2px;"><a href=${url}>${name}</a></td><td>${startTime}</td><td>${duration}</td></tr>`;
tableBody += tableRow;
});
// Create the complete table
const table = `<table>${tableHeader}${tableBody}</table>`;
// Append the table to an element in the HTML document
document.getElementById("table-container-lc").innerHTML = table;
})
.catch((error) => {
console.error("Error:", error);
});
fetch("https://kontests.net/api/v1/code_chef")
.then((response) => response.json())
.then((data) => {
// Create the table header
const tableHeader = "<tr><th>Name</th><th>Start Time</th><th>Duration</th></tr>";
// Create the table body
let tableBody = "";
data.forEach((contest) => {
const name = contest.name;
const url = contest.url;
const startTime = contest.start_time || "-";
const duration = contest.duration || "-";
const status = contest.status;
console.log(typeof(startTime))
document.getElementById("tr").style.color = "blue";
const tableRow = `<tr style="border: 4px; border-color: #4cd137;><td><a href=${url}>${name}</a></td><td>${startTime}</td><td>${duration}</td></tr>`;
tableBody += tableRow;
});
// Create the complete table
const table = `<table>${tableHeader}${tableBody}</table>`;
// Append the table to an element in the HTML document
document.getElementById("table-container-cc").innerHTML = table;
})
.catch((error) => {
console.error("Error:", error);
});
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
}
let dark=false;
function darkMode(){
if(dark==false){
document.body.style.backgroundColor="#706fd3";
dark=true;
}
else{
document.body.style.backgroundColor="#2c2c54";
dark=false
}
}
let doubtBox=false;
function openBot(){
alert("Coming Soon")
// document.getElementById("bot").style.width = "100vw";
// document.createElement("")
}
function closeBot(){
alert("Coming Soon")
// document.getElementById("bot").style.width = "0";
}