Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brandon-barker/8674451cce06d31ba0a4 to your computer and use it in GitHub Desktop.
Save brandon-barker/8674451cce06d31ba0a4 to your computer and use it in GitHub Desktop.
Saving calculator for takealot.com
// ==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