DEV Community

I built a userscript and Firefox add-on that checks if EU discounts are real

Every November the same thing happens: prices go up a little in October, then "drop" by 40% for Black Friday. In the EU there is actually a rule against this.

I built truediscount to make that rule visible while you shop.

The rule: Omnibus 30-day lowest price

Since 2022 the EU Omnibus Directive (Article 6a of the Price Indication Directive) says that when a shop announces a price reduction, the "before" price must be the lowest price it charged in the previous 30 days. Not the RRP, not a price from last spring.

Many shops now print this "lowest price in the last 30 days" somewhere on the page, often in small grey text far from the big red percentage.

So the honest discount is: (30-day lowest price minus current price) divided by the 30-day lowest price. Sometimes that number is much smaller than the badge. Sometimes it is zero or negative.

What truediscount does

  • Finds the current price, the advertised "was" price and the 30-day lowest price on a product page
  • Recalculates the discount against the 30-day lowest price and shows it next to the shop's claim
  • Keeps a small local price history so you can see a graph of prices you have already seen
  • Stores everything locally in the browser. No account, no server, no tracking

Three ways to install

Userscript (Greasy Fork). If you already use Tampermonkey, Violentmonkey or similar, this is the fastest option: https://greasyfork.org/en/scripts/602599-truediscount-is-this-discount-real

Firefox add-on. The add-on is currently in review on addons.mozilla.org. Until it is approved you can grab the Firefox zip from the GitHub releases.

Chrome-based browsers. Load the Chrome zip from the releases page as an unpacked extension.

A few things I learned

  • Price parsing is the hard part. "1.299,00 €", "€1,299.00" and "1 299,00 zΕ‚" all need to end up as the same number. I normalise by locale and treat the last separator followed by exactly two digits as the decimal mark.
  • Shops phrase the 30-day price differently in every language. "Niedrigster Preis der letzten 30 Tage", "prix le plus bas des 30 derniers jours", "najniΕΌsza cena z 30 dni" and so on. The extension keeps a list of phrases per language and searches near the price block.
  • One codebase, several targets. The MV3 extension and the userscript share the detection code. A small build script produces the Firefox zip, the Chrome zip and the .user.js from the same source.
  • Local-only is a feature. Not having a backend made the privacy policy short and the review process simple.

Try it, break it

The code is MIT licensed: https://github.com/emirmrkaljevic/truediscount

If you find a shop where detection fails, an issue with the product URL is the most helpful thing you can send.

Happy (honest) Black Friday shopping.

AI tools helped with editing this post.

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.