-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
548 lines (546 loc) · 25.2 KB
/
index.html
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
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
<!DOCTYPE html>
<html>
<head>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-31NT2N8W7L"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-31NT2N8W7L');
</script>
<title>Nutrition Calculator</title>
<style>
body {
background-color: rgb(228, 210, 255);
}
#step1 {
color: black;
font-size: 40px;
}
.position {
text-align: center;
position: relative;
top: 3in;
}
.visual {
font-size: 25px;
border-color: rgb(255, 131, 131);
border-width: 5px;
color: rgb(0, 0, 0);
background-color: rgb(255, 131, 131);
}
.finalize {
font-size: 20px;
border-color: rgb(255, 131, 131);
border-width: 5px;
color: rgb(0, 0, 0);
background-color: rgb(255, 131, 131);
}
.space {
text-align: center;
position: relative;
top: 3.2in;
}
#area0 {
border: solid 4px rgb(0, 128, 255);
bottom: 1.8in;
width: 450px;
height: 910px;
position: relative;
padding: 20px;
background-color: rgb(172, 236, 255);
color: rgb(0, 0, 0);
font-size: 20px;
visibility: hidden;
}
#area1 {
border: solid 4px rgb(0, 128, 255);
top: 0.08in;
width: 450px;
height: 910px;
left: 10.5in;
position: absolute;
padding: 20px;
background-color: rgb(172, 236, 255);
color: rgb(0, 0, 0);
font-size: 20px;
visibility: hidden;
}
#area2 {
border: solid 4px rgb(0, 128, 255);
top: 0.08in;
width: 580px;
height: 910px;
left: 4in;
position: absolute;
padding: 20px;
background-color: rgb(172, 236, 255);
color: rgb(0, 0, 0);
font-size: 20px;
visibility: hidden;
}
#creation {
top: 0.3in;
left: 14.2in;
bottom: 8in;
position: absolute;
text-align: center;
}
#rise {
top: 9.35in;
left: 15.2in;
bottom: 8in;
position: absolute;
text-align: center;
visibility: hidden;
}
#fall {
top: 9.35in;
left: 10.7in;
bottom: 8in;
position: absolute;
text-align: center;
visibility: hidden;
}
#cent {
top: 9.35in;
left: 13.4in;
bottom: 8in;
position: absolute;
text-align: center;
font-size: 20px;
visibility: hidden;
}
#previous {
top: 0.3in;
left: 10.7in;
bottom: 8in;
position: absolute;
text-align: center;
visibility: hidden;
}
.section {
position: relative;
left: 50%;
}
.title {
text-align: center;
}
.support {
float: right;
}
#scribble {
visibility: hidden;
}
#countup {
visibility: hidden;
}
.rating {
float: right;
}
#foodname {
display: block;
margin: auto;
}
#foodresult {
text-align: center;
}
#continue {
visibility: hidden;
}
#refresh {
top: 0.3in;
left: 0.3in;
position: absolute;
text-align: center;
font-size: 20px;
visibility: hidden;
}
</style>
<script>
var foodname = [];
var shift = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
var fixer = 0;
var boxnum = 0;
var data = [];
var mass = [];
var centipede = 0;
var nutrient = ["Calorie: ", "Carbohydrates: ", "Added Sugars: ", "Protein: ", "Fat: ", "Calcium: ", "Magnesium: ", "Phosphorous: ", "Potassium: ", "Fluoride: ",
"Zinc: ", "Choline: ", "Iron: ", "Manganese: ", "Sodium: ", "Vitamin C: ", "Vitamin B1 [Thiamin]: ", "Vitamin B2 [Riboflavin]: ", "Vitamin B3 [Niacin]: ",
"Vitamin B5 [Pantothenic Acid]: ", "Vitamin B6 [Pyridoxine]: ", "Vitamin E: ", "Vitamin A: ", "Vitamin D: ", "Vitamin K: ", "Vitamin B7 [Biotin]: ",
"Vitamin B9 [Folate]: ", "Vitamin B12 [Cobalamin]: ", "Chromium: ", "Copper: ", "Iodine: ", "Molybdenum: ", "Selenium: ", "Chloride: ",
"Sulfur: "];
window.onload = function preserve() {
if (localStorage.superboxnum) {
localStorage.superboxnum = 0;
window.boxnum = 1;
window.fixer = 1;
document.getElementById("enter").onclick = retain();
} else {
localStorage.setItem("superboxnum", -1);
}
}
function retain() {
document.getElementById("page1").style.visibility = "hidden";
document.getElementById("area0").style.visibility = "visible";
var waste = [];
for (let q = 0; q < 35; q++) {
var name = document.createElement("label");
var space = document.createElement("br");
var final = document.createElement("span");
name.for = "require0" + q;
name.innerHTML = nutrient[q];
name.id = "topic0" + q;
final.id = "claim0" + q;
space.id = "lead0" + q;
final.innerHTML = localStorage.getItem("detail0" + q);
document.getElementById("item0").appendChild(name);
document.getElementById("item0").appendChild(final);
document.getElementById("item0").appendChild(space);
waste.push(localStorage.getItem("detail0" + q));
}
data.push(waste);
document.getElementById("scribble").style.visibility = "visible";
document.getElementById("preserve0").style.visibility = "hidden";
document.getElementById("area2").style.visibility = "visible";
document.getElementById("refresh").style.visibility = "visible";
progressboard();
}
function create() {
document.getElementById("page1").style.visibility = "hidden";
document.getElementById("area0").style.visibility = "visible";
for (let n = 0; n < 35; n++) {
var name = document.createElement("label");
var space = document.createElement("br");
var slot = document.createElement("input");
var final = document.createElement("span");
var signal = "#require" + boxnum + n + ":hover + #topic" + boxnum + n + " {background-color: yellow;}";
var mood = document.createElement("style");
mood.innerText = signal;
slot.type = "text";
slot.id = "require" + boxnum + n;
slot.className = "support";
name.for = "require" + boxnum + n;
name.innerHTML = nutrient[n];
name.id = "topic" + boxnum + n;
final.id = "claim" + boxnum + n;
space.id = "lead" + boxnum + n;
document.getElementById("item" + boxnum).appendChild(slot);
document.getElementById("item" + boxnum).appendChild(name);
document.getElementById("item" + boxnum).appendChild(final);
document.getElementById("item" + boxnum).appendChild(space);
document.head.appendChild(mood);
}
if (boxnum > 0) {
document.getElementById("preserve1").style.visibility = "visible";
document.getElementById("area1").style.visibility = "visible";
}
}
function record() {
var stop = "";
var fill = [];
for (let t = 0; t < 35; t++) {
var check = document.getElementById("require" + boxnum + t).value;
if (check == "---") {
check = check;
} else {
check = Number(check);
}
if (check == "---") {
document.getElementById("require" + boxnum + t).style.backgroundColor = "white";
} else if (isNaN(check) === true || check < 0) {
stop = "true";
document.getElementById("require" + boxnum + t).style.backgroundColor = "red"
} else {
document.getElementById("require" + boxnum + t).style.backgroundColor = "white";
}
}
if (stop === "true" && check !== "---") {
alert("Error: Please choose a positive number, no letters, and fill all empty spaces");
return;
}
for (let n = 0; n < 35; n++) {
var steal = Number(document.getElementById("require" + boxnum + n).value);
fill.push(steal);
localStorage.setItem("detail" + boxnum + n, steal);
if (steal !== "---") {
if (n > 21) {
document.getElementById("claim" + boxnum + n).innerHTML = steal + "mcg";
} else if (n > 4) {
document.getElementById("claim" + boxnum + n).innerHTML = steal + "mg";
} else if (n > 0) {
document.getElementById("claim" + boxnum + n).innerHTML = steal + "g";
} else {
document.getElementById("claim" + boxnum + n).innerHTML = steal; //get rid of "g" after you are done with Gala Apple Video
}
} else {
document.getElementById("claim" + boxnum + n).innerHTML = steal;
}
document.getElementById("require" + boxnum + n).remove();
}
data.push(fill);
if (localStorage.superboxnum < boxnum) {
localStorage.superboxnum = Number(localStorage.superboxnum) + 1;
}
window.boxnum = window.boxnum + 1;
window.fixer = window.boxnum;
document.getElementById("preserve0").style.visibility = "hidden";
document.getElementById("preserve1").style.visibility = "hidden";
document.getElementById("scribble").style.visibility = "visible";
if (boxnum > 1) {
document.getElementById("rise").style.visibility = "visible";
document.getElementById("fall").style.visibility = "visible";
document.getElementById("cent").style.visibility = "visible";
var reaper = document.getElementById("foodname").value;
foodname.push(reaper);
document.getElementById("foodname").style.visibility = "hidden";
document.getElementById("foodresult").innerText = reaper;
document.getElementById("foodresult").style.visibility = "visible";
}
if (boxnum > 2) {
document.getElementById("countdown").style.visibility = "visible";
}
document.getElementById("area2").style.visibility = "visible";
}
function reset() {
window.boxnum = window.fixer;
document.getElementById("countdown").style.visibility = "hidden";
document.getElementById("scribble").style.visibility = "hidden";
document.getElementById("foodname").style.visibility = "visible";
document.getElementById("foodname").value = "";
document.getElementById("foodresult").style.visibility = "hidden";
document.getElementById("rise").style.visibility = "hidden";
document.getElementById("fall").style.visibility = "hidden";
document.getElementById("cent").style.visibility = "hidden";
if (boxnum > 1) {
document.getElementById("item" + (boxnum - 1)).id = "item" + boxnum;
for (let d = 0; d < 35; d++) {
document.getElementById("claim" + (boxnum - 1) + d).remove();
document.getElementById("topic" + (boxnum - 1) + d).remove();
document.getElementById("lead" + (boxnum - 1) + d).remove();
}
mass.push(document.getElementById("weight").innerHTML);
}
document.getElementById("weight").innerHTML = 0;
window.centipede = 0;
}
function decrease() {
if (fixer === boxnum) {
window.boxnum = window.boxnum - 2;
mass.push(document.getElementById("weight").innerHTML);
} else {
window.boxnum = window.boxnum - 1;
}
document.getElementById("scribble").innerHTML = ">";
document.getElementById("scribble").onclick = increase;
document.getElementById("creation").style.left = "15.2in";
if (boxnum === 1) {
document.getElementById("countdown").style.visibility = "hidden";
}
for (let v = 0; v < 35; v++) {
document.getElementById("claim" + (fixer - 1) + v).innerHTML = data[boxnum][v];
}
document.getElementById("foodresult").innerHTML = foodname[boxnum - 1];
window.mass[boxnum] = document.getElementById("weight").innerHTML;
document.getElementById("weight").innerHTML = mass[boxnum - 1];
window.centipede = mass[boxnum - 1];
}
function increase() {
window.boxnum = window.boxnum + 1;
document.getElementById("countdown").style.visibility = "visible";
if (boxnum === (fixer - 1)) {
document.getElementById("scribble").onclick = function both() {reset(); create();};
document.getElementById("scribble").innerHTML = "Create Item";
document.getElementById("creation").style.left = "14.2in";
}
for (let b = 0; b < 35; b++) {
document.getElementById("claim" + (fixer - 1) + b).innerHTML = data[boxnum][b];
}
document.getElementById("foodresult").innerHTML = foodname[boxnum - 1];
window.mass[boxnum - 2] = document.getElementById("weight").innerHTML;
document.getElementById("weight").innerHTML = mass[boxnum - 1];
window.centipede = mass[boxnum - 1];
}
function progressboard() {
for (let c = 0; c < 35; c++) {
var value = "";
var name = document.createElement("label");
var space = document.createElement("br");
var final = document.createElement("span");
var signal = "#nut" + c + ":hover + #prog" + c + " {background-color: yellow;}";
var show = "#prog" + c + " {color: rgb(195, 195, 0);}";
var mood = document.createElement("style");
var tone = document.createElement("style");
tone.innerText = show;
mood.innerText = signal;
name.innerHTML = nutrient[c];
name.id = "nut" + c;
final.id = "prog" + c;
space.id = "jump" + c;
if (c > 19) {
value = "mcg";
} else if (c > 3) {
value = "mg";
} else if (c > 0) {
value = "g";
} else {
value = "";
}
if (data[0][c] == "---") {
final.innerHTML = data[0][c];
} else {
final.innerHTML = "0" + value + " out of " + data[0][c] + value + " (0%)" //get rid of the g when done with Gala Apple Video
}
final.className = "rating";
document.getElementById("cross").appendChild(name);
document.getElementById("cross").appendChild(final);
document.getElementById("cross").appendChild(space);
document.head.appendChild(mood);
document.head.appendChild(tone);
}
}
function minus() {
if (centipede === 0) {
return;
}
window.centipede = window.centipede - 1;
document.getElementById("weight").innerHTML = centipede;
if (fixer === boxnum) {
boxnum = boxnum - 1;
}
for (let y = 0; y < 35; y++) {
var value = "";
if (data[boxnum][y] == "---") {
window.shift[y] == "---";
} else {
window.shift[y] = window.shift[y] - data[boxnum][y];
}
var percentage = window.shift[y]/data[0][y] * 100;
percentage = percentage.toFixed(0);
if (data[0][y] == "---" || data[boxnum][y] == "---") {
document.getElementById("prog" + y).style.color = "gray";
} else if (percentage < 100) {
document.getElementById("prog" + y).style.color = "rgb(195, 195, 0)";
} else if (percentage == 100) {
document.getElementById("prog" + y).style.color = "green";
} else {
document.getElementById("prog" + y).style.color = "red";
}
if (y > 21) {
value = "mcg";
} else if (y > 4) {
value = "mg";
} else if (y > 0) {
value = "g";
} else {
value = "";
}
if (data[0][y] == "---" || data[boxnum][y] == "---") {
document.getElementById("prog" + y).innerHTML = "---";
} else {
window.shift[y] = window.shift[y].toFixed(2);
document.getElementById("prog" + y).innerHTML = window.shift[y] + value + " out of " + data[0][y] + value + "(" + percentage + "%)"; //get rid of "g" after you are done with Gala Apple Video
}
}
}
function add() {
var value = "";
window.centipede = Number(window.centipede) + 1;
document.getElementById("weight").innerHTML = centipede;
if (fixer === boxnum) {
boxnum = boxnum - 1;
}
for (let z = 0; z < 35; z++) {
if (data[boxnum][z] == "---") {
window.shift[z] = "---";
} else {
window.shift[z] = Number(window.shift[z]) + Number(data[boxnum][z]);
}
var percentage = window.shift[z]/data[0][z] * 100;
if (data[0][z] == "---" || window.shift[z] == "---") {
document.getElementById("prog" + z).style.color = "gray";
} else if (percentage < 100) {
document.getElementById("prog" + z).style.color = "rgb(195, 195, 0)";
} else if (percentage == 100) {
document.getElementById("prog" + z).style.color = "green";
} else {
document.getElementById("prog" + z).style.color = "red";
}
percentage = percentage.toFixed(2);
if (z > 21) {
value = "mcg";
} else if (z > 4) {
value = "mg";
} else if (z > 0) {
value = "g";
} else {
value = "";
}
if (data[0][z] == "---" || window.shift[z] == "---") {
document.getElementById("prog" + z).innerHTML = "---";
} else {
window.shift[z] = window.shift[z].toFixed(2);
document.getElementById("prog" + z).innerHTML = window.shift[z] + value + " out of " + data[0][z] + value + "(" + percentage + "%)"; //get rid of "g" after you are done with Gala Apple Video
}
}
}
function bye() {
localStorage.clear();
}
</script>
</head>
<body>
<div id="page1">
<h1 id="step1" class="position">Nutrition Calculator</h1>
<div class="position">
<button id="enter" type="button" class="visual" onclick="create()">Custom</button>
</div>
<div class="space">
<button type="button" class="visual">Credits</button> <!-- Use this for Credits later-->
</div>
</div>
<div id="area0">
<form id="item0">
<h2 class="title">Plan</h2>
</form>
<div class="section">
<br />
<button type="button" id="preserve0" class="finalize" onclick="record(), progressboard()">Save</button>
</div>
</div>
<div id="area1">
<form id="item1" class="inventory">
<input type="text" id="foodname" />
<h2 id="foodresult"></h2>
</form>
<div class="section">
<br />
<button type="button" id="preserve1" class="finalize" onclick="record()">Save</button>
</div>
</div>
<div id="creation">
<button type="button" id="scribble" class="finalize" onclick= "reset(), create()">Create Item</button>
</div>
<div id="previous">
<button type="button" class="finalize" id="countdown" onclick="decrease()"><</button>
</div>
<div id="area2">
<form id="cross">
<h2 class="title" id="result">Progress</h2>
</form>
</div>
<div id="fall">
<button type="button" class="finalize" id="subtract" onclick="minus()">-</button>
</div>
<div id="rise">
<button type="button" class="finalize" id="add" onclick="add()">+</button>
</div>
<div id="cent">
<span id="weight">0</span>
</div>
<div id="refresh">
<button type="button" class="finalize" id="empty" onclick="bye()">Reset</button>
</div>
</body>
</html>