Created
August 12, 2014 14:50
-
-
Save brandon-barker/8674451cce06d31ba0a4 to your computer and use it in GitHub Desktop.
Saving calculator for takealot.com
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
// ==UserScript== | |
// @name TakeAlot Saving Calculator | |
// @namespace http://www.takealot.com/ | |
// @version 0.1 | |
// @description Shows % Saving on takealot.com | |
// @match http://www.takealot.com/* | |
// @copyright 2013, Brandon Barker | |
// ==/UserScript== | |
$('.price').each(function (key, value) { | |
var currentPrice = $(value).find('.amount').html(); | |
if (currentPrice != null && currentPrice != undefined) { | |
currentPrice = currentPrice.replace(',', ''); | |
} | |
var oldPrice = $(value).parent().find('.price-was').find('.old-price').html(); | |
if (oldPrice != null && oldPrice != undefined && oldPrice != 'NaN') { | |
oldPrice = oldPrice.replace('Was R ', '').replace(',', ''); | |
} | |
var saving = parseFloat((oldPrice - currentPrice) / oldPrice * 100).toFixed(0); | |
if (saving != undefined && saving != null && saving != 'NaN') { | |
$(value).parent().find('.price-was').append('<br /><p class="savings price">Saving: ' + saving + '%</p>'); | |
if (saving > 40) { | |
$(value).parent().find('.price-was').append('<br /><p class="savings price"><strong>!!! BIG SAVING !!!</strong></p>'); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment