Subbu1304 commited on
Commit
ce3593c
·
verified ·
1 Parent(s): fa585f1

Create script.js

Browse files
Files changed (1) hide show
  1. static/script.js +89 -0
static/script.js ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ document.getElementById('submit-btn').addEventListener('click', function () {
2
+ const userMessage = document.getElementById('user-message').value;
3
+ if (!userMessage) return;
4
+ addMessage(userMessage, 'user');
5
+
6
+ if (userMessage.toLowerCase() === 'yes' || userMessage.toLowerCase() === 'yeah') {
7
+ setTimeout(() => {
8
+ addMessage("Great! Please select a food category:", 'bot');
9
+ showCategorySelection();
10
+ }, 1000);
11
+ } else {
12
+ setTimeout(() => {
13
+ addMessage("Okay, let me know if you change your mind!", 'bot');
14
+ }, 1000);
15
+ }
16
+
17
+ document.getElementById('user-message').value = '';
18
+ });
19
+
20
+ function addMessage(message, sender) {
21
+ const messageContainer = document.createElement('div');
22
+ messageContainer.classList.add(sender + '-message');
23
+ messageContainer.textContent = message;
24
+ document.getElementById('chat-box').appendChild(messageContainer);
25
+ document.getElementById('chat-box').scrollTop = document.getElementById('chat-box').scrollHeight;
26
+ }
27
+
28
+ function showCategorySelection() {
29
+ document.getElementById('category-dropdown').hidden = false;
30
+
31
+ document.getElementById('category-dropdown').addEventListener('change', function () {
32
+ const selectedCategory = this.value;
33
+ setTimeout(() => {
34
+ addMessage(`You selected: ${selectedCategory}. Now, please select your nutrition preference.`, 'bot');
35
+ showNutritionSelection();
36
+ }, 1000);
37
+ });
38
+ }
39
+
40
+ function showNutritionSelection() {
41
+ document.getElementById('nutrition-dropdown').hidden = false;
42
+
43
+ document.getElementById('nutrition-dropdown').addEventListener('change', function () {
44
+ const selectedNutrition = this.value;
45
+ setTimeout(() => {
46
+ addMessage(`You selected: ${selectedNutrition}. Here are the ingredients based on your selection:`, 'bot');
47
+ showIngredientsList(selectedNutrition);
48
+ }, 1000);
49
+ });
50
+ }
51
+
52
+ function showIngredientsList(selectedNutrition) {
53
+ const ingredients = {
54
+ "Veg": ["Paneer", "Potato", "Cabbage", "Gobi"],
55
+ "Non-Veg": ["Chicken", "Fish", "Mutton"],
56
+ "Vegan": ["Tofu", "Tempeh", "Seitan"],
57
+ "Pasta & Noodles": ["Whole Wheat Pasta", "Rice Noodles"],
58
+ "Breads & Baked Goods": ["Whole Grain Bread", "Gluten-Free Bread"]
59
+ };
60
+
61
+ const ingredientList = ingredients[selectedCategory] || [];
62
+ const ingredientDropdown = document.getElementById('ingredient-dropdown');
63
+ ingredientDropdown.innerHTML = ingredientList.map(ingredient => `<option value="${ingredient}">${ingredient}</option>`).join('');
64
+
65
+ ingredientDropdown.hidden = false;
66
+
67
+ ingredientDropdown.addEventListener('change', function () {
68
+ const selectedIngredient = this.value;
69
+ setTimeout(() => {
70
+ addMessage(`You selected: ${selectedIngredient}. Here are the food items you can make:`, 'bot');
71
+ showFoodItems(selectedIngredient);
72
+ }, 1000);
73
+ });
74
+ }
75
+
76
+ function showFoodItems(selectedIngredient) {
77
+ const foodItems = {
78
+ "Paneer": ["Paneer Tikka", "Paneer Curry", "Paneer Manchurian", "Paneer Butter Masala"],
79
+ "Potato": ["Aloo Dal", "Potato and Chickpea Salad", "Paneer-Stuffed Potatoes", "Potato and Black Bean Tacos"],
80
+ "Cabbage": ["Cabbage and Chickpea Curry", "Cabbage Stir-Fry with Tofu", "Cabbage and Lentil Soup"],
81
+ "Chicken": ["Grilled Chicken Breast", "Chicken Tikka Masala", "Chicken Stir-Fry", "Chicken Biryani"],
82
+ "Fish": ["Grilled Salmon", "Fish Curry", "Baked Fish with Herbs", "Fish Tacos"],
83
+ "Mutton": ["Mutton Curry", "Mutton Biryani", "Grilled Lamb Chops", "Mutton Rogan Josh"],
84
+ "Tofu": ["Tofu Stir-Fry", "Crispy Tofu Nuggets", "Tofu Scramble", "Tofu Curry"]
85
+ };
86
+
87
+ const dishes = foodItems[selectedIngredient] || [];
88
+ addMessage(dishes.join(", "), 'bot');
89
+ }