-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.js
More file actions
257 lines (231 loc) · 9.03 KB
/
Copy pathapp.js
File metadata and controls
257 lines (231 loc) · 9.03 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
//Welcome to Time Table B2 Project
import {
showVideos,
do24HourFormat,
timeTableObj,
meetLinks,
timings,
} from "./config/config.js";
//foo is for functions which are returning some values
//DOMfoo is for DOM Manipulation functions
import foo from "./js/functions.js";
import DOMfoo from "./js/DOMFunctions.js";
import eventFoo from "./js/eventListenerFunctions.js";
//Async funtions to get api data
//Get meetlink data
// async function getMeetLinksData() {
// const response = await fetch(apiLinks["links"]);
// let data = await response.json();
// return data;
// }
//Get timings data
// async function getTimingsData() {
// const response = await fetch(apiLinks["timings"]);
// let data = await response.json();
// return data.timings;
// }
//Get TT data
// async function getTTData() {
// const response = await fetch(apiLinks["tt"]);
// let data = await response.json();
// return data;
// }
//Declaring variable for meetlinks,timing,tt
// let meetLinks;
// let timings;
// let timeTableObj;
// (async ()=>{
// meetLinks = await getMeetLinksData();
// timings = await getTimingsData();
// timeTableObj = await getTTData();
// // console.log(meetLinks)
// // console.log(timings)
// // console.log(timeTableObj)
// })();
//authuser value used in the meetlink
let authuser = '';
// TODO: save the value of authuser to cookies
//Todays Classes
let todayClasses;
// variable for current week day number
let weekDayNumber = foo.getWeekDayOnlyNumber();
//Funtion to Display/Render timetable to the HTML
function timeTableDisplay(weekDay) {
// if (
// meetLinks == undefined ||
// timings == undefined ||
// timeTableObj == undefined
// ) {
// DOMfoo.addProgressBar();
// meetLinks = await getMeetLinksData();
// timings = await getTimingsData();
// timeTableObj = await getTTData();
// DOMfoo.removeProgressBar();
// }
DOMfoo.DOMReset(logo);
weekDay = foo.weekDayConverter(weekDay);
DOMfoo.weekDayDOM(weekDay);
todayClasses = timeTableObj[weekDay];
for (let lectureNumber in todayClasses) {
// Select a mainDivBody element which is 'div.lectures'
let mainDivBody = document.querySelector("div.lectures");
// Span Tag for timings Details Display
let spanTag = DOMfoo.spanTag(timings[lectureNumber], do24HourFormat);
//When there is multiple classes in one given time period
if (todayClasses[lectureNumber].includes(" or ")) {
// Creating basePTag for Multiple Class using by appending spanTag of timeing and lecture Number
let basePTagOfMultipleClass = DOMfoo.basePTagOfMultipleClass(
spanTag,
lectureNumber,
timings
);
// Creating Array of Class in the same time period which are spearated by 'or'
let theClasses = todayClasses[lectureNumber].split(" or ");
// Mapping each class with its anchor Tag using Class name, meetlink, authuser
let aTags = theClasses.map((theClass) =>
DOMfoo.aTagDOM(theClass, meetLinks[theClass], authuser)
);
// appendig anchor tag to basePTag
aTags.forEach((aTag) => {
basePTagOfMultipleClass.append(aTag);
basePTagOfMultipleClass.append(" OR ");
});
// removing last child which is OR
basePTagOfMultipleClass.removeChild(
basePTagOfMultipleClass.lastChild
);
// appending basePTag to the main Div Body
mainDivBody.appendChild(basePTagOfMultipleClass);
}
//When there is only one class in the given time period
else {
// Gets the Class name
let theClass = todayClasses[lectureNumber];
// Creating Anchor Tag of the Class using Class name, meetlink, authuser
let aTag;
//if there is no class
if (theClass == "No Class") {
aTag = DOMfoo.aTagDOM(theClass, meetLinks[theClass], "");
} else {
aTag = DOMfoo.aTagDOM(theClass, meetLinks[theClass], authuser);
}
// Creating basePTag in which appending spanTag, Lecture Number, aTag
let basePTag = DOMfoo.basePTag(
aTag,
spanTag,
lectureNumber,
timings
);
// appending basePTag to the main Div Body
mainDivBody.appendChild(basePTag);
}
}
// TO show videos on the webpage or not, you can set the value in the config/config.js file
if (showVideos) {
DOMfoo.setVideo();
} else {
DOMfoo.videoHide();
}
}
// Displayes/Render the TimeTable accoring to given week day, here it is current week day
timeTableDisplay(weekDayNumber);
// selecting all authuser 'li' tag
let allAuthuser = document.querySelectorAll("footer ul.authuser li");
// adding event listener to each 'li' tag
allAuthuser.forEach((authUserElement) => {
authUserElement.addEventListener("click", (e) => {
// updating the value of authuser
authuser = parseInt(authUserElement.textContent);
// Displaying the Timetable with updated value of authuser
timeTableDisplay(foo.getWeekDayOnlyNumber());
});
});
// selecting left,right arrow and 'div#weekDay'
let prevButton = document.querySelector("button.left");
let nextButton = document.querySelector("button.right");
let resetDivButton = document.querySelector("header");
//Adding event listener to prevButton (left arrow),
//Decrement the value of weekDayNumber and facilitates the navigation of timetable between days
eventFoo.elementAndKeycodeEventBind(prevButton, "ArrowLeft", () => {
weekDayNumber--;
timeTableDisplay(weekDayNumber);
});
//Adding event listener to nextButton (right arrow)
//Increment the value of weekDayNumber and facilitates the navigation of timetable between days
eventFoo.elementAndKeycodeEventBind(nextButton, "ArrowRight", () => {
weekDayNumber++;
timeTableDisplay(weekDayNumber);
});
//Adding event listener to 'div#weekDay' (div where logo is situated)
eventFoo.elementAndKeycodeEventBind(resetDivButton, "ArrowUp", () => {
weekDayNumber = foo.getWeekDayOnlyNumber();
timeTableDisplay(foo.getWeekDayOnlyNumber());
});
//Adding Event Listener to directly join the meet or open links, And set authuser
document.addEventListener("keyup", (e) => {
if (e.code.includes("Digit") || e.code.includes("Numpad")) {
var keyNum = e.code.slice(-1);
var isNumPad = e.code.includes("Numpad") ? true : false;
} else {
return;
}
if (isNumPad) {
authuser = keyNum;
timeTableDisplay(foo.getWeekDayOnlyNumber());
} else {
let theClass = todayClasses[keyNum];
// open link only for while meetLinks exis.
if (theClass && meetLinks[theClass] != "#") {
window.open(`${meetLinks[theClass]}${authuser}`, "_blank");
}
}
});
//Join Current Class using Space Bar
document.addEventListener("keyup", (e) => {
if (e.code == "Space" && !e.ctrlKey) {
let currentClassNumber = foo.currentClassNumber(timings);
let theClass =
currentClassNumber != -1
? todayClasses[currentClassNumber]
: "NULL";
let link = meetLinks[theClass] ?? '#';
if (link != "#" && !theClass.includes("or")) {
window.open(`${link}${authuser}`, "_blank");
}
}
});
//Navigate Through Current Class/Lecture/Period which are/have 'OR'
let orClassCounter = 0;
let aTags;
let orJoinLink = "#";
document.addEventListener("keyup", (e) => {
if (e.ctrlKey && e.code == "Space") {
let currentClassNumber = foo.currentClassNumber(timings);
let theClass =
currentClassNumber != -1
? todayClasses[currentClassNumber]
: "NULL";
if (theClass.includes("or")) {
let totalClassesInCurrentPeriod = theClass.split(" or ").length;
let iterateValue = orClassCounter % totalClassesInCurrentPeriod;
let iterateValuePlusOne =
(orClassCounter + 1) % totalClassesInCurrentPeriod;
aTags = document.querySelectorAll("p.lecItemSplit a");
aTags[iterateValue].style = "border:1px solid #fff !important;";
orJoinLink = aTags[iterateValue].href ?? "#";
aTags[iterateValuePlusOne].style = "";
orClassCounter++;
}
}
if (e.code == "ControlLeft" && aTags != null) {
aTags.forEach((element) => {
element.style = "";
});
}
if (e.code == "ControlLeft" && orJoinLink != "#") {
orClassCounter = 0;
aTags = null;
window.open(orJoinLink, "_blank");
orJoinLink = "#";
}
});