Skip to content

Instantly share code, notes, and snippets.

@rileyjshaw
Last active February 12, 2020 22:19
Show Gist options
  • Save rileyjshaw/923b1cd75ce31a640f49dc2e8e7e9e69 to your computer and use it in GitHub Desktop.
Save rileyjshaw/923b1cd75ce31a640f49dc2e8e7e9e69 to your computer and use it in GitHub Desktop.
Long & McQuade is having their blowout sale this weekend which means it's time for me to waste money again
// This script finds the best deals from Long & McQuade's annual
// blowout sale and sorts them within their respective categories.
//
// USAGE:
// 1. Navigate to http://promo.long-mcquade.com/SaleFlyer.php
// 2. Select your nearest location under "View Other Locations' Flyers Here"
// 3. Open your browser's Javascript console
// 4. Paste the contents of this file into the console
// 5. Optionally, replace the value of ONLY_SHOW_DEALS_BELOW_THIS_FRACTION_OF_THE_ORIGINAL_COST
// 6. Optionally, replace the value of I_WILL_NOT_EVEN_CONSIDER_ANYTHING_THAT_COSTS_OVER
// 7. Hit enter
// Change these values to suit your needs.
// Reminder: you don't need anything from this sale.
const ONLY_SHOW_DEALS_BELOW_THIS_FRACTION_OF_THE_ORIGINAL_COST = 1 / 2; // All valid values between 0 and 1.
const I_WILL_NOT_EVEN_CONSIDER_ANYTHING_THAT_COSTS_OVER = 200.00; // Pinky promise!
const parsePrice = price => price.startsWith('$') && parseFloat(price.slice(1).replace(/,/g, ''));
Array.from(document.querySelectorAll('tbody tr'))
.map(tr => {
const cells = tr.querySelectorAll('td');
const originalPrice = parsePrice(cells[cells.length - 2].textContent);
const salePrice = parsePrice(cells[cells.length - 1].textContent);
const isPriceRow = typeof originalPrice === 'number' && typeof salePrice === 'number';
const deal = isPriceRow && salePrice / originalPrice;
const parent = tr.parentNode;
parent.removeChild(tr); // Eek! Side effect!
return {
deal,
element: tr,
show: isPriceRow && salePrice < I_WILL_NOT_EVEN_CONSIDER_ANYTHING_THAT_COSTS_OVER && deal <= ONLY_SHOW_DEALS_BELOW_THIS_FRACTION_OF_THE_ORIGINAL_COST,
parent,
};
})
.filter(row => row.show)
.sort((a, b) => a.deal > b.deal)
.forEach(({deal, element, parent}) => {
const td = document.createElement('td');
td.textContent = `${Math.floor((1 - deal) * 100)}% off`;
element.append(td);
parent.append(element);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment