-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
75 lines (67 loc) · 3.25 KB
/
Copy pathscript.js
File metadata and controls
75 lines (67 loc) · 3.25 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
document.addEventListener('DOMContentLoaded', () => {
const foodSelect = document.getElementById('foodSelect');
const quantityInput = document.getElementById('quantity');
const symptomsInput = document.getElementById('symptoms');
const addFoodButton = document.getElementById('addFood');
const foodList = document.getElementById('foodList');
const totalCaloriesDisplay = document.getElementById('totalCalories');
const totalOilDisplay = document.getElementById('totalOil');
const bleedDateInput = document.getElementById('bleedDate');
const addBleedButton = document.getElementById('addBleed');
const bleedCalendarDiv = document.getElementById('bleedCalendar');
const predictionText = document.getElementById('predictionText');
const suggestionList = document.getElementById('suggestionList');
const dietDate = document.getElementById('dietDate');
const dateDisplay = document.getElementById('date');
const foodData = [
{ name: 'Rice', calories: 130, oil: 0.3 },
{ name: 'Chicken Breast', calories: 165, oil: 3.6 },
{ name: 'Salmon', calories: 208, oil: 13 },
{ name: 'Broccoli', calories: 55, oil: 0.6 },
{ name: 'Banana', calories: 105, oil: 0.4 },
{ name: 'Oatmeal', calories: 68, oil: 3.3 },
{ name: 'Almonds', calories: 164, oil: 14.2},
{ name: 'Avocado', calories: 160, oil: 14.6},
{name: 'Plain Yogurt', calories: 61, oil: 3.3},
{name: 'Carrot', calories: 41, oil: 0.2},
{name: 'Spinach', calories: 23, oil: 0.1},
];
foodData.forEach(food => {
const option = document.createElement('option');
option.value = food.name;
option.textContent = food.name;
foodSelect.appendChild(option);
});
let dailyDiet = JSON.parse(localStorage.getItem('dailyDiet')) || {};
let bleedingEpisodes = JSON.parse(localStorage.getItem('bleedingEpisodes')) || [];
function updateDate() {
const now = new Date();
const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
dateDisplay.textContent = now.toLocaleDateString('en-US', options);
dietDate.valueAsDate = new Date();
bleedDateInput.valueAsDate = new Date();
}
updateDate();
function updateFoodList() {
const currentDate = dietDate.value;
if (!dailyDiet[currentDate]) {
dailyDiet[currentDate] = [];
}
foodList.innerHTML = '';
let totalCalories = 0;
let totalOil = 0;
dailyDiet[currentDate].forEach(item => {
const li = document.createElement('li');
li.textContent = `<span class="math-inline">\{item\.food\} \(</span>{item.quantity}g) - Symptoms: ${item.symptoms || 'None'}`;
foodList.appendChild(li);
const foodItem = foodData.find(f => f.name === item.food);
if (foodItem) {
totalCalories += (foodItem.calories / 100) * item.quantity;
totalOil += (foodItem.oil / 100) * item.quantity;
}
});
totalCaloriesDisplay.textContent = totalCalories.toFixed(2);
totalOilDisplay.textContent = totalOil.toFixed(2);
localStorage.setItem('dailyDiet', JSON.stringify(dailyDiet));
}
updateFoodList();