andyontrade commited on
Commit
7af4e49
·
verified ·
1 Parent(s): a86eb17

Add 1 files

Browse files
Files changed (1) hide show
  1. index.html +183 -27
index.html CHANGED
@@ -81,6 +81,21 @@
81
  border-left: 5px solid;
82
  border-radius: 8px 0 0 8px;
83
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  @keyframes pulse {
85
  0% { transform: scale(1); }
86
  50% { transform: scale(1.05); }
@@ -152,7 +167,7 @@
152
  <label class="block text-gray-700 mb-2 flex items-center">
153
  <span class="emoji-input">⚖️</span> Peso (kg)
154
  </label>
155
- <input type="number" id="weight" class="w-full px-4 py-3 border-2 border-gray-200 rounded-xl focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-transparent" min="40" max="200, value="70">
156
  </div>
157
 
158
  <div>
@@ -212,6 +227,71 @@
212
  </div>
213
  </div>
214
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
  <div class="mt-8">
216
  <button id="calculateBtn" class="w-full gradient-bg text-white py-4 rounded-xl font-bold text-lg hover:opacity-90 transition duration-300 flex items-center justify-center pulse-animation">
217
  <span class="emoji-input">✨</span> Calcular mis macronutrientes
@@ -464,6 +544,12 @@
464
  document.getElementById('manualTab').addEventListener('click', () => switchBodyfatTab('manual'));
465
  document.getElementById('calculateTab').addEventListener('click', () => switchBodyfatTab('calculate'));
466
  document.getElementById('calculateBodyfatBtn').addEventListener('click', calculateBodyfatPercentage);
 
 
 
 
 
 
467
 
468
  // Funciones
469
  function setGender(selectedGender) {
@@ -507,6 +593,40 @@
507
  document.getElementById('bodyfatValue').textContent = `${bodyfat}%`;
508
  }
509
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
510
  function calculateBodyfatPercentage() {
511
  const neck = parseFloat(document.getElementById('neck').value);
512
  const waist = parseFloat(document.getElementById('waist').value);
@@ -546,6 +666,7 @@
546
  const activity = parseFloat(document.getElementById('activity').value);
547
  const goal = document.getElementById('goal').value;
548
  const bodyfat = parseInt(document.getElementById('bodyfat').value) || 20;
 
549
 
550
  // Validaciones básicas
551
  if (age < 15 || age > 100 || weight < 40 || weight > 200 || height < 140 || height > 220) {
@@ -553,6 +674,19 @@
553
  return;
554
  }
555
 
 
 
 
 
 
 
 
 
 
 
 
 
 
556
  // Calcular calorías (Harris-Benedict revisada por Mifflin-St Jeor)
557
  let bmr;
558
  if (gender === 'male') {
@@ -579,33 +713,47 @@
579
  const dailyCalories = Math.round(tdee + calorieAdjustment);
580
 
581
  // Calcular macronutrientes
582
- // Proteína: 2.2g/kg para pérdida de peso, 1.8g/kg para mantenimiento, 1.6g/kg para aumento
583
- let proteinPerKg;
584
- if (goal === 'loss') {
585
- proteinPerKg = 2.2;
586
- } else if (goal === 'maintenance') {
587
- proteinPerKg = 1.8;
588
- } else {
589
- proteinPerKg = 1.6;
590
- }
591
 
592
- // Ajustar proteína si hay % grasa alto (>25%)
593
- if (bodyfat > 25) {
594
- proteinPerKg = Math.min(proteinPerKg + 0.2, 2.5);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
595
  }
596
 
597
- const proteinGrams = Math.round(weight * proteinPerKg);
598
- const proteinCalories = proteinGrams * 4;
599
-
600
- // Grasas: 25-35% de calorías
601
- const fatPercentage = 0.3; // 30%
602
- const fatCalories = Math.round(dailyCalories * fatPercentage);
603
- const fatGrams = Math.round(fatCalories / 9);
604
-
605
- // Carbohidratos: resto de calorías
606
- const carbsCalories = dailyCalories - proteinCalories - fatCalories;
607
- const carbsGrams = Math.round(carbsCalories / 4);
608
-
609
  // Agua recomendada
610
  const waterIntake = Math.round((weight * 0.035) * 10) / 10; // 35ml por kg
611
 
@@ -625,7 +773,7 @@
625
  document.getElementById('fatBar').style.width = `${Math.min(fatGrams / (weight * 1.2) * 100, 100)}%`;
626
 
627
  // Generar recomendaciones
628
- generateRecommendations(goal, dailyCalories, proteinGrams, carbsGrams, fatGrams, waterIntake);
629
 
630
  // Crear/actualizar gráfico
631
  updateChart(proteinGrams, carbsGrams, fatGrams);
@@ -637,7 +785,7 @@
637
  document.getElementById('results').scrollIntoView({ behavior: 'smooth' });
638
  }
639
 
640
- function generateRecommendations(goal, calories, protein, carbs, fat, water) {
641
  const recommendationsEl = document.getElementById('recommendations');
642
  recommendationsEl.innerHTML = '';
643
 
@@ -657,6 +805,13 @@
657
 
658
  addRecommendation(goalRecommendation);
659
 
 
 
 
 
 
 
 
660
  // Recomendación de proteína
661
  addRecommendation(`Consume aproximadamente ${protein}g de proteína diarios 🍗. Buenas fuentes incluyen carnes magras, pescado 🐟, huevos 🥚 y lácteos 🧀.`);
662
 
@@ -756,6 +911,7 @@
756
 
757
  // Inicializar
758
  setGender('male');
 
759
  </script>
760
  <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=andyontrade/macros" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
761
  </html>
 
81
  border-left: 5px solid;
82
  border-radius: 8px 0 0 8px;
83
  }
84
+ .macro-slider-container {
85
+ background-color: #f8f9fa;
86
+ border-radius: 10px;
87
+ padding: 15px;
88
+ margin-bottom: 15px;
89
+ }
90
+ .macro-slider-label {
91
+ display: flex;
92
+ justify-content: space-between;
93
+ margin-bottom: 5px;
94
+ }
95
+ .macro-percentage {
96
+ font-weight: bold;
97
+ color: #4A00E0;
98
+ }
99
  @keyframes pulse {
100
  0% { transform: scale(1); }
101
  50% { transform: scale(1.05); }
 
167
  <label class="block text-gray-700 mb-2 flex items-center">
168
  <span class="emoji-input">⚖️</span> Peso (kg)
169
  </label>
170
+ <input type="number" id="weight" class="w-full px-4 py-3 border-2 border-gray-200 rounded-xl focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-transparent" min="40" max="200" value="70">
171
  </div>
172
 
173
  <div>
 
227
  </div>
228
  </div>
229
 
230
+ <!-- Nueva sección para personalizar macros -->
231
+ <div class="mt-8">
232
+ <h3 class="text-xl font-semibold text-gray-800 mb-4 flex items-center">
233
+ <span class="emoji-input">⚖️</span> Distribución de Macronutrientes
234
+ </h3>
235
+
236
+ <div class="mb-4">
237
+ <div class="flex items-center mb-2">
238
+ <input type="checkbox" id="customMacrosToggle" class="mr-2 h-5 w-5">
239
+ <label for="customMacrosToggle" class="text-gray-700 font-medium flex items-center">
240
+ <span class="emoji-input">🎛️</span> Personalizar distribución de macros
241
+ </label>
242
+ </div>
243
+ <p class="text-sm text-gray-500 mb-4">Deja desmarcado para usar valores recomendados según tu objetivo</p>
244
+ </div>
245
+
246
+ <div id="customMacrosSection" class="hidden">
247
+ <div class="macro-slider-container">
248
+ <div class="macro-slider-label">
249
+ <span class="flex items-center">
250
+ <span class="emoji-input">🍗</span> Proteína (%)
251
+ </span>
252
+ <span id="proteinPercentValue" class="macro-percentage">30%</span>
253
+ </div>
254
+ <input type="range" id="proteinPercent" class="w-full" min="10" max="50" value="30" step="1">
255
+ <div class="flex justify-between text-xs text-gray-500 mt-1">
256
+ <span>10%</span>
257
+ <span>50%</span>
258
+ </div>
259
+ </div>
260
+
261
+ <div class="macro-slider-container">
262
+ <div class="macro-slider-label">
263
+ <span class="flex items-center">
264
+ <span class="emoji-input">🥑</span> Grasas (%)
265
+ </span>
266
+ <span id="fatPercentValue" class="macro-percentage">30%</span>
267
+ </div>
268
+ <input type="range" id="fatPercent" class="w-full" min="10" max="50" value="30" step="1">
269
+ <div class="flex justify-between text-xs text-gray-500 mt-1">
270
+ <span>10%</span>
271
+ <span>50%</span>
272
+ </div>
273
+ </div>
274
+
275
+ <div class="macro-slider-container">
276
+ <div class="macro-slider-label">
277
+ <span class="flex items-center">
278
+ <span class="emoji-input">🍞</span> Carbohidratos (%)
279
+ </span>
280
+ <span id="carbsPercentValue" class="macro-percentage">40%</span>
281
+ </div>
282
+ <input type="range" id="carbsPercent" class="w-full" min="10" max="80" value="40" step="1">
283
+ <div class="flex justify-between text-xs text-gray-500 mt-1">
284
+ <span>10%</span>
285
+ <span>80%</span>
286
+ </div>
287
+ <div class="mt-2 text-sm text-gray-600">
288
+ <span id="totalPercent" class="font-bold">Total: 100%</span>
289
+ <span id="percentError" class="text-red-500 ml-2 hidden">⚠️ La suma debe ser 100%</span>
290
+ </div>
291
+ </div>
292
+ </div>
293
+ </div>
294
+
295
  <div class="mt-8">
296
  <button id="calculateBtn" class="w-full gradient-bg text-white py-4 rounded-xl font-bold text-lg hover:opacity-90 transition duration-300 flex items-center justify-center pulse-animation">
297
  <span class="emoji-input">✨</span> Calcular mis macronutrientes
 
544
  document.getElementById('manualTab').addEventListener('click', () => switchBodyfatTab('manual'));
545
  document.getElementById('calculateTab').addEventListener('click', () => switchBodyfatTab('calculate'));
546
  document.getElementById('calculateBodyfatBtn').addEventListener('click', calculateBodyfatPercentage);
547
+ document.getElementById('customMacrosToggle').addEventListener('change', toggleCustomMacros);
548
+
549
+ // Sliders de macros personalizados
550
+ document.getElementById('proteinPercent').addEventListener('input', updateMacroPercentages);
551
+ document.getElementById('fatPercent').addEventListener('input', updateMacroPercentages);
552
+ document.getElementById('carbsPercent').addEventListener('input', updateMacroPercentages);
553
 
554
  // Funciones
555
  function setGender(selectedGender) {
 
593
  document.getElementById('bodyfatValue').textContent = `${bodyfat}%`;
594
  }
595
 
596
+ function toggleCustomMacros() {
597
+ const customMacrosSection = document.getElementById('customMacrosSection');
598
+ if (document.getElementById('customMacrosToggle').checked) {
599
+ customMacrosSection.classList.remove('hidden');
600
+ // Actualizar porcentajes iniciales
601
+ updateMacroPercentages();
602
+ } else {
603
+ customMacrosSection.classList.add('hidden');
604
+ }
605
+ }
606
+
607
+ function updateMacroPercentages() {
608
+ const proteinPercent = parseInt(document.getElementById('proteinPercent').value);
609
+ const fatPercent = parseInt(document.getElementById('fatPercent').value);
610
+ const carbsPercent = parseInt(document.getElementById('carbsPercent').value);
611
+
612
+ // Actualizar valores mostrados
613
+ document.getElementById('proteinPercentValue').textContent = `${proteinPercent}%`;
614
+ document.getElementById('fatPercentValue').textContent = `${fatPercent}%`;
615
+ document.getElementById('carbsPercentValue').textContent = `${carbsPercent}%`;
616
+
617
+ // Calcular total
618
+ const total = proteinPercent + fatPercent + carbsPercent;
619
+ document.getElementById('totalPercent').textContent = `Total: ${total}%`;
620
+
621
+ // Mostrar error si no suma 100%
622
+ const errorElement = document.getElementById('percentError');
623
+ if (total !== 100) {
624
+ errorElement.classList.remove('hidden');
625
+ } else {
626
+ errorElement.classList.add('hidden');
627
+ }
628
+ }
629
+
630
  function calculateBodyfatPercentage() {
631
  const neck = parseFloat(document.getElementById('neck').value);
632
  const waist = parseFloat(document.getElementById('waist').value);
 
666
  const activity = parseFloat(document.getElementById('activity').value);
667
  const goal = document.getElementById('goal').value;
668
  const bodyfat = parseInt(document.getElementById('bodyfat').value) || 20;
669
+ const useCustomMacros = document.getElementById('customMacrosToggle').checked;
670
 
671
  // Validaciones básicas
672
  if (age < 15 || age > 100 || weight < 40 || weight > 200 || height < 140 || height > 220) {
 
674
  return;
675
  }
676
 
677
+ // Validar porcentajes de macros si está usando valores personalizados
678
+ if (useCustomMacros) {
679
+ const proteinPercent = parseInt(document.getElementById('proteinPercent').value);
680
+ const fatPercent = parseInt(document.getElementById('fatPercent').value);
681
+ const carbsPercent = parseInt(document.getElementById('carbsPercent').value);
682
+ const total = proteinPercent + fatPercent + carbsPercent;
683
+
684
+ if (total !== 100) {
685
+ alert('⚠️ La suma de los porcentajes de macronutrientes debe ser exactamente 100%');
686
+ return;
687
+ }
688
+ }
689
+
690
  // Calcular calorías (Harris-Benedict revisada por Mifflin-St Jeor)
691
  let bmr;
692
  if (gender === 'male') {
 
713
  const dailyCalories = Math.round(tdee + calorieAdjustment);
714
 
715
  // Calcular macronutrientes
716
+ let proteinGrams, fatGrams, carbsGrams;
 
 
 
 
 
 
 
 
717
 
718
+ if (useCustomMacros) {
719
+ // Usar porcentajes personalizados
720
+ const proteinPercent = parseInt(document.getElementById('proteinPercent').value);
721
+ const fatPercent = parseInt(document.getElementById('fatPercent').value);
722
+ const carbsPercent = parseInt(document.getElementById('carbsPercent').value);
723
+
724
+ proteinGrams = Math.round((dailyCalories * proteinPercent / 100) / 4);
725
+ fatGrams = Math.round((dailyCalories * fatPercent / 100) / 9);
726
+ carbsGrams = Math.round((dailyCalories * carbsPercent / 100) / 4);
727
+ } else {
728
+ // Usar valores recomendados según objetivo
729
+ // Proteína: 2.2g/kg para pérdida de peso, 1.8g/kg para mantenimiento, 1.6g/kg para aumento
730
+ let proteinPerKg;
731
+ if (goal === 'loss') {
732
+ proteinPerKg = 2.2;
733
+ } else if (goal === 'maintenance') {
734
+ proteinPerKg = 1.8;
735
+ } else {
736
+ proteinPerKg = 1.6;
737
+ }
738
+
739
+ // Ajustar proteína si hay % grasa alto (>25%)
740
+ if (bodyfat > 25) {
741
+ proteinPerKg = Math.min(proteinPerKg + 0.2, 2.5);
742
+ }
743
+
744
+ proteinGrams = Math.round(weight * proteinPerKg);
745
+ const proteinCalories = proteinGrams * 4;
746
+
747
+ // Grasas: 25-35% de calorías
748
+ const fatPercentage = 0.3; // 30%
749
+ const fatCalories = Math.round(dailyCalories * fatPercentage);
750
+ fatGrams = Math.round(fatCalories / 9);
751
+
752
+ // Carbohidratos: resto de calorías
753
+ const carbsCalories = dailyCalories - proteinCalories - fatCalories;
754
+ carbsGrams = Math.round(carbsCalories / 4);
755
  }
756
 
 
 
 
 
 
 
 
 
 
 
 
 
757
  // Agua recomendada
758
  const waterIntake = Math.round((weight * 0.035) * 10) / 10; // 35ml por kg
759
 
 
773
  document.getElementById('fatBar').style.width = `${Math.min(fatGrams / (weight * 1.2) * 100, 100)}%`;
774
 
775
  // Generar recomendaciones
776
+ generateRecommendations(goal, dailyCalories, proteinGrams, carbsGrams, fatGrams, waterIntake, useCustomMacros);
777
 
778
  // Crear/actualizar gráfico
779
  updateChart(proteinGrams, carbsGrams, fatGrams);
 
785
  document.getElementById('results').scrollIntoView({ behavior: 'smooth' });
786
  }
787
 
788
+ function generateRecommendations(goal, calories, protein, carbs, fat, water, customMacros) {
789
  const recommendationsEl = document.getElementById('recommendations');
790
  recommendationsEl.innerHTML = '';
791
 
 
805
 
806
  addRecommendation(goalRecommendation);
807
 
808
+ if (customMacros) {
809
+ addRecommendation('Estás usando una distribución personalizada de macronutrientes 🎛️. Asegúrate de seguir tus porcentajes establecidos.');
810
+ } else {
811
+ // Recomendación basada en valores por defecto
812
+ addRecommendation(`Estás usando valores recomendados de macronutrientes para tu objetivo de ${goal === 'loss' ? 'pérdida' : goal === 'gain' ? 'aumento' : 'mantenimiento'} de peso.`);
813
+ }
814
+
815
  // Recomendación de proteína
816
  addRecommendation(`Consume aproximadamente ${protein}g de proteína diarios 🍗. Buenas fuentes incluyen carnes magras, pescado 🐟, huevos 🥚 y lácteos 🧀.`);
817
 
 
911
 
912
  // Inicializar
913
  setGender('male');
914
+ updateMacroPercentages(); // Para mostrar los valores iniciales
915
  </script>
916
  <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=andyontrade/macros" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
917
  </html>