forked from Technigo/project-library
-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
297 lines (286 loc) · 10.2 KB
/
script.js
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
const allButton = document.getElementById("allButton");
const fishButton = document.getElementById("fishButton");
const meatButton = document.getElementById("meatButton");
const chickenButton = document.getElementById("chickenButton");
const vegetarianButton = document.getElementById("vegetarianButton");
const surpriseButton = document.getElementById("surpriseButton");
const cookingTimeButton = document.getElementById("cookingTimeButton");
const longestCookingTimeButton = document.getElementById("longestCookingTime");
const buttons = document.getElementsByClassName("button");
const recipes = [
{
name: "Individual vegetarian lasagnes",
cuisineType: ["Vegetarian"],
ingredients: [
"1.2 kg cherry tomatoes",
"5 sprigs of fresh thyme",
"extra virgin olive oil",
"2 shallots",
"2 cloves of garlic",
"500 g baby spinach",
"8-12 fresh or dried lasagne sheets",
"350 g ricotta cheese",
"WHITE SAUCE",
"600 ml milk",
"25 g unsalted butter",
"2 heaped tablespoons flour",
"150 g vegetarian sharp, mature cheese",
"100 g mozzarella",
],
source: "Jamie Oliver",
totalTime: 130,
url: "http://www.jamieoliver.com/recipes/vegetables-recipes/individual-vegetarian-lasagnes/",
image: "./recipe-images/individual-vegetarian-lasagnes.jpg",
},
{
name: "Vegetarian Stir-Fried Garlic Scape",
cuisineType: ["Vegetarian"],
ingredients: [
"8 oz. garlic scapes",
"3 oz. baby corn",
"3 oz. carrots",
"1 oz. dried shiitake mushrooms",
"1 clove of garlic sliced thinly",
"3 slices of fresh ginger root",
"2 tablespoons vegetable oil",
"1/4 cup shaoxing cooking wine",
"1/4 vegetarian stock or water",
"1 tablespoon light soy sauce",
"1 teaspoon sugar",
"1 teaspoon cornstarch",
"1/4 teaspoon ground white pepper",
],
source: "Red Cook",
totalTime: 90,
url: "http://redcook.net/2010/06/16/garlic-scape-an-off-menu-treat/",
image: "./recipe-images/vegetarian-stir-fried-garlic-s.jpg",
},
{
name: "Cheat’s cheesy focaccia",
cuisineType: ["Vegetarian"],
ingredients: [
"500g pack bread mix",
"2 tbsp olive oil , plus a little extra for drizzling",
"25g parmesan (or vegetarian alternative), grated",
"75g dolcelatte cheese (or vegetarian alternative)",
],
source: "BBC Good Food",
totalTime: 40,
url: "https://www.bbcgoodfood.com/recipes/cheats-cheesy-focaccia",
image: "./recipe-images/cheat’s-cheesy-focaccia.jpg",
},
{
name: "Vegetarian Shepherd's Pie",
cuisineType: ["Vegetarian"],
ingredients: [
"2 tablespoons extra-virgin olive oil",
"1 large onion, finely diced",
"2 carrots, peeled and thinly sliced",
"2 celery stalks, thinly sliced",
"10 ounces cremini mushrooms, trimmed and sliced",
"1 tablespoon tomato paste",
"1 tablespoon vegetarian Worcestershire sauce, such as Annie's Naturals",
"1 dried bay leaf",
"1 cup French green lentils, picked over",
"Kosher salt and freshly ground pepper",
"1 cup frozen peas",
"2 pounds Yukon Gold potatoes, scrubbed and cut into 1 1/2-inch pieces",
"4 cloves garlic",
"4 tablespoons unsalted butter",
"1/2 cup whole milk, warmed",
],
source: "Martha Stewart",
totalTime: 120,
url: "https://www.marthastewart.com/1535235/vegetarian-shepherds-pie",
image: "./recipe-images/vegetarian-shepherd's-pie.jpg",
},
{
name: "Chicken Paprikash",
cuisineType: ["Chicken"],
ingredients: [
"640 grams chicken - drumsticks and thighs ( 3 whole chicken legs cut apart)",
"1/2 teaspoon salt",
"1/4 teaspoon black pepper",
"1 tablespoon butter – cultured unsalted (or olive oil)",
"240 grams onion sliced thin (1 large onion)",
"70 grams Anaheim pepper chopped (1 large pepper)",
"25 grams paprika (about 1/4 cup)",
"1 cup chicken stock",
"1/2 teaspoon salt",
"1/2 cup sour cream",
"1 tablespoon flour – all-purpose",
],
source: "No Recipes",
totalTime: 80,
url: "http://norecipes.com/recipe/chicken-paprikash/",
image: "./recipe-images/chicken-paprikash.jpg",
},
{
name: "Baked Chicken",
cuisineType: ["Chicken"],
ingredients: [
"6 bone-in chicken breast halves, or 6 chicken thighs and wings, skin-on",
"1/2 teaspoon coarse salt",
"1/2 teaspoon Mrs. Dash seasoning",
"1/4 teaspoon freshly ground black pepper",
],
source: "Martha Stewart",
totalTime: 90,
url: "http://www.marthastewart.com/318981/baked-chicken",
image: "./recipe-images/baked-chicken.jpg",
},
{
name: "Deep Fried Fish Bones",
cuisineType: ["Fish"],
ingredients: ["8 small whiting fish or smelt", "4 cups vegetable oil"],
source: "Serious Eats",
totalTime: 31,
url: "http://www.seriouseats.com/recipes/2011/03/deep-fried-fish-bones-recipe.html",
image: "./recipe-images/deep-fried-fish-bones.jpg",
},
{
name: "Burnt-Scallion Fish",
cuisineType: ["Fish"],
ingredients: ["2 bunches scallions", "8 tbsp. butter", "2 8-oz. fish filets"],
source: "Saveur",
totalTime: 70,
url: "http://www.saveur.com/article/Recipes/Burnt-Scallion-Fish",
image: "./recipe-images/fish-dish.jpg",
},
{
name: "Curry-Crusted Fish",
cuisineType: ["Fish"],
ingredients: [
"3 slices bread , about 85g/3oz in total",
"1 lime",
"1.0 tbsp Korma curry paste",
"4 thick white fish fillets",
],
source: "BBC Good Food",
totalTime: 80,
url: "http://www.bbcgoodfood.com/recipes/4717/",
image: "./recipe-images/fish-dish.jpg",
},
{
name: "Meat Stock",
cuisineType: ["Meat"],
ingredients: [
"2.5 pounds beef marrow bones",
"1 large onion, quartered",
"2 carrots, sliced",
"1 leek, cleaned and sliced",
"2 celery stalks, sliced",
"2.5 pounds organic beef stew meat, cubed",
"2 tablespoons tomato paste",
"5 cloves garlic",
"2 bay leaves",
"3 sprigs thyme",
"3 sprigs Italian parsley",
"1/2 teaspoon black peppercorns",
],
source: "Food52",
totalTime: 60,
url: "https://food52.com/recipes/3712-meat-stock",
image: "./recipe-images/meat.jpg",
},
{
name: "Homemade Meat Broth",
cuisineType: ["Meat"],
ingredients: [
"1 teaspoon salt",
"1 carrot, peeled",
"1 medium onion, peeled",
"2 or 3 celery stalks",
"¼ red or yellow bell pepper, stripped of all its seeds",
"1 small boiling potato, peeled",
"1 ripe, fresh tomato, or 1 canned Italian plum tomato, drained of juice",
"5 pounds assorted pieces of meat and bones (see meat suggestions above), of which no less than 1½ pounds is all meat",
],
source: "Cookstr",
totalTime: 60,
url: "http://www.cookstr.com/recipes/il-brodo-homemade-meat-broth",
image: "./recipe-images/meat.jpg",
},
{
name: "Spice-Rubbed Grilled Flap Meat (Sirloin Tip) Recipe",
cuisineType: ["Meat"],
ingredients: [
"1 tablespoon whole black peppercorns, toasted",
"1 teaspoon coriander seed, toasted",
"1 teaspoon fennel seed, toasted",
"1 teaspoon cumin pods, toasted",
"1 teaspoon red pepper flakes",
"1/2 teaspoon dried oregano",
"2 medium cloves garlic, minced (about 2 teaspoons)",
"2 tablespoons vegetable or canola oil",
"1 whole flap meat steak, 2 to 2 1/2 pounds",
"Kosher salt",
],
source: "Serious Eats",
totalTime: 240,
url: "http://www.seriouseats.com/recipes/2012/05/spice-rubbed-grilled-flap-meat-sirloin-tip-recipe.html",
image: "./recipe-images/grilled.jpg",
},
];
const displayRecipes = (recipes) => {
recipeContainer.innerHTML = "";
recipes.forEach((recipe) => {
const recipeDiv = document.createElement("div");
recipeDiv.setAttribute("id", "card");
recipeDiv.innerHTML = `
<h3>${recipe.name}</h3>
<img src="${recipe.image}" alt="${recipe.name}" />
<p><strong>Ingredients:</strong></p>
<ul>
${recipe.ingredients.map((ingr) => `<li>${ingr}</li>`).join("")}
</ul>
<p><strong>Source:</strong> ${recipe.source}</p>
<p><strong>Total Time:</strong> ${recipe.totalTime} minutes</p>
`;
recipeContainer.appendChild(recipeDiv);
});
};
displayRecipes(recipes);
const filterRecipesByType = (cuisineType) => {
let filteredRecipes;
if (cuisineType === "all") {
filteredRecipes = recipes;
} else {
filteredRecipes = recipes.filter((recipe) => recipe.cuisineType.includes(cuisineType));
}
displayRecipes(filteredRecipes);
};
const getRandomRecipe = () => {
recipeContainer.innerHTML = "";
recipes[Math.floor(Math.random() * recipes.length)];
const surprise = recipes[Math.floor(Math.random() * recipes.length)];
const recipeDiv = document.createElement("div");
recipeDiv.setAttribute("id", "card");
recipeDiv.innerHTML += `
<h3>${surprise.name}</h3>
<img src="${surprise.image}" alt="${surprise.name}" />
<p><strong>Ingredients:</strong></p>
<ul>
${surprise.ingredients.map((ingr) => `<li>${ingr}</li>`).join("")}
</ul>
<p><strong>Source:</strong> ${surprise.source}</p>
<p><strong>Total Time:</strong> ${surprise.totalTime} minutes</p>
`;
recipeContainer.appendChild(recipeDiv);
};
const sortByShortestCookingTime = () => {
const cookingTime = [...recipes].sort((a, b) => a.totalTime - b.totalTime);
displayRecipes(cookingTime);
};
const sortByLongestCookingTime = () => {
const cookingTime = [...recipes].sort((a, b) => b.totalTime - a.totalTime);
displayRecipes(cookingTime);
};
allButton.addEventListener("click", () => filterRecipesByType("all"));
fishButton.addEventListener("click", () => filterRecipesByType("Fish"));
meatButton.addEventListener("click", () => filterRecipesByType("Meat"));
chickenButton.addEventListener("click", () => filterRecipesByType("Chicken"));
vegetarianButton.addEventListener("click", () => filterRecipesByType("Vegetarian"));
surpriseButton.addEventListener("click", getRandomRecipe);
cookingTimeButton.addEventListener("click", sortByShortestCookingTime);
longestCookingTimeButton.addEventListener("click", sortByLongestCookingTime);