Skip to content

Commit 803046e

Browse files
committed
[userscript] nourishd-meal-highlighter: fix script for new meal selector
1 parent 0a1b042 commit 803046e

File tree

2 files changed

+47
-44
lines changed

2 files changed

+47
-44
lines changed

userscripts/nourishd-meal-highlighter/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
// @supportURL https://github.com/0xdevalias/userscripts/issues
1010
// @downloadURL https://github.com/0xdevalias/userscripts/raw/main/userscripts/nourishd-meal-highlighter/nourishd-meal-highlighter.user.js
1111
// @namespace https://www.devalias.net/
12-
// @version 0.1.4
13-
// @match https://nourishd.com.au/account
12+
// @version 0.1.5
13+
// @match https://nourishd.com.au/menu
1414
// @grant none
1515
// ==/UserScript==
1616
```

userscripts/nourishd-meal-highlighter/nourishd-meal-highlighter.user.js

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
// @supportURL https://github.com/0xdevalias/userscripts/issues
77
// @downloadURL https://github.com/0xdevalias/userscripts/raw/main/userscripts/nourishd-meal-highlighter/nourishd-meal-highlighter.user.js
88
// @namespace https://www.devalias.net/
9-
// @version 0.1.4
10-
// @match https://nourishd.com.au/account
9+
// @version 0.1.5
10+
// @match https://nourishd.com.au/menu
1111
// @grant none
1212
// ==/UserScript==
1313

@@ -139,9 +139,9 @@
139139

140140
const validPortionSizes = ["Regular", "Large", "Extra Large"];
141141

142-
const mealsContainerSelector = 'div[x-show="currentTab === \'my-meals\'"]';
143-
const mealTitleSelector = 'div > a > h4';
144-
const mealsSelector = 'div > div:has(> a > div.meal-slider-image)';
142+
const mealsContainerSelector = 'main .container';
143+
const mealsSelector = '.product-card';
144+
const mealTitleSelector = '.add-to-cart-box a';
145145
const mealImageSelector = '.meal-slider-image > img, .meal-slider-image > video';
146146
const mealSizeQuantityAddSectionSelector = 'div:has(div > div > div > select), div:has(div > div > div > input)';
147147

@@ -180,7 +180,8 @@
180180
}
181181

182182
function setDefaultPortionSize(meal, portionSize) {
183-
const selectElement = meal.querySelector('select[name="product_variant"]');
183+
const selectElement = meal.querySelector('select[wire\\:model="selectedVariantId"]');
184+
184185
if (selectElement && portionSize) {
185186
const desiredOption = Array.from(selectElement.options).find((option) =>
186187
option.textContent.includes(portionSize)
@@ -210,46 +211,48 @@
210211

211212
debugLog('processMeals->meals.forEach', title, { titleElement, meal });
212213

213-
if (!title) return;
214-
215-
if (mealsToHighlight.includes(title)) {
216-
debugLog('processMeals->meals.forEach->mealsToHighlight.includes', title);
217-
218-
styleAsHighlighted(meal);
219-
} else if (mealsToIgnore.includes(title)) {
220-
debugLog('processMeals->meals.forEach->mealsToIgnore.includes', title);
221-
222-
styleAsIgnored(meal);
223-
} else {
224-
debugLog('processMeals->meals.forEach->unknown', title);
225-
226-
styleAsUnknown(meal);
214+
if (title) {
215+
if (mealsToHighlight.includes(title)) {
216+
debugLog('processMeals->meals.forEach->mealsToHighlight.includes', title);
217+
218+
styleAsHighlighted(meal);
219+
} else if (mealsToIgnore.includes(title)) {
220+
debugLog('processMeals->meals.forEach->mealsToIgnore.includes', title);
221+
222+
styleAsIgnored(meal);
223+
} else {
224+
debugLog('processMeals->meals.forEach->unknown', title);
225+
226+
styleAsUnknown(meal);
227+
}
228+
229+
// Removing the excess padding/margin below the meal image
230+
// meal.classList.remove('pb-10', 'mb-10');
231+
// meal.classList.add('mb-2');
232+
233+
// Ensure the meal title contrasts against the background
234+
titleElement.classList.add("text-white");
235+
// meal.classList.add("text-white");
236+
237+
// TODO: Re-add something here to make it reduce the size of the entire box to fit the smaller image?
238+
// const mealImageElement = meal.querySelector(mealImageSelector);
239+
// debugLog('mealImageElement', { mealImageElement });
240+
// if (mealImageElement) {
241+
// mealImageElement.classList.remove('w-full', 'h-full');
242+
// mealImageElement.classList.add('w-1/2', 'h-1/2', 'mx-auto');
243+
// }
244+
245+
// const sizeQuantityAddMealSection = meal.querySelector(mealSizeQuantityAddSectionSelector);
246+
// debugLog('sizeQuantityAddMealSection', { sizeQuantityAddMealSection });
247+
// if (sizeQuantityAddMealSection) {
248+
// // Ensure there is an even amount of left/right padding around the size/quanity/etc section
249+
// sizeQuantityAddMealSection.classList.remove("md:pl-6")
250+
// sizeQuantityAddMealSection.classList.add("px-6")
251+
// }
227252
}
228253

229254
// Select our desired portion size in the dropdown
230255
setDefaultPortionSize(meal, defaultPortionSize);
231-
232-
// Removing the excess padding/margin below the meal image
233-
meal.classList.remove('pb-10', 'mb-10');
234-
meal.classList.add('mb-2');
235-
236-
// Ensure the meal title contrasts against the background
237-
titleElement.classList.add("text-white");
238-
239-
const mealImageElement = meal.querySelector(mealImageSelector);
240-
debugLog('mealImageElement', { mealImageElement });
241-
if (mealImageElement) {
242-
mealImageElement.classList.remove('w-full', 'h-full');
243-
mealImageElement.classList.add('w-1/2', 'h-1/2', 'mx-auto');
244-
}
245-
246-
const sizeQuantityAddMealSection = meal.querySelector(mealSizeQuantityAddSectionSelector);
247-
debugLog('sizeQuantityAddMealSection', { sizeQuantityAddMealSection });
248-
if (sizeQuantityAddMealSection) {
249-
// Ensure there is an even amount of left/right padding around the size/quanity/etc section
250-
sizeQuantityAddMealSection.classList.remove("md:pl-6")
251-
sizeQuantityAddMealSection.classList.add("px-6")
252-
}
253256
});
254257
}
255258

0 commit comments

Comments
 (0)