-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkout.js
More file actions
120 lines (106 loc) · 4.27 KB
/
workout.js
File metadata and controls
120 lines (106 loc) · 4.27 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
// Workout Recommender
function initWorkoutRecommender() {
// Check if we're on the programs page
if (window.location.hash === '#categories' || document.querySelector('.programs-section')) {
const recommendButton = document.createElement('button');
recommendButton.id = 'workout-recommender-btn';
recommendButton.textContent = 'Get Personalized Recommendations';
recommendButton.classList.add('btn', 'btn-primary');
const programsSection = document.querySelector('.programs-section .container');
if (programsSection) {
programsSection.appendChild(recommendButton);
recommendButton.addEventListener('click', () => {
showWorkoutQuestionnaire();
});
}
}
}
function showWorkoutQuestionnaire() {
const modal = document.createElement('div');
modal.id = 'workout-modal';
modal.innerHTML = `
<div class="workout-modal-content">
<h3>Personalized Workout Recommendation</h3>
<form id="workout-form">
<div class="form-group">
<label>What are your primary fitness goals?</label>
<select id="fitness-goal">
<option value="strength">Build Strength</option>
<option value="weightloss">Lose Weight</option>
<option value="endurance">Improve Endurance</option>
<option value="flexibility">Increase Flexibility</option>
</select>
</div>
<div class="form-group">
<label>How many days per week can you workout?</label>
<select id="workout-frequency">
<option value="2">2 days</option>
<option value="3">3 days</option>
<option value="4">4 days</option>
<option value="5">5+ days</option>
</select>
</div>
<div class="form-group">
<label>What's your current fitness level?</label>
<select id="fitness-level">
<option value="beginner">Beginner</option>
<option value="intermediate">Intermediate</option>
<option value="advanced">Advanced</option>
</select>
</div>
<button type="submit" class="btn btn-primary">Get Recommendations</button>
</form>
</div>
`;
document.body.appendChild(modal);
document.getElementById('workout-form').addEventListener('submit', (e) => {
e.preventDefault();
generateRecommendations();
});
// Close modal when clicking outside
modal.addEventListener('click', (e) => {
if (e.target === modal) {
document.body.removeChild(modal);
}
});
}
function generateRecommendations() {
const goal = document.getElementById('fitness-goal').value;
const frequency = document.getElementById('workout-frequency').value;
const level = document.getElementById('fitness-level').value;
// Simple recommendation logic (can be enhanced with more complex AI)
let recommendedPrograms = [];
if (goal === 'strength') {
recommendedPrograms.push('Strength Training');
if (frequency >= 3) recommendedPrograms.push('HIIT Workouts');
} else if (goal === 'weightloss') {
recommendedPrograms.push('Cardio Blast', 'HIIT Workouts');
} else if (goal === 'endurance') {
recommendedPrograms.push('Cardio Blast');
if (frequency >= 3) recommendedPrograms.push('HIIT Workouts');
} else if (goal === 'flexibility') {
recommendedPrograms.push('Yoga & Mobility');
if (frequency >= 3) recommendedPrograms.push('Pilates');
}
// Adjust for fitness level
if (level === 'beginner') {
recommendedPrograms = recommendedPrograms.map(p => `${p} (Beginner)`);
} else if (level === 'advanced') {
recommendedPrograms = recommendedPrograms.map(p => `${p} (Advanced)`);
}
// Show results
const modal = document.getElementById('workout-modal');
modal.querySelector('.workout-modal-content').innerHTML = `
<h3>Recommended For You</h3>
<p>Based on your goals and availability, we recommend:</p>
<ul class="recommendations-list">
${recommendedPrograms.map(p => `<li>${p}</li>`).join('')}
</ul>
<button id="close-modal" class="btn btn-primary">Close</button>
`;
document.getElementById('close-modal').addEventListener('click', () => {
document.body.removeChild(modal);
});
}
// Initialize when page loads
document.addEventListener('DOMContentLoaded', initWorkoutRecommender);