BasSteenbeeke / AH Cart total

// ==UserScript==
// @name     				AH Cart total
// @description             Show a cart total on the shoppingcart page
// @copyright               2019, BasSteenbeeke (https://openuserjs.org/users/BasSteenbeeke)
// @license                 GPL-3.0-or-later
// @author 	 				Bas Steenbeeke
// @match		 			https://www.ah.nl/mijnlijst
// @require 				https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js 
// @run-at                  document-start
// @version  				1
// ==/UserScript==

$(document).on('DOMSubtreeModified', '.shoppinglist-lane', function() {
  	getTotals();
});

function getTotals() {
  	
  	var productrow = 0;	
  	var price = 0;
  	var count = 0;
  	var pricetotal = 0;
  	var total = 0;
  
  	$('body').find('.product').each(function() {
      	price = Number($(this).find('.price').not('.price--was').text());
      	count = $(this).find('.product-controls__item--show-controls__quantity').text();
      
      	// 2e gratis uitzondering (dirty!)
      	if ( $(this).find('.product-description__heading:contains("2e gratis")').length ) {
          if (count >= 2) {
            var newprice = (price / 2);
            price = newprice;
          }
        }
      
      	// 2 voor uitzondering (dirty!)
      	if ( $(this).find('.product-description__heading:contains("2 voor")').length ) {
          if (count >= 2) {
            var str = $(this).find('.product-description__heading').text();
            var lastword = str.split(" ").pop();
            var newprice = parseInt(lastword);
            
            price = newprice;
            
            if(count == 2) {
              pricetotal += price;
            } else {
              pricetotal += (price * count);
            }
          }
        } else {
          pricetotal += (price * count);
        }
      
  	});
  
  
  	var total = pricetotal.toFixed(2);

  	if($('.totals').length)	 {
      $('.totals').html('<div class="totals" style="float: left; font-weight: bold; padding: 0 10px; font-size: 18px;">Totaal: '+total+' -- Dirty!</div>');
    } else {
      $('<div class="totals" style="float: left; font-weight: bold; padding: 0 10px; font-size: 18px;">Totaal: '+total+' -- Dirty!</div>').prependTo('.order-controls');
    }
  
}