Last active
February 12, 2025 14:18
-
-
Save ivanhoe011/c34f004506cbbce0032e21980cee51c8 to your computer and use it in GitHub Desktop.
eKupi popust
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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