forked from jeremiah-fan/gainsville_app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gainsville.js
377 lines (331 loc) · 11.5 KB
/
gainsville.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
var goal, days, numDays, parts; // global variables that affect workout
var day_dict = {
"sun": "<b>Sunday</b>",
"mon": "<b>Monday</b>",
"tue": "<b>Tuesday</b>",
"wed": "<b>Wednesday</b>",
"thu": "<b>Thursday</b>",
"fri": "<b>Friday</b>",
"sat": "<b>Saturday</b>"
};
window.onload = function() { // pull information from query string
var query = window.location.search;
// Skip the leading ?
if (query.substring(0, 1) == '?') {
query = query.substring(1);
}
else {
return 0;
}
parts = query.split(',');
var temp = parts.splice(parts.length - 2, parts.length);
days = temp[0];
goal = temp[1];
numDays = parseInt(days.charAt(days.length - 1))
if(numDays == 1) {
createTable(arrayFill(0), days.substring(0, 3));
}
else {
var d = 3;
for(var i = 0; i < numDays; i++) {
// fill tables with alternating day 1 and day 2
createTable(arrayFill((i % 2) + 1), days.substring(d - 3, d));
d += 3;
}
}
}
function arrayFill(day) { // populate 2D array
var tempArr = [];
var counter = 1;
var arrIndex = 1; // temp array index
tempArr[0] = ["Muscle", "Exercise", "Sets x Reps"];
if(day == 0) {
while(counter < parts.length + 1) { // only 1 day of workout per week
switch(parts[counter - 1]) { // populate array based on part
case "deltoid":
if(goal === "str") {
tempArr[counter] = ["Deltoid", "Overhead Press", "3 x 5"];
}
else {
tempArr[counter] = ["Deltoid", "Dumbbell Lateral Raise", "3 x 12"];
}
break;
case "bicep":
if(goal === "str") {
tempArr[counter] = ["Bicep", "Barbell Bicep Curl", "3 x 8"];
}
else {
tempArr[counter] = ["Bicep", "Incline Dumbbell Bicep Curl", "3 x 12"];
}
break;
case "forearm":
tempArr[counter] = ["Forearm", "Dumbbell Wrist Curl", "3 x 12"];
break;
case "quadricep":
if(goal === "aes") {
tempArr[counter] = ["Quadricep", "Leg Extension", "3 x 12"];
}
else if(parts.indexOf("glutes") != -1) { // include glutes in quads
tempArr[counter] = ["Quadricep, Glutes", "Barbell Squat", "3 x 5"];
}
else {
tempArr[counter] = ["Quadricep", "Barbell Squat", "3 x 5"];
}
break;
case "chest":
if(goal === "aes") {
tempArr[counter] = ["Chest", "Cable Fly", "3 x 12"];
}
else {
tempArr[counter] = ["Chest", "Bench Press", "3 x 5"];
}
break;
case "tricep":
if(goal === "str") {
tempArr[counter] = ["Tricep", "Close Grip Bench Press", "3 x 8"];
}
else {
tempArr[counter] = ["Tricep", "Cable Tricep Extension", "3 x 12"];
}
break;
case "abdomen":
tempArr[counter] = ["Abdomen", "Plank", "3 x As long as possible"];
break;
case "hamstring":
if(goal === "str") {
tempArr[counter] = ["Hamstring", "Leg Curl", "3 x 8"];
}
else {
tempArr[counter] = ["Hamstring", "Leg Curl", "3 x 12"];
}
break;
case "calves":
tempArr[counter] = ["Calves", "Standing Calf Raise", "3 x 15"];
break;
case "trapezius":
if(goal === "aes") {
tempArr[counter] = ["Trapezius", "Barbell Shrug", "3 x 12"];
}
else if(parts.indexOf("lowerback") != -1) {
break;
}
else {
tempArr[counter] = ["Trapezius", "Barbell Shrug", "3 x 8"];
}
break;
case "upper":
if(goal === "aes") {
tempArr[counter] = ["Upper Back", "Cable Row", "3 x 12"];
}
else {
tempArr[counter] = ["Upper Back", "Barbell Row", "3 x 5"];
}
break;
case "lower":
if(goal === "aes") {
tempArr[counter] = ["Lower Back", "Hyperextension", "3 x 12"];
}
else if(parts.indexOf("trapezius") != -1) { // include traps in back
tempArr[counter] = ["Lower Back, Trapezius", "Deadlift", "3 x 5"];
}
else {
tempArr[counter] = ["Lower Back", "Deadlift", "3 x 5"];
}
break;
case "glutes":
if(goal === "aes") {
tempArr[counter] = ["Glutes", "Barbell Hip Thrust", "3 x 12"];
}
else if(parts.indexOf("quadricep") != -1) {
break;
}
else {
tempArr[counter] = ["Glutes", "Barbell Hip Thrust", "3 x 8"];
}
break;
case "obliques":
tempArr[counter] = ["Obliques", "Side Bends", "3 x 10"];
break;
case "lats":
if(goal === "aes") {
tempArr[counter] = ["Lats", "Lat Pulldown", "3 x 12"];
}
else {
tempArr[counter] = ["Lats", "Pull-Ups", "3 x 8"];
}
}
counter++; // move on to next part
}
}
else if(day == 1) { // day 1 of workout
while(counter < parts.length + 1) {
switch(parts[counter - 1]) { // populate array based on part
case "quadricep":
if(goal === "aes") {
tempArr[arrIndex++] = ["Quadricep", "Leg Extension", "3 x 12"];
}
else if(parts.indexOf("glutes") != -1) { // include glutes in quads
tempArr[arrIndex++] = ["Quadricep, Glutes", "Barbell Squat", "3 x 5"];
}
else {
tempArr[arrIndex++] = ["Quadricep", "Barbell Squat", "3 x 5"];
}
break;
case "deltoid":
if(goal === "str") {
tempArr[arrIndex++] = ["Deltoid", "Overhead Press", "3 x 5"];
}
else {
tempArr[arrIndex++] = ["Deltoid", "Dumbbell Lateral Raise", "3 x 12"];
}
break;
case "upper":
if(goal === "aes") {
tempArr[arrIndex++] = ["Upper Back", "Cable Row", "3 x 12"];
}
else {
tempArr[arrIndex++] = ["Upper Back", "Barbell Row", "3 x 5"];
}
break;
case "bicep":
if(goal === "str") {
tempArr[arrIndex++] = ["Bicep", "Barbell Bicep Curl", "3 x 8"];
}
else {
tempArr[arrIndex++] = ["Bicep", "Incline Dumbbell Bicep Curl", "3 x 12"];
}
break;
case "forearm":
tempArr[arrIndex++] = ["Forearm", "Dumbbell Wrist Curl", "3 x 12"];
break;
case "abdomen":
tempArr[arrIndex++] = ["Abdomen", "Plank", "3 x As long as possible"];
break;
case "hamstring":
if(goal === "str") {
tempArr[arrIndex++] = ["Hamstring", "Leg Curl", "3 x 8"];
}
else {
tempArr[arrIndex++] = ["Hamstring", "Leg Curl", "3 x 12"];
}
break;
case "glutes":
if(goal === "aes") {
tempArr[arrIndex++] = ["Glutes", "Barbell Hip Thrust", "3 x 12"];
}
else if(parts.indexOf("quadricep") != -1) {
break;
}
else {
tempArr[arrIndex++] = ["Glutes", "Barbell Hip Thrust", "3 x 8"];
}
break;
case "calves":
tempArr[arrIndex++] = ["Calves", "Standing Calf Raise", "3 x 15"];
break;
case "obliques":
tempArr[arrIndex++] = ["Obliques", "Side Bends", "3 x 10"];
break;
case "lats":
if(goal === "aes") {
tempArr[arrIndex++] = ["Lats", "Lat Pulldown", "3 x 12"];
}
else {
tempArr[arrIndex++] = ["Lats", "Pull-Ups", "3 x 8"];
}
}
counter++; // move on to next part
}
}
else { // day 2 of workout
while(counter < parts.length + 1) {
switch(parts[counter - 1]) { // populate array based on part
case "chest":
if(goal === "aes") {
tempArr[arrIndex++] = ["Chest", "Cable Fly", "3 x 12"];
}
else {
tempArr[arrIndex++] = ["Chest", "Bench Press", "3 x 5"];
}
break;
case "lower":
if(goal === "aes") {
tempArr[arrIndex++] = ["Lower Back", "Hyperextension", "3 x 12"];
}
else if(parts.indexOf("trapezius") != -1) { // include traps in back
tempArr[arrIndex++] = ["Lower Back, Trapezius", "Deadlift", "3 x 5"];
}
else {
tempArr[arrIndex++] = ["Lower Back", "Deadlift", "3 x 5"];
}
break;
case "bicep":
if(goal === "str") {
tempArr[arrIndex++] = ["Bicep", "Dumbbell Bicep Curl", "3 x 8"];
}
else {
tempArr[arrIndex++] = ["Bicep", "Incline Dumbbell Bicep Curl", "3 x 12"];
}
break;
case "forearm":
tempArr[arrIndex++] = ["Forearm", "Dumbbell Wrist Curl", "3 x 12"];
break;
case "tricep":
if(goal === "str") {
tempArr[arrIndex++] = ["Tricep", "Close Grip Bench Press", "3 x 8"];
}
else {
tempArr[arrIndex++] = ["Tricep", "Cable Tricep Extension", "3 x 12"];
}
break;
case "abdomen":
tempArr[arrIndex++] = ["Abdomen", "Plank", "3 x As long as possible"];
break;
case "calves":
tempArr[arrIndex++] = ["Calves", "Seated Calf Raise", "3 x 15"];
break;
case "trapezius":
if(goal === "aes") {
tempArr[arrIndex++] = ["Trapezius", "Barbell Shrug", "3 x 12"];
}
else if(parts.indexOf("lowerback") != -1) {
break;
}
else {
tempArr[arrIndex++] = ["Trapezius", "Barbell Shrug", "3 x 8"];
}
break;
case "obliques":
tempArr[arrIndex++] = ["Obliques", "Side Bends", "3 x 10"];
break;
}
counter++; // move on to next part
}
}
return tempArr;
}
function createTable(partsArray, daysOfWeek) { // creates table
var col = 3; // number of columns
var body = document.body,
tbl = document.createElement('table');
tbl.className = "u-full-width";
for(var i = 0; i < partsArray.length; i++) {
var tr = tbl.insertRow();
for(var j = 0; j < col; j++) {
var td = tr.insertCell();
td.appendChild(document.createTextNode('cell'));
}
}
body.appendChild(tbl);
var caption = tbl.createCaption();
caption.innerHTML = day_dict[daysOfWeek];
tbl.rows[0].cells[0].style.fontWeight = 'bold';
tbl.rows[0].cells[1].style.fontWeight = 'bold';
tbl.rows[0].cells[2].style.fontWeight = 'bold';
for(var x = 0; x < partsArray.length; x++) {
for(var y = 0; y < col; y++) {
tbl.rows[x].cells[y].innerHTML = partsArray[x][y];
}
}
tbl.style.marginBottom = "50px"; // spaces between tables
}