-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.js
More file actions
781 lines (702 loc) · 30.5 KB
/
Copy pathdata.js
File metadata and controls
781 lines (702 loc) · 30.5 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
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
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
const DEFAULT_TRAINING_TIME = 40; // Default training time in second
const DEFAULT_REST_TIME = 60; // Default rest time in second
const DEFAULT_SETS = 3; // Default number of sets
const workoutDataLegacy = {
exercises: [
{ name: "Jump Rope", description: "", tags: ["cardio"], bodyParts: [] },
{ name: "DB Row", description: "", tags: ["strength", "upper body"], bodyParts: ["back", "arms"] },
{ name: "Push-ups", description: "", tags: ["strength", "upper body", "bodyweight"], bodyParts: ["chest", "triceps", "shoulders"] },
{ name: "High Knees", description: "", tags: ["cardio"], bodyParts: ["legs", "core"] },
{ name: "Goblet Squat", description: "", tags: ["strength", "lower body"], bodyParts: ["quads", "glutes"] },
{ name: "Glute Bridge (elastic)", description: "", tags: ["strength", "glutes"], bodyParts: ["glutes", "hamstrings"] },
{ name: "Mountain Climbers", description: "", tags: ["cardio", "core"], bodyParts: ["abs", "shoulders"] },
{ name: "Russian Twist", description: "", tags: ["core"], bodyParts: ["abs", "obliques"] },
{ name: "Burpees", description: "", tags: ["cardio", "full body"], bodyParts: ["full body"] },
{ name: "Jump Squats", description: "", tags: ["strength", "explosive", "legs"], bodyParts: ["quads", "glutes"] },
{ name: "Reverse Lunge", description: "", tags: ["strength", "legs"], bodyParts: ["quads", "hamstrings", "glutes"] },
{ name: "Sumo Deadlift", description: "", tags: ["strength", "legs"], bodyParts: ["hamstrings", "glutes", "back"] },
{ name: "Skater Jumps", description: "", tags: ["cardio", "explosive"], bodyParts: ["legs", "glutes"] },
{ name: "Bulgarian Split Squat", description: "", tags: ["strength", "legs"], bodyParts: ["quads", "glutes"] },
{ name: "Glute Bridge Hold", description: "", tags: ["core", "glutes"], bodyParts: ["glutes", "hamstrings"] },
{ name: "Jumping Jacks", description: "", tags: ["cardio"], bodyParts: ["full body"] },
{ name: "Plank Row", description: "", tags: ["strength", "core", "upper body"], bodyParts: ["core", "back", "arms"] },
{ name: "Side Plank", description: "", tags: ["core", "stability"], bodyParts: ["obliques", "core"] },
{ name: "Chest Press", description: "", tags: ["strength", "upper body"], bodyParts: ["chest", "arms"] },
{ name: "Overhead Press", description: "", tags: ["strength", "shoulders"], bodyParts: ["shoulders", "arms"] },
{ name: "Biceps Curl", description: "", tags: ["strength", "arms"], bodyParts: ["biceps"] },
{ name: "Triceps Extension", description: "", tags: ["strength", "arms"], bodyParts: ["triceps"] },
{ name: "Hammer Curl", description: "", tags: ["strength", "arms"], bodyParts: ["biceps"] },
{ name: "Hip Thrust", description: "", tags: ["strength", "glutes"], bodyParts: ["glutes", "hamstrings"] },
{ name: "Glute Kickback (elastic)", description: "", tags: ["strength", "glutes"], bodyParts: ["glutes"] },
{ name: "Side Lunge", description: "", tags: ["strength", "legs"], bodyParts: ["quads", "glutes"] },
{ name: "Side Plank with Leg Raise", description: "", tags: ["core", "stability"], bodyParts: ["obliques", "glutes"] },
{ name: "Leg Raises", description: "", tags: ["core"], bodyParts: ["lower abs"] },
{ name: "Deadlift", description: "", tags: ["strength", "full body"], bodyParts: ["hamstrings", "glutes", "back"] },
{ name: "Squat Press", description: "", tags: ["strength", "full body"], bodyParts: ["legs", "shoulders"] },
{ name: "Renegade Row", description: "", tags: ["strength", "core"], bodyParts: ["core", "back", "arms"] },
{ name: "DB Swing", description: "", tags: ["explosive", "conditioning"], bodyParts: ["hips", "glutes", "shoulders"] },
{ name: "Plank Hold", description: "", tags: ["core", "stability"], bodyParts: ["abs", "back"] }
],
plans: [
{
name: "5-Day Circuit Training Plan",
description: "A structured 5-day cardio and strength plan with mixed focus areas.",
days: [
{
name: "Day 1 - Upper / Lower Focus",
blocks: [
{
name: "Block 1",
sets: 3,
rest: 60,
exercises: [
{ name: "Jump Rope", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "DB Row", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Push-ups", trainingTime: DEFAULT_TRAINING_TIME }
]
},
{
name: "Block 2",
sets: 3,
rest: 60,
exercises: [
{ name: "High Knees", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Goblet Squat", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Glute Bridge (elastic)", trainingTime: DEFAULT_TRAINING_TIME }
]
},
{
name: "Block 3",
sets: 3,
rest: 60,
exercises: [
{ name: "Mountain Climbers", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Russian Twist", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Burpees", trainingTime: DEFAULT_TRAINING_TIME }
]
}
]
},
{
name: "Day 2 - Legs + Core Focus",
blocks: [
{
name: "Block 1",
sets: 3,
rest: 60,
exercises: [
{ name: "Jump Squats", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Reverse Lunge", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Sumo Deadlift", trainingTime: DEFAULT_TRAINING_TIME }
]
},
{
name: "Block 2",
sets: 3,
rest: 60,
exercises: [
{ name: "Skater Jumps", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Bulgarian Split Squat", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Glute Bridge Hold", trainingTime: DEFAULT_TRAINING_TIME }
]
},
{
name: "Block 3",
sets: 3,
rest: 60,
exercises: [
{ name: "Jumping Jacks", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Plank Row", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Side Plank", trainingTime: DEFAULT_TRAINING_TIME }
]
}
]
},
{
name: "Day 3 - Push / Pull Focus",
blocks: [
{
name: "Block 1",
sets: 3,
rest: 60,
exercises: [
{ name: "Jump Rope", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Chest Press", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "DB Row", trainingTime: DEFAULT_TRAINING_TIME }
]
},
{
name: "Block 2",
sets: 3,
rest: 60,
exercises: [
{ name: "High Knees", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Overhead Press", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Biceps Curl", trainingTime: DEFAULT_TRAINING_TIME }
]
},
{
name: "Block 3",
sets: 3,
rest: 60,
exercises: [
{ name: "Mountain Climbers", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Triceps Extension", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Hammer Curl", trainingTime: DEFAULT_TRAINING_TIME }
]
}
]
},
{
name: "Day 4 - Glutes / Core Focus",
blocks: [
{
name: "Block 1",
sets: 3,
rest: 60,
exercises: [
{ name: "Skater Jumps", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Hip Thrust", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Glute Kickback (elastic)", trainingTime: DEFAULT_TRAINING_TIME }
]
},
{
name: "Block 2",
sets: 3,
rest: 60,
exercises: [
{ name: "Jumping Jacks", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Side Lunge", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Side Plank with Leg Raise", trainingTime: DEFAULT_TRAINING_TIME }
]
},
{
name: "Block 3",
sets: 3,
rest: 60,
exercises: [
{ name: "Jump Rope", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Russian Twist", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Leg Raises", trainingTime: DEFAULT_TRAINING_TIME }
]
}
]
},
{
name: "Day 5 - Full Body Conditioning",
blocks: [
{
name: "Block 1",
sets: 3,
rest: 60,
exercises: [
{ name: "Burpees", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Deadlift", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Push-ups", trainingTime: DEFAULT_TRAINING_TIME }
]
},
{
name: "Block 2",
sets: 3,
rest: 60,
exercises: [
{ name: "High Knees", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Squat Press", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Renegade Row", trainingTime: DEFAULT_TRAINING_TIME }
]
},
{
name: "Block 3",
sets: 3,
rest: 60,
exercises: [
{ name: "Jump Squats", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "DB Swing", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Plank Hold", trainingTime: DEFAULT_TRAINING_TIME }
]
}
]
}
]
},
{
name: "Cardio Crusher 5-Day Plan",
description: "A high-energy, cardio-focused 5-day workout plan designed to boost endurance, burn fat, and improve cardiovascular health.",
days: [
{
name: "Day 1 - Explosive Start",
blocks: [
{
name: "Block 1",
sets: 3,
rest: 45,
exercises: [
{ name: "Jumping Jacks", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Jump Squats", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Plank Jacks", trainingTime: DEFAULT_TRAINING_TIME }
]
},
{
name: "Block 2",
sets: 3,
rest: 60,
exercises: [
{ name: "Skater Jumps", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Mountain Climbers", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Burpees", trainingTime: DEFAULT_TRAINING_TIME }
]
}
]
},
{
name: "Day 2 - Core Fire",
blocks: [
{
name: "Block 1",
sets: 3,
rest: 45,
exercises: [
{ name: "High Knees", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Side Plank with Leg Raise", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Russian Twist", trainingTime: DEFAULT_TRAINING_TIME }
]
},
{
name: "Block 2",
sets: 3,
rest: 60,
exercises: [
{ name: "Jump Rope", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Plank to Push-up", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Leg Raises", trainingTime: DEFAULT_TRAINING_TIME }
]
}
]
},
{
name: "Day 3 - Plyo Sweat",
blocks: [
{
name: "Block 1",
sets: 3,
rest: 45,
exercises: [
{ name: "Jump Lunges", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Burpees", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Mountain Climbers", trainingTime: DEFAULT_TRAINING_TIME }
]
},
{
name: "Block 2",
sets: 3,
rest: 60,
exercises: [
{ name: "Squat Jumps", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Plank Jacks", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Skater Jumps", trainingTime: DEFAULT_TRAINING_TIME }
]
}
]
},
{
name: "Day 4 - Speed & Stability",
blocks: [
{
name: "Block 1",
sets: 3,
rest: 45,
exercises: [
{ name: "Jump Rope", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Side Plank", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Reverse Lunge to Knee Drive", trainingTime: DEFAULT_TRAINING_TIME }
]
},
{
name: "Block 2",
sets: 3,
rest: 60,
exercises: [
{ name: "High Knees", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Bear Crawl", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Leg Raises", trainingTime: DEFAULT_TRAINING_TIME }
]
}
]
},
{
name: "Day 5 - Total Body Burnout",
blocks: [
{
name: "Block 1",
sets: 3,
rest: 60,
exercises: [
{ name: "Burpees", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Squat to Jump", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Plank Shoulder Taps", trainingTime: DEFAULT_TRAINING_TIME }
]
},
{
name: "Block 2",
sets: 3,
rest: 60,
exercises: [
{ name: "Mountain Climbers", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Jump Rope", trainingTime: DEFAULT_TRAINING_TIME },
{ name: "Push-up to Knee Drive", trainingTime: DEFAULT_TRAINING_TIME }
]
}
]
}
]
}
]
};
const WORKOUT_KEY = "workoutData";
const loadData = () => {
let workoutData;
try {
workoutData = JSON.parse(localStorage.getItem(WORKOUT_KEY));
const exits = workoutData.plans[0] != undefined;
} catch {
localStorage.setItem(WORKOUT_KEY, JSON.stringify(workoutDataLegacy));
workoutData = workoutDataLegacy;
}
return workoutData;
}
let workoutData = loadData();
const resetPlans = () => {
localStorage.setItem(WORKOUT_KEY, JSON.stringify(workoutDataLegacy));
workoutData = workoutDataLegacy;
}
const downloadData = (name, data) => {
const blob = new Blob([data], { type: "application/json" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.download = `${name}-${new Date().toISOString()}.json`;
a.href = url;
a.click();
URL.revokeObjectURL(url);
}
const exportWorkoutData = () => {
const data = JSON.stringify(workoutData, null, 2);
downloadData("workout-data", data);
}
const exportPlan = (planName) => {
const plan = workoutData.plans.find(
p => p.name === planName
);
if (!plan) {
return "Plan not found";
}
const exerciseNames = {};
plan.days.forEach(day => {
day.blocks.forEach(block => {
block.exercises.forEach(exercise => {
exerciseNames[exercise.name] = exercise.name;
});
});
});
const filteredExercises = workoutData.exercises.filter(exercise => exerciseNames[exercise.name]);
const filteredData = {
exercises: filteredExercises,
plans: [plan],
}
const data = JSON.stringify(filteredData, null, 2);
downloadData(planName, data);
return true;
}
const importPlan = () => {
const fileInput = document.createElement('input');
fileInput.type = 'file';
fileInput.accept = '.json';
fileInput.style.display = 'none';
fileInput.addEventListener('change', (event) => {
const file = event.target.files[0];
if (!file) {
alert("No file selected.");
return;
}
const reader = new FileReader();
reader.onload = function (e) {
try {
const contents = e.target.result;
const data = JSON.parse(contents);
if (!Array.isArray(data.exercises) || !Array.isArray(data.plans)) {
alert("Invalid file.");
return;
}
data.exercises.forEach(newEx => {
if (!workoutData.exercises.some(ex => ex.name === newEx.name)) {
workoutData.exercises.push(newEx);
}
});
data.plans.forEach(newPlan => {
if (!workoutData.plans.some(plan => plan.name === newPlan.name)) {
workoutData.plans.push(newPlan);
}
});
localStorage.setItem(WORKOUT_KEY, JSON.stringify(workoutData));
alert("Plan imported successfully!")
} catch (err) {
alert("Error parsing JSON file: " + err.message);
}
};
reader.onerror = function () {
alert("Error reading the file.");
};
reader.readAsText(file);
});
document.body.appendChild(fileInput);
fileInput.click();
fileInput.remove();
};
const createPlan = (name, description) => {
if (!name) {
return "Plan name is required";
}
const planExists = workoutData.plans.some(plan => plan.name === name);
if (planExists) {
return `Plan ${name} already exists`;
}
workoutData.plans.push({
name,
description,
days: []
});
localStorage.setItem(WORKOUT_KEY, JSON.stringify(workoutData));
}
const deleteBlock = (planName, dayName, blockName) => {
const plan = workoutData.plans.find(plan => plan.name === planName);
if (!plan) {
return `Plan ${planName} not found`;
}
const day = plan.days.find(day => day.name === dayName);
if (!day) {
return `Day ${dayName} not found in plan ${planName}`;
}
const blockIndex = day.blocks.findIndex(block => block.name === blockName);
if (blockIndex === -1) {
return `Block ${blockName} not found in day ${dayName}`;
}
day.blocks.splice(blockIndex, 1);
localStorage.setItem(WORKOUT_KEY, JSON.stringify(workoutData));
}
const deletePlan = (name) => {
const planIndex = workoutData.plans.findIndex(plan => plan.name === name);
if (planIndex === -1) {
return `Plan ${name} not found`;
}
workoutData.plans.splice(planIndex, 1);
localStorage.setItem(WORKOUT_KEY, JSON.stringify(workoutData));
}
const createExercise = (name, description, tags, bodyParts) => {
if (!name) {
return "Exercise name is required";
}
const exerciseExists = workoutData.exercises.some(exercise => exercise.name === name);
if (exerciseExists) {
return `Exercise ${name} already exists`;
}
workoutData.exercises.push({
name,
description,
tags,
bodyParts
});
localStorage.setItem(WORKOUT_KEY, JSON.stringify(workoutData));
}
const modifyExercise = (name, newDescription, newTags, newBodyParts) => {
const exercise = workoutData.exercises.find(exercise => exercise.name === name);
if (!exercise) {
return `Exercise ${name} not found`;
}
exercise.description = newDescription;
exercise.tags = newTags;
exercise.bodyParts = newBodyParts;
localStorage.setItem(WORKOUT_KEY, JSON.stringify(workoutData));
return;
}
const modifyExerciseTimer = (planName, dayName, blockName, exerciseName, newTrainingTime) => {
const plan = workoutData.plans.find(plan => plan.name === planName);
if (!plan) {
return `Plan ${planName} not found`;
}
const day = plan.days.find(day => day.name === dayName);
if (!day) {
return `Day ${dayName} not found in plan ${planName}`;
}
const block = day.blocks.find(block => block.name === blockName);
if (!block) {
return `Block ${blockName} not found in day ${dayName}`;
}
const exercise = block.exercises.find(exercise => exercise.name === exerciseName);
if (!exercise) {
return `Exercise ${exerciseName} not found in block ${blockName}`;
}
exercise.trainingTime = newTrainingTime;
localStorage.setItem(WORKOUT_KEY, JSON.stringify(workoutData));
return;
}
const addExerciseToPlan = (planName, dayName, blockName, exerciseName) => {
const plan = workoutData.plans.find(plan => plan.name === planName);
if (!plan) {
return `Plan ${planName} not found`;
}
const day = plan.days.find(day => day.name === dayName);
if (!day) {
return `Day ${dayName} not found in plan ${planName}`;
}
const block = day.blocks.find(block => block.name === blockName);
if (!block) {
return `Block ${blockName} not found in day ${dayName}`;
}
block.exercises.push({ name: exerciseName, trainingTime: DEFAULT_TRAINING_TIME });
localStorage.setItem(WORKOUT_KEY, JSON.stringify(workoutData));
return;
}
const createBlock = (planName, dayName, blockName) => {
const plan = workoutData.plans.find(plan => plan.name === planName);
if (!plan) {
return `Plan ${planName} not found`;
}
const day = plan.days.find(day => day.name === dayName);
if (!day) {
return `Day ${dayName} not found in plan ${planName}`;
}
const blockExists = day.blocks.some(block => block.name === blockName);
if (blockExists) {
return `Block ${blockName} already exists in day ${dayName}`;
}
day.blocks.push({
name: blockName,
sets: DEFAULT_SETS,
rest: DEFAULT_REST_TIME,
exercises: []
});
localStorage.setItem(WORKOUT_KEY, JSON.stringify(workoutData));
return;
}
const modifyBlockRepetitions = (planName, dayName, blockName, newSets) => {
const plan = workoutData.plans.find(plan => plan.name === planName);
if (!plan) {
return `Plan ${planName} not found`;
}
const day = plan.days.find(day => day.name === dayName);
if (!day) {
return `Day ${dayName} not found in plan ${planName}`;
}
const block = day.blocks.find(block => block.name === blockName);
if (!block) {
return `Block ${blockName} not found in day ${dayName}`;
}
block.sets = newSets;
localStorage.setItem(WORKOUT_KEY, JSON.stringify(workoutData));
return;
}
const createDay = (planName, dayName) => {
const plan = workoutData.plans.find(plan => plan.name === planName);
if (!plan) {
return `Plan ${planName} not found`;
}
const dayExists = plan.days.some(day => day.name === dayName);
if (dayExists) {
return `Day ${dayName} already exists in plan ${planName}`;
}
plan.days.push({
name: dayName,
blocks: []
});
localStorage.setItem(WORKOUT_KEY, JSON.stringify(workoutData));
return;
}
const deleteDay = (planName, dayName) => {
const plan = workoutData.plans.find(plan => plan.name === planName);
if (!plan) {
return `Plan ${planName} not found`;
}
const dayIndex = plan.days.findIndex(day => day.name === dayName);
if (dayIndex === -1) {
return `Day ${dayName} not found in plan ${planName}`;
}
plan.days.splice(dayIndex, 1);
localStorage.setItem(WORKOUT_KEY, JSON.stringify(workoutData));
return;
}
const removeBlock = (planName, dayName, blockName) => {
const plan = workoutData.plans.find(plan => plan.name === planName);
if (!plan) {
return `Plan ${planName} not found`;
}
const day = plan.days.find(day => day.name === dayName);
if (!day) {
return `Day ${dayName} not found in plan ${planName}`;
}
const blockIndex = day.blocks.findIndex(block => block.name === blockName);
if (blockIndex === -1) {
return `Block ${blockName} not found in day ${dayName}`;
}
day.blocks.splice(blockIndex, 1);
localStorage.setItem(WORKOUT_KEY, JSON.stringify(workoutData));
return;
}
const removeExerciseFromBlock = (planName, dayName, blockName, exerciseIndex) => {
const plan = workoutData.plans.find(plan => plan.name === planName);
if (!plan) {
return `Plan ${planName} not found`;
}
const day = plan.days.find(day => day.name === dayName);
if (!day) {
return `Day ${dayName} not found in plan ${planName}`;
}
const block = day.blocks.find(block => block.name === blockName);
if (!block) {
return `Block ${blockName} not found in day ${dayName}`;
}
const exercise = block.exercises[exerciseIndex];
if (!exercise) {
return `Exercise at index ${index} not found in block ${blockName}`;
}
block.exercises.splice(exerciseIndex, 1);
localStorage.setItem(WORKOUT_KEY, JSON.stringify(workoutData));
return;
}
// Settings:
const THEME = "theme";
const AUTO = "auto";
const getTheme = () => {
const theme = localStorage.getItem(THEME) || "light";
return theme;
}
const setTheme = (isDark) => {
let theme = "light";
if (isDark) {
theme = "dark";
}
localStorage.setItem(THEME, theme);
document.documentElement.setAttribute("data-theme", theme);
}
const useTheme = () => {
const theme = localStorage.getItem(THEME) || "light";
document.documentElement.setAttribute("data-theme", theme);
}
const getAuto = () => {
const auto = localStorage.getItem(AUTO) || "";
return auto;
}
const setAuto = (isAuto) => {
let auto = "";
if (isAuto) {
auto = "auto";
}
localStorage.setItem(AUTO, auto);
}
const getAudioData = (type) => {
const sound = localStorage.getItem(type) || DEFAULT_SOUND;
const time = localStorage.getItem(`${type}_time`) || DEFAULT_SOUND_TIME;
return { sound, time };
}
const saveAudioData = (type, values) => {
localStorage.setItem(type, values.sound);
localStorage.setItem(`${type}_time`, values.time);
}