-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathcontent.js
More file actions
385 lines (354 loc) · 12 KB
/
content.js
File metadata and controls
385 lines (354 loc) · 12 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
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
function getPersonalData(){
let dp=document.getElementsByClassName('pull-left image')[0].getElementsByTagName('img')[0].src;
let name=document.getElementsByClassName('pull-left info')[0].getElementsByTagName('p')[0].innerHTML.trim();
let str=document.getElementsByClassName('content-header')[0]
.getElementsByClassName('breadcrumb')[0]
.getElementsByTagName('li')[1].innerText;
// let d=document.getElementsByClassName('col-lg-12');
// let roll_no;
// let programme;
// let dept;
// let appliedCredits;
// for(let i=1;i<d.length;i++){
// if(d[i].getElementsByTagName('div')[0].previousElementSibling.innerText==="Applied Credits :"){
// appliedCredits=d[i].getElementsByTagName('div')[0].innerText;
// }
// else if(d[i].getElementsByTagName('div')[0].previousElementSibling.innerText==="Roll No. :"){
// roll_no=d[i].getElementsByTagName('div')[0].innerText;
// }
// else if(d[i].getElementsByTagName('div')[0].previousElementSibling.innerText==="Programme :"){
// programme=d[i].getElementsByTagName('div')[0].innerText;
// }
// else if(d[i].getElementsByTagName('div')[0].previousElementSibling.innerText==="Department :"){
// dept=d[i].getElementsByTagName('div')[0].innerText;
// }
// }
let roll_no=document.getElementsByClassName('row col-lg-12 form-group')[0].getElementsByClassName('col-sm-4 col-lg-8 col-xs-4 col-md-4')[0].innerText;
let programme=document.getElementsByClassName('row col-lg-12 form-group')[1].getElementsByClassName('col-sm-4 col-lg-8 col-xs-4 col-md-4')[0].innerText;
let dept=document.getElementsByClassName('row col-lg-12 form-group')[1].getElementsByClassName('col-sm-4 col-lg-8 col-xs-4 col-md-4')[1].innerText;
let appliedCredits=document.getElementsByClassName('row col-lg-12 form-group')[2].getElementsByClassName('col-sm-4 col-lg-8 col-xs-4 col-md-4')[0].innerText;
let sem="";
for(let i=0;i<str.length;i++){
if((str[i]>='0'&&str[i]<='9')||str[i]==='/') sem+=str[i];
}
sem=sem.slice(0,4) +'-'+sem.slice(4);
return {dp:dp,name:name,roll_no:roll_no,programme:programme,dept:dept,appliedCredits:appliedCredits,sem:sem};
}
chrome.runtime.onMessage.addListener(async function(request, sender, sendResponse) {
if (request.action === 'GetTT') {
// check the page
// if the "headerText" of the page is "Student Add & Drop Application" then put the value of the var t = 1;
// if the "headerText" of the page is " Form Status" then put the value of the var t = 2
const bodyContent = document.body.innerHTML;
const parser = new DOMParser();
const doc = parser.parseFromString(bodyContent, 'text/html');
let timetable = {}
let personal_data = {}
if(!CheckSite(doc)){
sendResponse({timetable: timetable, personal_data: personal_data});
return
}
var headerText = doc.getElementById("headerText");
var t;
if (headerText === "Student Add & Drop Application") {
t = 1;
} else if (headerText === "Form Status") {
t = 2;
} else {
t = 0;
}
if(t === 1 || t === 0){
personal_data = getPersonalData();
const datatable1 = doc.getElementById("datatable1");
if (datatable1) {
const content = datatable1.getElementsByTagName("tbody");
const rows = content[0].getElementsByTagName("tr");
// console.log(rows.length)
for (let j = 0; j < rows.length; j++) {
const x = rows[j].getElementsByTagName("td");
let lectureData = [];
let tutorialData = [];
let practicalData = [];
const inputString = x[8].innerText;
const parts = inputString.split(',');
const lhc=parseLHC(inputString)
for (const part of parts) {
// console.log(part)
if (part.includes('Lec')) {
const data = parseTimeAndDays(part,'Lec');
if (data) {
lectureData.push(data)
}
}
else if (part.includes('Tut')) {
const data = parseTimeAndDays(part,'Tut');
// console.log(data)
if (data) {
tutorialData.push(data);
}
}
else if (part.includes('Prc')) {
const data = parseTimeAndDays(part,'Prc');
if (data) {
practicalData.push(data);
}
}
}
if (lectureData.length > 0) {
for (const day0 of lectureData[0].days) {
let day=Day(day0)
if (!timetable.hasOwnProperty(day)) {
timetable[day] = [];
}
if(!(lectureData[0].start==="00:00"||lectureData[0].end==="00:00")){
timetable[day].push({
time: lectureData[0].start,
time_end: lectureData[0].end,
title: "Lec-"+removeExtas(x[1].innerText),
lectureHall: lhc
});
}
}
}
if (tutorialData.length > 0) {
for (const day0 of tutorialData[0].days) {
let day=Day(day0)
if (!timetable.hasOwnProperty(day)) {
timetable[day] = [];
}
if(!(tutorialData[0].start==="00:00"||tutorialData[0].end==="00:00")){
timetable[day].push({
time: tutorialData[0].start,
time_end: tutorialData[0].end,
title: "Tut-"+removeExtas(x[1].innerText),
lectureHall: ''
});
}
}
}
if (practicalData.length > 0) {
for (const day0 of practicalData[0].days) {
let day=Day(day0)
if (!timetable.hasOwnProperty(day)) {
timetable[day] = [];
}
if(!(practicalData[0].start==="00:00"||practicalData[0].end==="00:00")){
timetable[day].push({
time: practicalData[0].start,
time_end: practicalData[0].end,
title: "Prc-"+removeExtas(x[1].innerText),
lectureHall: ''
});
}
}
}
}
const days=['Monday','Tuesday','Wednesday','Thursday','Friday']
for(const day in days){
timetable[days[day]].sort(compareTime);
}
}
sendResponse({ timetable: timetable, personal_data: personal_data });
}
if(t === 2 || t === 0){
const content = doc.getElementsByClassName("fc-event-container")
let d = -1;
for(let i=0; i<content.length; i++){
const x = content[i].getElementsByClassName("fc-content")
if(!(x.length)){
d++;
}
for(let j=0; j<x.length; j++){
const time1 = x[j].getElementsByClassName("fc-time")
const title1 = x[j].getElementsByClassName("fc-title")
let time = null
let time_start = null;
let time_end = null;
let title = null;
Array.from(time1).forEach((element) => {
time = element.getAttribute("data-full")
for(let k=0; k<time.length; k++){
if(time[k] === '-'){
time_start = time.slice(0,k-1)
time_end = time.slice(k+2)
}
}
});
Array.from(title1).forEach((element) => {
title = element.innerText
});
let day = Day(d);
if (!timetable.hasOwnProperty(day)) {
timetable[day] = [];
}
timetable[day].push({ time: time_start, time_end: time_end, title: title , lectureHall : '' })
}
}
sendResponse({timetable: timetable, personal_data: personal_data});
}
}
if(request.action === 'LHC'){
const bodyContent = document.body.innerHTML;
const parser = new DOMParser();
const doc = parser.parseFromString(bodyContent, 'text/html');
chrome.runtime.sendMessage({action: 'alert', alert_type: CheckSite_1(doc)});
if(CheckSite_1(doc) !== '3'){
return
}
let data
search(request.courses, 10).then(LHC => {
console.log(LHC)
chrome.runtime.sendMessage({ action: 'LHCData', data: LHC });
})
.catch(error => {
console.error(error);
});
}
});
async function search(queries, delay) {
let LHC = {}
const parent = document.getElementById('datatable_filter');
const input = parent.querySelector('.form-control');
for (const query of queries) {
console.log(query);
input.value = '(' + query + ')';
const inputEvent = new Event('input', { bubbles: true });
input.dispatchEvent(inputEvent);
const changeEvent = new Event('change', { bubbles: true });
input.dispatchEvent(changeEvent);
await new Promise(resolve => setTimeout(resolve, delay));
const table = document.getElementById('datatable');
const tbody = table.tBodies[0]
const firstRow = tbody.rows[0];
const firstCell = firstRow.cells[9];
const innerText = firstCell.innerText;
LHC[query] = innerText
console.log(innerText);
}
return LHC
}
// function CheckSite_1(doc){
// const header = doc.getElementById('headerText')
// if(header == null){
// return '1'
// }
// if(header.innerText != ' Check Timetable'){
// return '1'
// }
// const show = doc.getElementById('showTimeTableBtn')
// if (showTimeTableBtn.getAttribute('disabled') !== null) {
// return '2'
// }
// if(showTimeTableBtn.getAttribute('disabled') == null){
// const table = document.getElementById('datatable');
// const tbody = table.tBodies[0]
// if(tbody.innerText === 'No data available in table'){
// InvalidSite_1(2)
// return '2'
// }
// }
// return '3'
// }
function CheckSite(doc){
const header = doc.getElementById('headerText')
if(header === null){
return false
}
if(!header.innerText.includes('Status')){
return false
}
return true
}
function Day(d){
if(d == 0){
return "Monday"
}
if(d == 1){
return "Tuesday"
}
if(d == 2){
return "Wednesday"
}
if(d == 3){
return "Thursday"
}
if(d == 4){
return "Friday"
}
}
function parseTimeAndDays(input, classType) {
let idx = input.indexOf(classType);
idx += 5;
let dayString = '';
let startTime = '';
let endTime = '';
while (input[idx] >= 'A' && input[idx] <= 'Z' || input[idx] >= 'a' && input[idx] <= 'z') {
dayString += input[idx];
idx++;
}
idx++;
for (let i = 0; i < 5; i++) {
startTime += input[idx];
idx++;
}
idx++;
for (let i = 0; i < 5; i++) {
endTime += input[idx];
idx++;
}
let days = [];
if (dayString.includes('F')) days.push(4);
if (dayString.includes('W')) days.push(2);
if (dayString.includes('M')) days.push(0);
//if there is a T
idx = dayString.indexOf('T');
let count = 0;
//Then check the number of T's
//if there are 2 T's then
// There are Two T's
for (let i = 0; i < dayString.length; i++) {
if (dayString[i] === 'T') count++;
}
// If there is only One T
// We have to check for that
if (count == 1){
idx = dayString.indexOf('T');
if (idx == dayString.length - 1) days.push(1);
else if (dayString[idx + 1] == 'h') {
days.push(3);
}
} else if (count == 2) {
days.push(1);
days.push(3);
}
return { days: days, start: startTime, end: endTime };
}
function removeExtas(s){
let out='';
for(let i =0;i<s.length;i++){
if(s[i]>='A'&&s[i]<='Z'||s[i]>='a'&&s[i]<='Z'||s[i]>='0'&&s[i]<='9') out+=s[i]
}
return out
}
function parseLHC(input){
let idx=input.indexOf('(')
let lhc=''
if(idx==-1) return lhc;
idx++;
while(input[idx]!=')'){
lhc+=input[idx]
idx++
}
return lhc
}
function compareTime(a, b) {
const timeA = a.time;
const timeB = b.time;
if (timeA < timeB) {
return -1;
}
if (timeA > timeB) {
return 1;
}
return 0;
}