Difference between revisions of "User:Areid/common.js"

From ipswichmakerspace
Jump to: navigation, search
m
m
Line 4: Line 4:
  
 
var $subtotals = $('tr td b').filter(function(i) { return $(this).text()=='£subtotal'; });
 
var $subtotals = $('tr td b').filter(function(i) { return $(this).text()=='£subtotal'; });
 +
var running_total = 0;
 
var prior = '';
 
var prior = '';
 
var table = $subtotals.parents('table').first();
 
var table = $subtotals.parents('table').first();
Line 23: Line 24:
 
});
 
});
  
 +
        running_total += costotal;
 
$(e).text('£' + costotal.toFixed(2));
 
$(e).text('£' + costotal.toFixed(2));
 
$(summary).append('<p><strong>' + prior + '</strong> : £' + costotal.toFixed(2));
 
$(summary).append('<p><strong>' + prior + '</strong> : £' + costotal.toFixed(2));
Line 28: Line 30:
 
});
 
});
  
 +
$('td:contains(£tree.fiddy)').text(running_total.toFixed(2));
 
$(table).after(summary);
 
$(table).after(summary);
  
 
}
 
}

Revision as of 01:52, 1 February 2018


if (mw.config.values.wgTitle == 'Wishlist') {


var $subtotals = $('tr td b').filter(function(i) { return $(this).text()=='£subtotal'; });
var running_total = 0;
var prior = '';
var table = $subtotals.parents('table').first();
var summary = document.createElement('div');
$(summary).append('<h4>Summary:</h4>');

$subtotals.each(function(i, e) {

	
	//prior = $(e).parent().parent().prev().children('td:nth-child(3)').text().trim();
	prior = $(e).parent().siblings('th').text().trim();
	

	$costs = $('td:contains('+prior+')').filter(function(i) { return $(this).text().trim()==prior; }).nextAll('td:nth-child(7)');
	var costotal = 0, cost = 0;
	$costs.each(function(ci,ce) {
		cost = parseFloat($(ce).text().trim().replace('£',''));
		costotal += cost;
	});

        running_total += costotal;
	$(e).text('£' + costotal.toFixed(2));
	$(summary).append('<p><strong>' + prior + '</strong> : £' + costotal.toFixed(2));

});

$('td:contains(£tree.fiddy)').text(running_total.toFixed(2));
$(table).after(summary);

}