Skip to content

Instantly share code, notes, and snippets.

@goffreder
Last active August 29, 2015 14:23
Show Gist options
  • Save goffreder/768852992640c32f7be5 to your computer and use it in GitHub Desktop.
Save goffreder/768852992640c32f7be5 to your computer and use it in GitHub Desktop.
Average fund calculation for indiegogo
(function($) {
$('<div>').addClass('i-average-fund').insertBefore($('.i-progress-bar'));
$('<div>').addClass('i-ppl-needed').insertBefore($('.i-progress-bar'));
window.avgInterval = setInterval(function() {
var balanceTxt = $(".i-balance span span").text();
var curr = balanceTxt[0];
var balance = parseFloat($(".i-balance span span").text().replace(curr, '').replace(/,/g,''));
var people = parseInt($(".i-raised-funders").text().replace(/,/g,''));
var total = parseInt($(".i-goal-amount .currency").text().replace(/,/g,'').replace(curr, ''));
var avg = new Number((balance/people).toFixed(2));
var pplneeded = new Number(((total-balance)/avg).toFixed(2));
$('.i-average-fund').html('Avg. fund: <b>' + avg + curr + '</b>');
$('.i-ppl-needed').html('<b>' + pplneeded.toLocaleString() + '</b> people needed');
}, 1000);
})($);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment