brandon-barker
8/12/2014 - 2:50 PM

Saving calculator for takealot.com

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>');
        }
    }
});