Skip to content

Instantly share code, notes, and snippets.

@ivanhoe011
Last active February 12, 2025 14:18
Show Gist options
  • Select an option

  • Save ivanhoe011/c34f004506cbbce0032e21980cee51c8 to your computer and use it in GitHub Desktop.

Select an option

Save ivanhoe011/c34f004506cbbce0032e21980cee51c8 to your computer and use it in GitHub Desktop.
eKupi popust
/**
* This code snippet calculates the discount % on eKupi.hr and injects the info for each listing.
*
* Usage: Paste the code int Snippets in Chrome DevTools, open ekupi.hr page of interest,
* right-click the Snipper and choose Run.
*/
$('.price-block').each(function () {
const $this = $(this);
const oldPrice = parseInt($this.find('.item-old-price').text().replace(',00 kn', '').replace('.', ''));
const newPrice = parseInt($this.find('.price').text().replace(',00 kn', '').replace('.', ''));
if (oldPrice && newPrice) {
const diff = oldPrice - newPrice;
const perc = Math.round(100 * diff / oldPrice, 2);
$this.append($('<strong style="color:red"/>').text('POPUST ' + perc + '%'));
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment