CH&L script to sort by total cost
Discussion
This script sorts the CH&L results by total cost:
Note: author Rory McCrossan
// ==UserScript==
// @name Contract Hire and Leasing Calculator
// @namespace http://rorymccrossan.co.uk
// @version 1.0
// @description Adds helpful information to each deal
// @author Rory McCrossan
// @match http://www.contracthireandleasing.com/personal/*
// @match http://www.contracthireandleasing.com/business/*
// @match https://www.contracthireandleasing.com/personal/*
// @match https://www.contracthireandleasing.com/business/*
// @grant none
// ==/UserScript==
$('<style />', {
text: '.overall-cost { text-align: right; padding: 0; position: absolute; top: 0; left: 0; right: 0; background-color: #DDD; }' +
'.deal .title-wrap { padding: 0 0 0 10px; }' +
'.all-price-wrap { padding: 0 10px 10px 0 }' +
'ul.amortised li { list-style: inherit; display: inline-block; position: relative; padding-left: 15px; text-align: left; margin: 0 5px 0 15px; }' +
'ul.amortised li:before { position: absolute; left: 0; content: "\u25b6"; }' +
'.manufacturer-banner, #ootwWindow, .right-panel, .leaderboard-wrap, .deal-panel h2, .crosslinks, .inline-srb-wrap, footer { display: none; }' +
'.content { margin-top: 0; padding: 5px 3%; }' +
'#btnClose { top: 33px; right: 0; border-left: 5px solid #FFF }' +
'.deal-panel .listing-text { width: 50%; float: left; padding: 7px 0; }' +
'.pagination.posts { width: 50%; clear: none; padding: 0 0 10px; margin: 0;}' +
'.search-button-wrap { width: 25%; float: right; position: relative; padding: 0 }' +
'.keywords-wrap { width: 75%; float: left; margin: 0 }' +
'.adv-options { padding: 0 }' +
'#alldeals .deal { color: #333; background-color: transparent; border: 1px solid #DDD; padding-top: 30px; }' +
'#alldeals .deal:first-child { color: #080; background-color: #ecffef; border-color: #88E886; }' +
'#alldeals .deal:first-child .deal-table { background-color: transparent }' +
'#alldeals .deal:first-child ul.amortised li { font-weight: bold; }' +
'#alldeals .deal:first-child .overall-cost { background-color: #88E886; }'
}).appendTo('head');
$('.pagination.posts').clone(true).insertAfter('.listing-text
$('.search-button-wrap').appendTo('.adv-hold');
$('<div class="deal-container"></div>').appendTo('#alldeals');
$('#alldeals .deal').each(function(i) {
var $deal = $(this);
// price calc
var monthlyPrice = $deal.find('.deal-price').text().replace).replace(',', '');
var initialPayment = parseFloat($deal.find('.deal-user').text().replace).replace(',', ''));
var profileText = $deal.find('.personal-deal-profile').text
var monthRegex = /(\d+)\+(\d+)/gi;
var monthMatches = monthRegex.exec(profileText);
if (isNaN(initialPayment)) {
initialPayment = monthMatches[1] * monthlyPrice;
}
var months = parseInt(monthMatches[2]);
var years = (months + 1) / 12;
var totalCost = ((monthlyPrice * months) + initialPayment).toFixed(2);
var yearlyCost = (totalCost / years).toFixed(2);
var $costDiv = $('<div class="overall-cost" />');
var $amortisedData = $('<ul class="amortised" />').appendTo($costDiv);
$('<li />', {
text: '£' + groupNumber((yearlyCost / 12).toFixed(2)) + ' / mo',
class: 'monthly'
}).prependTo($amortisedData);
$('<li />', {
text: '£' + groupNumber(yearlyCost) + ' / yr',
class: 'yearly'
}).prependTo($amortisedData);
$('<li />', {
text: '£' + groupNumber(totalCost) + ' total',
class: 'total'
}).prependTo($amortisedData);
$deal.data('yearly-costearlyCost).prepend($costDiv);
}).sort(function(a, b) {
return $(a).data('yearly-cost') - $(b).data('yearly-cost');
}).appendTo('.deal-container');
function toFloat(input) {
return parseFloat(input.replace(/[^0-9\.]+/g,""));
}
function groupNumber(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
Note: author Rory McCrossan
// ==UserScript==
// @name Contract Hire and Leasing Calculator
// @namespace http://rorymccrossan.co.uk
// @version 1.0
// @description Adds helpful information to each deal
// @author Rory McCrossan
// @match http://www.contracthireandleasing.com/personal/*
// @match http://www.contracthireandleasing.com/business/*
// @match https://www.contracthireandleasing.com/personal/*
// @match https://www.contracthireandleasing.com/business/*
// @grant none
// ==/UserScript==
$('<style />', {
text: '.overall-cost { text-align: right; padding: 0; position: absolute; top: 0; left: 0; right: 0; background-color: #DDD; }' +
'.deal .title-wrap { padding: 0 0 0 10px; }' +
'.all-price-wrap { padding: 0 10px 10px 0 }' +
'ul.amortised li { list-style: inherit; display: inline-block; position: relative; padding-left: 15px; text-align: left; margin: 0 5px 0 15px; }' +
'ul.amortised li:before { position: absolute; left: 0; content: "\u25b6"; }' +
'.manufacturer-banner, #ootwWindow, .right-panel, .leaderboard-wrap, .deal-panel h2, .crosslinks, .inline-srb-wrap, footer { display: none; }' +
'.content { margin-top: 0; padding: 5px 3%; }' +
'#btnClose { top: 33px; right: 0; border-left: 5px solid #FFF }' +
'.deal-panel .listing-text { width: 50%; float: left; padding: 7px 0; }' +
'.pagination.posts { width: 50%; clear: none; padding: 0 0 10px; margin: 0;}' +
'.search-button-wrap { width: 25%; float: right; position: relative; padding: 0 }' +
'.keywords-wrap { width: 75%; float: left; margin: 0 }' +
'.adv-options { padding: 0 }' +
'#alldeals .deal { color: #333; background-color: transparent; border: 1px solid #DDD; padding-top: 30px; }' +
'#alldeals .deal:first-child { color: #080; background-color: #ecffef; border-color: #88E886; }' +
'#alldeals .deal:first-child .deal-table { background-color: transparent }' +
'#alldeals .deal:first-child ul.amortised li { font-weight: bold; }' +
'#alldeals .deal:first-child .overall-cost { background-color: #88E886; }'
}).appendTo('head');
$('.pagination.posts').clone(true).insertAfter('.listing-text
$('.search-button-wrap').appendTo('.adv-hold');
$('<div class="deal-container"></div>').appendTo('#alldeals');
$('#alldeals .deal').each(function(i) {
var $deal = $(this);
// price calc
var monthlyPrice = $deal.find('.deal-price').text().replace).replace(',', '');
var initialPayment = parseFloat($deal.find('.deal-user').text().replace).replace(',', ''));
var profileText = $deal.find('.personal-deal-profile').text
var monthRegex = /(\d+)\+(\d+)/gi;
var monthMatches = monthRegex.exec(profileText);
if (isNaN(initialPayment)) {
initialPayment = monthMatches[1] * monthlyPrice;
}
var months = parseInt(monthMatches[2]);
var years = (months + 1) / 12;
var totalCost = ((monthlyPrice * months) + initialPayment).toFixed(2);
var yearlyCost = (totalCost / years).toFixed(2);
var $costDiv = $('<div class="overall-cost" />');
var $amortisedData = $('<ul class="amortised" />').appendTo($costDiv);
$('<li />', {
text: '£' + groupNumber((yearlyCost / 12).toFixed(2)) + ' / mo',
class: 'monthly'
}).prependTo($amortisedData);
$('<li />', {
text: '£' + groupNumber(yearlyCost) + ' / yr',
class: 'yearly'
}).prependTo($amortisedData);
$('<li />', {
text: '£' + groupNumber(totalCost) + ' total',
class: 'total'
}).prependTo($amortisedData);
$deal.data('yearly-costearlyCost).prepend($costDiv);
}).sort(function(a, b) {
return $(a).data('yearly-cost') - $(b).data('yearly-cost');
}).appendTo('.deal-container');
function toFloat(input) {
return parseFloat(input.replace(/[^0-9\.]+/g,""));
}
function groupNumber(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
Accelebrate said:
This is my working version, I think PH messes up some of the syntax:
https://gist.github.com/ianhampton/3a1760df294bec2...
https://gist.github.com/ianhampton/3a1760df294bec2...
I changed the version from github, on line 42 where it says .deal-user change it to say .personal-deal-upfront
i.e.
instead of:-
var initialPayment = parseFloat($deal.find('.deal-user').text().replace('£', '').replace(',', ''));
have the line
var initialPayment = parseFloat($deal.find('.personal-deal-upfront').text().replace('£', '').replace(',', ''));
i.e.
instead of:-
var initialPayment = parseFloat($deal.find('.deal-user').text().replace('£', '').replace(',', ''));
have the line
var initialPayment = parseFloat($deal.find('.personal-deal-upfront').text().replace('£', '').replace(',', ''));
mrunderhill said:
I changed the version from github, on line 42 where it says .deal-user change it to say .personal-deal-upfront
i.e.
instead of:-
var initialPayment = parseFloat($deal.find('.deal-user').text().replace('£', '').replace(',', ''));
have the line
var initialPayment = parseFloat($deal.find('.personal-deal-upfront').text().replace('£', '').replace(',', ''));
Close, should be this:i.e.
instead of:-
var initialPayment = parseFloat($deal.find('.deal-user').text().replace('£', '').replace(',', ''));
have the line
var initialPayment = parseFloat($deal.find('.personal-deal-upfront').text().replace('£', '').replace(',', ''));
var initialPayment = parseFloat($deal.find('.personal-deal-upfront').text().replace(',', ''));
PP - thanks for emailing me your script. I still can't get it to work though. 
You can see it's enabled through Tampermonkey but my results aren't being sorted or anything.

Anyone else having issues?
This is the code I'm using:
$('<style />', {
text: '.overall-cost { text-align: right; padding: 0; position: absolute; top: 0; left: 0; right: 0; background-color: #DDD; }' +
'.deal .title-wrap { padding: 0 0 0 10px; }' +
'.all-price-wrap { padding: 0 10px 10px 0 }' +
'ul.amortised li { list-style: inherit; display: inline-block; position: relative; padding-left: 15px; text-align: left; margin: 0 5px 0 15px; }' +
'ul.amortised li:before { position: absolute; left: 0; content: "\u25b6"; }' +
'.manufacturer-banner, #ootwWindow, .right-panel, .leaderboard-wrap, .deal-panel h2, .crosslinks, .inline-srb-wrap, footer { display: none; }' +
'.content { margin-top: 0; padding: 5px 3%; }' +
'#btnClose { top: 33px; right: 0; border-left: 5px solid #FFF }' +
'.deal-panel .listing-text { width: 50%; float: left; padding: 7px 0; }' +
'.pagination.posts { width: 50%; clear: none; padding: 0 0 10px; margin: 0;}' +
'.search-button-wrap { width: 25%; float: right; position: relative; padding: 0 }' +
'.keywords-wrap { width: 75%; float: left; margin: 0 }' +
'.adv-options { padding: 0 }' +
'#alldeals .deal { color: #333; background-color: transparent; border: 1px solid #DDD; padding-top: 30px; }' +
'#alldeals .deal:first-child { color: #080; background-color: #ecffef; border-color: #88E886; }' +
'#alldeals .deal:first-child .deal-table { background-color: transparent }' +
'#alldeals .deal:first-child ul.amortised li { font-weight: bold; }' +
'#alldeals .deal:first-child .overall-cost { background-color: #88E886; }'
}).appendTo('head');
$('.pagination.posts').clone(true).insertAfter('.listing-text');
$('.search-button-wrap').appendTo('.adv-hold');
$('<div class="deal-container"></div>').appendTo('#alldeals');
$('#alldeals .deal').each(function(i) {
var $deal = $(this);
// price calc
var monthlyPrice = $deal.find('.deal-price').text().replace('�', '').replace(',', '');
var initialPayment = parseFloat($deal.find('.personal-deal-upfront').text().replace(',', ''));
var profileText = $deal.find('.personal-deal-profile').text();
var monthRegex = /(\d+)\+(\d+)/gi;
var monthMatches = monthRegex.exec(profileText);
if (isNaN(initialPayment)) {
initialPayment = monthMatches[1] * monthlyPrice;
}
var months = parseInt(monthMatches[2]);
var years = (months + 1) / 12;
var totalCost = ((monthlyPrice * months) + initialPayment).toFixed(2);
var yearlyCost = (totalCost / years).toFixed(2);
var $costDiv = $('<div class="overall-cost" />');
var $amortisedData = $('<ul class="amortised" />').appendTo($costDiv);
$('<li />', {
text: '�' + groupNumber((yearlyCost / 12).toFixed(2)) + ' / mo',
class: 'monthly'
}).prependTo($amortisedData);
$('<li />', {
text: '�' + groupNumber(yearlyCost) + ' / yr',
class: 'yearly'
}).prependTo($amortisedData);
$('<li />', {
text: '�' + groupNumber(totalCost) + ' total',
class: 'total'
}).prependTo($amortisedData);
$deal.data('yearly-cost', yearlyCost).prepend($costDiv); }).sort(function(a, b) {
return $(a).data('yearly-cost') - $(b).data('yearly-cost'); }).appendTo('.deal-container');
function toFloat(input) {
return parseFloat(input.replace(/[^0-9\.]+/g,""));
}
function groupNumber(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); }

You can see it's enabled through Tampermonkey but my results aren't being sorted or anything.
Anyone else having issues?
This is the code I'm using:
$('<style />', {
text: '.overall-cost { text-align: right; padding: 0; position: absolute; top: 0; left: 0; right: 0; background-color: #DDD; }' +
'.deal .title-wrap { padding: 0 0 0 10px; }' +
'.all-price-wrap { padding: 0 10px 10px 0 }' +
'ul.amortised li { list-style: inherit; display: inline-block; position: relative; padding-left: 15px; text-align: left; margin: 0 5px 0 15px; }' +
'ul.amortised li:before { position: absolute; left: 0; content: "\u25b6"; }' +
'.manufacturer-banner, #ootwWindow, .right-panel, .leaderboard-wrap, .deal-panel h2, .crosslinks, .inline-srb-wrap, footer { display: none; }' +
'.content { margin-top: 0; padding: 5px 3%; }' +
'#btnClose { top: 33px; right: 0; border-left: 5px solid #FFF }' +
'.deal-panel .listing-text { width: 50%; float: left; padding: 7px 0; }' +
'.pagination.posts { width: 50%; clear: none; padding: 0 0 10px; margin: 0;}' +
'.search-button-wrap { width: 25%; float: right; position: relative; padding: 0 }' +
'.keywords-wrap { width: 75%; float: left; margin: 0 }' +
'.adv-options { padding: 0 }' +
'#alldeals .deal { color: #333; background-color: transparent; border: 1px solid #DDD; padding-top: 30px; }' +
'#alldeals .deal:first-child { color: #080; background-color: #ecffef; border-color: #88E886; }' +
'#alldeals .deal:first-child .deal-table { background-color: transparent }' +
'#alldeals .deal:first-child ul.amortised li { font-weight: bold; }' +
'#alldeals .deal:first-child .overall-cost { background-color: #88E886; }'
}).appendTo('head');
$('.pagination.posts').clone(true).insertAfter('.listing-text');
$('.search-button-wrap').appendTo('.adv-hold');
$('<div class="deal-container"></div>').appendTo('#alldeals');
$('#alldeals .deal').each(function(i) {
var $deal = $(this);
// price calc
var monthlyPrice = $deal.find('.deal-price').text().replace('�', '').replace(',', '');
var initialPayment = parseFloat($deal.find('.personal-deal-upfront').text().replace(',', ''));
var profileText = $deal.find('.personal-deal-profile').text();
var monthRegex = /(\d+)\+(\d+)/gi;
var monthMatches = monthRegex.exec(profileText);
if (isNaN(initialPayment)) {
initialPayment = monthMatches[1] * monthlyPrice;
}
var months = parseInt(monthMatches[2]);
var years = (months + 1) / 12;
var totalCost = ((monthlyPrice * months) + initialPayment).toFixed(2);
var yearlyCost = (totalCost / years).toFixed(2);
var $costDiv = $('<div class="overall-cost" />');
var $amortisedData = $('<ul class="amortised" />').appendTo($costDiv);
$('<li />', {
text: '�' + groupNumber((yearlyCost / 12).toFixed(2)) + ' / mo',
class: 'monthly'
}).prependTo($amortisedData);
$('<li />', {
text: '�' + groupNumber(yearlyCost) + ' / yr',
class: 'yearly'
}).prependTo($amortisedData);
$('<li />', {
text: '�' + groupNumber(totalCost) + ' total',
class: 'total'
}).prependTo($amortisedData);
$deal.data('yearly-cost', yearlyCost).prepend($costDiv); }).sort(function(a, b) {
return $(a).data('yearly-cost') - $(b).data('yearly-cost'); }).appendTo('.deal-container');
function toFloat(input) {
return parseFloat(input.replace(/[^0-9\.]+/g,""));
}
function groupNumber(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); }
I use Greasemonkey on Firefox and don't have any other special settings. Patched the script with the suggestion from yesterday on both my computers and it works. Except as stated above by Wemorgan, sometimes can find lower prices on second page. But the more filters applied, the better results.
Even yesterday, it worked ok when I filtered by brand and model. Just didn't work when I had too many results without filters.
Even yesterday, it worked ok when I filtered by brand and model. Just didn't work when I had too many results without filters.
Magic_Mike said:
Anyone else having issues with this since the change to the website? I've added the new address and Chrome has found a matching script, however it doesn't seem to be doing anything. Thanks
No issues with the changes I posted earlier. Make sure you haven't used "www.leasing.com" by mistake - There's no "www." prefix now.Looks like a really powerful tool, but there's some instructions that us mere mortals are missing here I think?
I have copied and pasted the script, in full from the OP from the first // to the last }, with the addition of the two new..
// @match *://leasing.com/personal/*
// @match *://leasing.com/business/*
..links and I have saved it. But I am not sure what to do now? How do you 'launch', or 'run' or 'open' it? I have tried opening the 'homepage' once I saved it but it just presents me with an error.
Using Chrome
I have copied and pasted the script, in full from the OP from the first // to the last }, with the addition of the two new..
// @match *://leasing.com/personal/*
// @match *://leasing.com/business/*
..links and I have saved it. But I am not sure what to do now? How do you 'launch', or 'run' or 'open' it? I have tried opening the 'homepage' once I saved it but it just presents me with an error.
Using Chrome
Edited by Noz85 on Monday 2nd July 08:53
Edited by Noz85 on Monday 2nd July 08:54
Hi, i've got this to run on the page, but it isn't returning the summary:
Could someone post a known good script as of today please?
{ // ==UserScript==
// @name Contract Hire and Leasing Calculator
// @namespace http://rorymccrossan.co.uk
// @version 1.0
// @description Adds helpful information to each deal
// @author Rory McCrossan
// @match *://leasing.com/personal/*
// @match *://leasing.com/business/*
// @grant none
// ==/UserScript==
$('<style />', {
text: '.overall-cost { text-align: right; padding: 0; position: absolute; top: 0; left: 0; right: 0; background-color: #DDD; }' +
'.deal .title-wrap { padding: 0 0 0 10px; }' +
'.all-price-wrap { padding: 0 10px 10px 0 }' +
'ul.amortised li { list-style: inherit; display: inline-block; position: relative; padding-left: 15px; text-align: left; margin: 0 5px 0 15px; }' +
'ul.amortised li:before { position: absolute; left: 0; content: "\u25b6"; }' +
'.manufacturer-banner, #ootwWindow, .right-panel, .leaderboard-wrap, .deal-panel h2, .crosslinks, .inline-srb-wrap, footer { display: none; }' +
'.content { margin-top: 0; padding: 5px 3%; }' +
'#btnClose { top: 33px; right: 0; border-left: 5px solid #FFF }' +
'.deal-panel .listing-text { width: 50%; float: left; padding: 7px 0; }' +
'.pagination.posts { width: 50%; clear: none; padding: 0 0 10px; margin: 0;}' +
'.search-button-wrap { width: 25%; float: right; position: relative; padding: 0 }' +
'.keywords-wrap { width: 75%; float: left; margin: 0 }' +
'.adv-options { padding: 0 }' +
'#alldeals .deal { color: #333; background-color: transparent; border: 1px solid #DDD; padding-top: 30px; }' +
'#alldeals .deal:first-child { color: #080; background-color: #ecffef; border-color: #88E886; }' +
'#alldeals .deal:first-child .deal-table { background-color: transparent }' +
'#alldeals .deal:first-child ul.amortised li { font-weight: bold; }' +
'#alldeals .deal:first-child .overall-cost { background-color: #88E886; }'
}).appendTo('head');
$('.pagination.posts').clone(true).insertAfter('.listing-text');
$('.search-button-wrap').appendTo('.adv-hold');
$('<div class="deal-container"></div>').appendTo('#alldeals');
$('#alldeals .deal').each(function(i) {
var $deal = $(this);
// price calc
var monthlyPrice = $deal.find('.deal-price').text().replace('£', '').replace(',', '');
var initialPayment = parseFloat($deal.find('.deal-user').text().replace('£', '').replace(',', ''));
var profileText = $deal.find('.deal-profile').text
var monthRegex = /(\d+)\+(\d+)/gi;
var monthMatches = monthRegex.exec(profileText);
if (isNaN(initialPayment)) {
initialPayment = monthMatches[1] * monthlyPrice;
}
var months = parseInt(monthMatches[2]);
var years = (months + 1) / 12;
var totalCost = ((monthlyPrice * months) + initialPayment).toFixed(2);
var yearlyCost = (totalCost / years).toFixed(2);
var $costDiv = $('<div class="overall-cost" />');
var $amortisedData = $('<ul class="amortised" />').appendTo($costDiv);
$('<li />', {
text: '£' + groupNumber((yearlyCost / 12).toFixed(2)) + ' / mo',
class: 'monthly'
}).prependTo($amortisedData);
$('<li />', {
text: '£' + groupNumber(yearlyCost) + ' / yr',
class: 'yearly'
}).prependTo($amortisedData);
$('<li />', {
text: '£' + groupNumber(totalCost) + ' total',
class: 'total'
}).prependTo($amortisedData);
$deal.data('yearly-cost', yearlyCost).prepend($costDiv);
}).sort(function(a, b) {
return $(a).data('yearly-cost') - $(b).data('yearly-cost');
}).appendTo('.deal-container');
function toFloat(input) {
return parseFloat(input.replace(/[^0-9\.]+/g,""));
}
function groupNumber(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
} }
Could someone post a known good script as of today please?
{ // ==UserScript==
// @name Contract Hire and Leasing Calculator
// @namespace http://rorymccrossan.co.uk
// @version 1.0
// @description Adds helpful information to each deal
// @author Rory McCrossan
// @match *://leasing.com/personal/*
// @match *://leasing.com/business/*
// @grant none
// ==/UserScript==
$('<style />', {
text: '.overall-cost { text-align: right; padding: 0; position: absolute; top: 0; left: 0; right: 0; background-color: #DDD; }' +
'.deal .title-wrap { padding: 0 0 0 10px; }' +
'.all-price-wrap { padding: 0 10px 10px 0 }' +
'ul.amortised li { list-style: inherit; display: inline-block; position: relative; padding-left: 15px; text-align: left; margin: 0 5px 0 15px; }' +
'ul.amortised li:before { position: absolute; left: 0; content: "\u25b6"; }' +
'.manufacturer-banner, #ootwWindow, .right-panel, .leaderboard-wrap, .deal-panel h2, .crosslinks, .inline-srb-wrap, footer { display: none; }' +
'.content { margin-top: 0; padding: 5px 3%; }' +
'#btnClose { top: 33px; right: 0; border-left: 5px solid #FFF }' +
'.deal-panel .listing-text { width: 50%; float: left; padding: 7px 0; }' +
'.pagination.posts { width: 50%; clear: none; padding: 0 0 10px; margin: 0;}' +
'.search-button-wrap { width: 25%; float: right; position: relative; padding: 0 }' +
'.keywords-wrap { width: 75%; float: left; margin: 0 }' +
'.adv-options { padding: 0 }' +
'#alldeals .deal { color: #333; background-color: transparent; border: 1px solid #DDD; padding-top: 30px; }' +
'#alldeals .deal:first-child { color: #080; background-color: #ecffef; border-color: #88E886; }' +
'#alldeals .deal:first-child .deal-table { background-color: transparent }' +
'#alldeals .deal:first-child ul.amortised li { font-weight: bold; }' +
'#alldeals .deal:first-child .overall-cost { background-color: #88E886; }'
}).appendTo('head');
$('.pagination.posts').clone(true).insertAfter('.listing-text');
$('.search-button-wrap').appendTo('.adv-hold');
$('<div class="deal-container"></div>').appendTo('#alldeals');
$('#alldeals .deal').each(function(i) {
var $deal = $(this);
// price calc
var monthlyPrice = $deal.find('.deal-price').text().replace('£', '').replace(',', '');
var initialPayment = parseFloat($deal.find('.deal-user').text().replace('£', '').replace(',', ''));
var profileText = $deal.find('.deal-profile').text
var monthRegex = /(\d+)\+(\d+)/gi;
var monthMatches = monthRegex.exec(profileText);
if (isNaN(initialPayment)) {
initialPayment = monthMatches[1] * monthlyPrice;
}
var months = parseInt(monthMatches[2]);
var years = (months + 1) / 12;
var totalCost = ((monthlyPrice * months) + initialPayment).toFixed(2);
var yearlyCost = (totalCost / years).toFixed(2);
var $costDiv = $('<div class="overall-cost" />');
var $amortisedData = $('<ul class="amortised" />').appendTo($costDiv);
$('<li />', {
text: '£' + groupNumber((yearlyCost / 12).toFixed(2)) + ' / mo',
class: 'monthly'
}).prependTo($amortisedData);
$('<li />', {
text: '£' + groupNumber(yearlyCost) + ' / yr',
class: 'yearly'
}).prependTo($amortisedData);
$('<li />', {
text: '£' + groupNumber(totalCost) + ' total',
class: 'total'
}).prependTo($amortisedData);
$deal.data('yearly-cost', yearlyCost).prepend($costDiv);
}).sort(function(a, b) {
return $(a).data('yearly-cost') - $(b).data('yearly-cost');
}).appendTo('.deal-container');
function toFloat(input) {
return parseFloat(input.replace(/[^0-9\.]+/g,""));
}
function groupNumber(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
} }
Gassing Station | Car Buying | Top of Page | What's New | My Stuff


