Skip to content

Instantly share code, notes, and snippets.

@masonwan
Created February 24, 2025 01:17
Show Gist options
  • Save masonwan/83334e654e59425b877502b5b9deadb6 to your computer and use it in GitHub Desktop.
Save masonwan/83334e654e59425b877502b5b9deadb6 to your computer and use it in GitHub Desktop.
The script works with HelloFresh.com. It fades out veggie, vegan, no-cook, or anything with extra fee. It works best to be a bookmarklet.
const unwantedTags = [
'Veggie',
'Vegan',
'No Cook',
]
const menuElms = [...document.querySelectorAll(`#page > div > div > div > div > div.sc-54d3413f-0.cWKOLc > div.sc-54d3413f-0.cAaXLm > div > div > div`)]
const meals = menuElms
.map((menuElm, i) => {
fadeOutUnwantedMeals(menuElm)
const observer = new MutationObserver((mutationList, observer) => {
for (const mutation of mutationList) {
fadeOutUnwantedMeals(mutation.target)
}
})
observer.observe(menuElm, { childList: true })
return {
position: i,
menuElm,
observer,
}
})
function fadeOutUnwantedMeals(target) {
const nameElm = target.querySelector(`.dIgmZW`)
if (nameElm == null) {
return
}
const name = nameElm.textContent
const productTags = [...target.querySelectorAll(`ul > li`)]
.map((productTagElm) => productTagElm.textContent)
const isUnwanted = unwantedTags.some(tag => productTags.includes(tag))
const needAdditionalPrice = (target.querySelector(`.dKJIqe`) != null)
console.log({
name,
productTags: productTags.join(','),
isUnwanted,
needAdditionalPrice,
})
if (isUnwanted) {
console.log(`${name}: Fade the veggie options`)
target.style.opacity = 0.5
return
}
if (needAdditionalPrice) {
console.log(`${name}: Fade the meals that need fee`)
target.style.opacity = 0.5
return
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment