-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdisplay.js
More file actions
191 lines (161 loc) · 5.26 KB
/
display.js
File metadata and controls
191 lines (161 loc) · 5.26 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
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
const COLORS = [
'#7B71DC',
'#CF6679',
'#2DAE6D',
'#F2853C',
'#5597DF',
'#9D81B5',
'#2B9DD3',
'#F06D65',
'#7E7E7E'
];
window.onload = () => {
const ttList = document.getElementById('tts');
const colorMap = new Map();
const addTT = (tt, index) => {
const singleTT = [
[{}, {}, {}, {}, {}, {}],
[{}, {}, {}, {}, {}, {}],
[{}, {}, {}, {}, {}, {}],
[{}, {}, {}, {}, {}, {}],
[{}, {}, {}, {}, {}, {}],
[{}, {}, {}, {}, {}, {}],
[{}, {}, {}, {}, {}, {}],
[{}, {}, {}, {}, {}, {}],
[{}, {}, {}, {}, {}, {}],
[{}, {}, {}, {}, {}, {}],
[{}, {}, {}, {}, {}, {}]
];
tt.forEach((course) => {
if (!colorMap.has(course.courseId)) {
colorMap.set(course.courseId, COLORS[colorMap.size]);
}
course.days.forEach((day, i) => {
day.forEach((hour) => {
singleTT[+hour][i] = {
id: course.courseId,
name: course.courseTitle,
lec: course.lecType + course.section,
prof: course.instructor
};
});
});
});
const div1 = document.createElement('div');
div1.className = 'w-11/12 mx-auto';
const div2 = document.createElement('div');
div2.className = 'flex flex-col mt-5';
div1.appendChild(div2);
const div3 = document.createElement('div');
div3.className = '-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8';
div2.appendChild(div3);
const div4 = document.createElement('div');
div4.className = 'py-2 align-middle inline-block min-w-full sm:px-6 lg:px-8';
div3.appendChild(div4);
const div5 = document.createElement('div');
div5.className = 'shadow overflow-hidden';
div4.appendChild(div5);
const pn = document.createElement('p');
pn.textContent = '#' + index;
pn.className = 'text-white text-center text-3xl';
div5.appendChild(pn);
const table = document.createElement('table');
table.className = 'min-w-full';
div5.appendChild(table);
const thead = document.createElement('thead');
thead.className = 'bg-gray-200 text-center';
table.appendChild(thead);
const tr1 = document.createElement('tr');
tr1.className = 'border border-tt-bdr border-opacity-10';
tr1.style.borderWidth = 0.5;
table.appendChild(tr1);
const th1 = document.createElement('th');
th1.className = 'px-2 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider';
tr1.appendChild(th1);
['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'].forEach((day) => {
const th = document.createElement('th');
th.scope = 'col';
th.className = 'w-1/6 py-3 text-xs font-medium text-white uppercase tracking-wider';
th.style.maxWidth = '30px';
th.textContent = day;
tr1.appendChild(th);
});
const tbody = document.createElement('tbody');
tbody.className = 'bg-tt-cellbg text-center';
table.appendChild(tbody);
for (let i = 0; i < singleTT.length; i++) {
const tr = document.createElement('tr');
tbody.appendChild(tr);
const td1 = document.createElement('td');
td1.className = 'px-2 py-4 border border-tt-bdr border-opacity-10 whitespace-nowrap';
td1.style.borderWidth = 0.5;
tr.appendChild(td1);
const timeDiv = document.createElement('div');
timeDiv.className = 'text-xs text-white';
timeDiv.textContent = i + 8 + ':00 - ' + (i + 9) + ': 00';
td1.appendChild(timeDiv);
singleTT[i].forEach((cell) => {
const td = document.createElement('td');
td.className =
'w-1/12 whitespace-nowrap border border-tt-bdr border-opacity-10 font-bold';
td.style.borderWidth = 0.5;
tr.appendChild(td);
const innerDiv = document.createElement('div');
innerDiv.className = 'text-xs text-white py-2';
innerDiv.style.fontSize = '10px';
if (cell.name) {
innerDiv.style.background = colorMap.get(cell.id);
let p1;
p1 = document.createElement('p');
p1.textContent = cell.id;
p1.style.fontSize = '12px';
innerDiv.appendChild(p1);
p1 = document.createElement('p');
p1.textContent = cell.name;
p1.className = 'w-32 overflow-ellipsis overflow-hidden mx-auto';
innerDiv.appendChild(p1);
p1 = document.createElement('p');
p1.textContent = cell.lec;
innerDiv.appendChild(p1);
p1 = document.createElement('p');
p1.textContent = cell.prof;
p1.className = 'w-32 overflow-ellipsis overflow-hidden mx-auto';
innerDiv.appendChild(p1);
} else {
innerDiv.textContent = '';
}
td.appendChild(innerDiv);
});
}
ttList.appendChild(div1);
};
const noTT = () => {
const p = document.createElement('p');
p.className = 'text-white text-3xl text-center w-full mt-64';
p.textContent = 'No Possible Timetables!';
ttList.appendChild(p);
};
chrome.storage.sync.get('selectedCourses', (e) => {
if (e.selectedCourses) {
const finalList = e.selectedCourses
.filter((course) => course.status)
.map((course) => ({
course: course.name.split(' : ')[0],
section: course.sections
}));
if (finalList.length === 0) noTT();
else
fetch('http://68.183.45.22:1337/api/tt/generatett', {
method: 'POST',
body: JSON.stringify({ courseIdArr: finalList }),
headers: { 'Content-type': 'application/json; charset=UTF-8' }
})
.then((response) => response.json())
.then((data) => {
if (data.totalTTs === 0) noTT();
else data.list.map((tt, index) => addTT(tt, index + 1));
})
.catch((err) => console.log(err));
}
});
};