-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
475 lines (409 loc) · 13.1 KB
/
script.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
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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
//Swaps High school and Middle school
function hsmsSwap(){
var checked = document.getElementById("hsmsInput").checked
if (document.getElementById("hsmsInput").checked == true){
document.getElementById("gradeLvl").innerHTML = "High School"
document.getElementById("modalClass").innerHTML = "High School"
localStorage.setItem('gradecookie', checked);
document.getElementById("numOfClasses").value = courses.length
for (let itr = 1; itr < courses.length + 1; itr++ ) {
document.getElementById("typeId" + itr).innerHTML = '<p>Type:</p>\
<form>\
<select class="dropmenu" id="cltyp' + itr + '">\
<option value="1">N/A</option>\
<option value="2">Honors</option>\
</select>\
</form>'
}
} else {
document.getElementById("gradeLvl").innerHTML = "Middle School"
document.getElementById("modalClass").innerHTML = "Middle School"
localStorage.setItem('gradecookie', checked);
if (courses != null) {
for (let itr = 1; itr < courses.length + 1; itr++ ) {
document.getElementById("typeId" + itr).innerHTML = null
}
}
}
}
var courses = [];
var classAmountNum = 0;
//create Course class
class Course{
constructor(num){
this.letterGrade = 5;
this.classText = "";
this.classNum = num;
this.classType = "1"
}
}
//create Course function
function createCourse(num){
var tempElementId = "temp".concat("", String(num));
var tempElementIdNext = "temp".concat("", String(num + 1));
var tempElementIdAlsoNext = "temp".concat("", String(num + 2));
//creates html elements in the courses class
document.getElementById(tempElementId).innerHTML= '\
<div id="input-con-div" class="input-container lightModeInput">\
<input id="cl' + num + 'txt" type="text" required=""/>\
<label id="cl' + num + 'label">Class ' + num + '</label>\
</div>\
<span id="typeId' + num + '">\
<p>Type:</p>\
<form>\
<select class="dropmenu" id="cltyp' + num + '">\
<option value="1">N/A</option>\
<option value="2">Honors</option>\
</select>\
</form>\
</span>\
<p>Grade:</p>\
<form>\
<select class="dropmenu SM" id="cl' + num + '">\
<option value="4">A</option>\
<option value="3">B</option>\
<option value="2">C</option>\
<option value="1">D</option>\
<option value="0">F</option>\
<option value="5">N/A</option>\
</select>\
<br><br>\
</form>\
<div class="selectionbox" id="' + tempElementIdNext +'">';
}
function getCookies(){//Called on pageload
//Pulls cookies from localStorage
var color = localStorage.getItem('color');
var shade = localStorage.getItem('shade');
var gradecookie = localStorage.getItem('gradecookie');
var arraycookie = localStorage.getItem('arraycookie');
//sets top header, slider, and dark mode to correct values
if (shade == "dark"){
var element = document.body;
element.classList.toggle("darkModebg");
element.classList.toggle("lightModebg");
var c = document.getElementById("c");
c.classList.toggle("darkMode");
c.classList.toggle("lightMode");
var c2 = document.getElementById("c2");
c2.classList.toggle("darkMode");
c2.classList.toggle("lightMode");
document.getElementById("darkModeButton").innerHTML = 'Light Mode'
}
//Easter Egg
if (color == "red"){
var element = document.body;
element.classList.add("redModebg");
} else if (color == "orange"){
var element = document.body;
element.classList.add("orangeModebg");
} else if (color == "yellow"){
var element = document.body;
element.classList.add("yellowModebg");
} else if (color == "lime"){
var element = document.body;
element.classList.add("limeModebg");
} else if (color == "cyan"){
var element = document.body;
element.classList.add("cyanModebg");
} else if (color == "blue"){
var element = document.body;
element.classList.add("blueModebg");
} else if (color == "purple"){
var element = document.body;
element.classList.add("purpleModebg");
} else if (color == "pink"){
var element = document.body;
element.classList.add("pinkModebg");
} else if (color == "pinkred"){
var element = document.body;
element.classList.add("pinkredModebg");
}
if (gradecookie == "true"){
document.getElementById("hsmsInput").checked = true
checked = true
document.getElementById("gradeLvl").innerHTML = "High School"
document.getElementById("modalClass").innerHTML = "High School"
} else if (gradecookie == "false"){
document.getElementById("hsmsInput").checked = false
checked = false
document.getElementById("gradeLvl").innerHTML = "Middle School"
document.getElementById("modalClass").innerHTML = "Middle School"
} else {
//Modal that pops up on first start
document.getElementById('id01').style.display='block';
hsmsSwap();
}
if (arraycookie == null){//if cookies don't exist
classAmount();
} else {//if cookies do exist
fromCookies(arraycookie);
loadgpa();
}
}
function classAmount(){//if cookies don't exist
//create array
courses = [];
//get textbox with number of classes
classAmountNum = Math.abs(parseInt(document.getElementById("numOfClasses").value));
if (classAmountNum == parseInt(0)){//stops NaN/0/null on numOfClasses textbox
classAmountNum = 7;
} else if (classAmountNum.isNaN == true) {
classAmountNum = 7;
} else if (classAmountNum == null) {
classAmountNum = 7;
} else if (classAmountNum > 256) {
classAmountNum = 7;
}
//creates classes for number of iterations
for (let itr = 0; itr < classAmountNum; itr++ ) {
courses.push(new Course(itr + 1));
createCourse(itr + 1);
}
if (document.getElementById("hsmsInput").checked == false){
for (let itr = 1; itr < courses.length + 1; itr++ ) {
//loops through all course classes and removes the <span id="typeId"></span> (honors dropdown)
document.getElementById("typeId" + itr).innerHTML = null
}
}
//calculates and saves the gpa
loadgpa();
//sets the gpa text to ""
document.getElementById("gpa").innerHTML =
"";
}
function fromCookies(arraycookie){//not to be confused with getCookies()
courses = JSON.parse(arraycookie);
//creates courses from array data after it is pulled from cookies
if (courses != null) {
for (var itr = 0; itr < courses.length; itr++ ) {
createCourse(courses[itr].classNum);
createCookieCourse(courses[itr].classNum, courses[itr].letterGrade, courses[itr].classText, courses[itr].classType, itr);
}
for (let itr = 0; itr < courses.length; itr++) {
tempLGID = "cl".concat("", String(itr + 1));
tempCTID = "cl".concat("", String(itr + 1) + "txt");
tempCTYID = "cltyp" + String(itr + 1);
document.getElementById(tempLGID).value = courses[itr].letterGrade;
document.getElementById(tempCTID).value = courses[itr].classText;
document.getElementById(tempCTYID).value = courses[itr].classType;
}
if (document.getElementById("hsmsInput").checked == false){
for (let itr = 1; itr < courses.length + 1; itr++ ) {
//removes typeId <span> element from courses objects
document.getElementById("typeId" + itr).innerHTML = null
}
}
}
}
function createCookieCourse(classNum, letterGrade, classText, classType, itr){//Populates course object data
let num = classNum;
var tempElementId = "temp".concat("", String(num));
var tempElementIdNext = "temp".concat("", String(num + 1));
document.getElementById(tempElementId).value = classText;
document.getElementById(tempElementIdNext).value = classNum;
}
function help(){
window.location.href='help.html';
}
function loadgpahelp(){
loadgpa()
window.location.href='index.html';
}
function loadgpa(){ //Saves values to the array
if (courses != null) {
//set var
var pregpa = 0;
var courseLen = courses.length;
var tempLGID = "";
var tempCTID = "";
var tempCTYID = "";
//save classes to array
for (let itr = 0; itr < courses.length; itr++ ) {
tempLGID = "cl".concat("", String(itr + 1));
tempCTID = "cl".concat("", String(itr + 1)) + "txt";
tempCTYID = "cltyp".concat("", String(itr + 1));
courses[itr].letterGrade = document.getElementById(tempLGID).value;
courses[itr].classText = document.getElementById(tempCTID).value;
if (document.getElementById("hsmsInput").checked != false){
tempCTYID = "cltyp" + String(itr + 1);
courses[itr].classType = document.getElementById(tempCTYID).value;
}
}
//remove N/A from addition
for (let itr = 0; itr < courses.length; itr++ ) {
if (courses[itr].letterGrade == 5){
var courseLen = courseLen - 1;
} else {
//adds to pregpa
if (courses[itr].classType == "2"){
if (courses[itr].letterGrade == "0"){
var pregpa = pregpa + parseInt(courses[itr].letterGrade);
} else {
var pregpa = pregpa + 1 + parseInt(courses[itr].letterGrade);
}
} else {
var pregpa = pregpa + parseInt(courses[itr].letterGrade);
}
}
}
//divide
gpa = pregpa / courseLen;
//round
var gpa = gpa.toFixed(2);
document.getElementById("gpa").innerHTML =
"Your GPA is a: " + gpa;
//shows save text
document.getElementById("saved").innerHTML =
"Saved!";
setTimeout(saveRemove, 1000);
//save cookies
var arraycookie = JSON.stringify(courses);
localStorage.setItem('arraycookie', arraycookie, 365);
}
//Remove "Saved!" Text
function saveRemove(){
document.getElementById("saved").innerHTML = "";
}
}
//clears class cookie data
function clearData(){
localStorage.setItem('arraycookie', null, -1);
location.reload()
}
//clears all website cookie data
function clearAll(){
localStorage.setItem('arraycookie', null, -1);
localStorage.setItem('gradecookie', null, -1);
localStorage.setItem('color', null, -1);
localStorage.setItem('shade', null, -1);
}
// Side nav bar
function w3_open() {
var x = document.getElementById("mySidebar");
x.style.width = "30%";
x.style.fontSize = "40px";
x.style.paddingTop = "10%";
x.style.display = "block";
}
function w3_close() {
document.getElementById("mySidebar").style.display = "none";
}
//Dark Mode
function darkMode() {
var element = document.body;
element.classList.toggle("darkModebg");
element.classList.toggle("lightModebg");
var c = document.getElementById("c");
c.classList.toggle("darkMode");
c.classList.toggle("lightMode");
var c2 = document.getElementById("c2");
c2.classList.toggle("darkMode");
c2.classList.toggle("lightMode");
if (c.classList.contains("darkMode") == true){
document.getElementById("darkModeButton").innerHTML = 'Light Mode'
localStorage.setItem('shade', "dark", 365);
} else if(element.classList.contains("lightMode") == false) {
document.getElementById("darkModeButton").innerHTML = 'Dark Mode'
localStorage.setItem('shade', "light", 365);
}
}
//Easter Egg
//Context: https://www.google.com/search?q=Konami+Code
function remColors(){
const classes = ["redModebg","orangeModebg","yellowModebg","limeModebg","cyanModebg","blueModebg","purpleModebg","pinkModebg","pinkredModebg"];
classes.forEach(c => {
var element = document.body;
if (element.classList.contains(c)) {
element.classList.remove(c);
}
var element = document.getElementById("c");
if (element.classList.contains(c)) {
element.classList.remove(c);
}
var element = document.getElementById("c2");
if (element.classList.contains(c)) {
element.classList.remove(c);
}
})
};
var keys = "";
window.onkeydown = function (e) {
var code = e.keyCode ? e.keyCode : e.which;
if (code === 38) { //up key
keys += "1"
} else if (code === 40) { //down key
keys += "2"
} else if (code === 37) { //left key
keys += "3"
} else if (code === 39) { //right key
keys += "4"
} else if (code === 66) { //B key
keys += "5"
} else if (code === 65) { //A key
keys += "6"
} else if (code === 13) { //Start (enter) key
keys += "7"
};
if (keys == "11223434567"){//sequence
console.log(keys)
alert("You Found It!");
document.getElementById('id02').style.display='block';
remColors()
};
};
//Button Theme Changing Functions
function rTH() {
remColors()
var element = document.body;
element.classList.add("redModebg");
localStorage.setItem('color', "red", 365);
}
function oTH() {
remColors()
var element = document.body;
element.classList.add("orangeModebg");
localStorage.setItem('color', "orange", 365);
}
function yTH() {
remColors()
var element = document.body;
element.classList.add("yellowModebg");
localStorage.setItem('color', "yellow", 365);
}
function lTH() {
remColors()
var element = document.body;
element.classList.add("limeModebg");
localStorage.setItem('color', "lime", 365);
}
function cTH() {
remColors()
var element = document.body;
element.classList.add("cyanModebg");
localStorage.setItem('color', "cyan", 365);
}
function bTH() {
remColors()
var element = document.body;
element.classList.add("blueModebg");
localStorage.setItem('color', "blue", 365);
}
function pTH() {
remColors()
var element = document.body;
element.classList.add("purpleModebg");
localStorage.setItem('color', "purple", 365);
}
function piTH() {
remColors()
var element = document.body;
element.classList.add("pinkModebg");
localStorage.setItem('color', "pink", 365);
}
function prTH() {
remColors()
var element = document.body;
element.classList.add("pinkredModebg");
localStorage.setItem('color', "pinkred", 365);
}