User:Areid/common.js

From ipswichmakerspace
< User:Areid
Revision as of 10:06, 31 January 2018 by Areid (Talk | contribs)

Jump to: navigation, search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Clear the cache in Tools → Preferences

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


var $subtotals = $('tr td b').filter(function(i) { return $(this).text()=='£subtotal'; });
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()=='+prior+'; }).nextAll('td:nth-child(7)');
	var costotal = 0, cost = 0;
	$costs.each(function(ci,ce) {
		cost = parseFloat($(ce).text().trim().replace('£',''));
		costotal += cost;
	});

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

});

$(table).after(summary);

}