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

From ipswichmakerspace
Jump to: navigation, search
m
m
 
(24 intermediate revisions by the same user not shown)
Line 1: Line 1:
if (mw.config.values.wgTitle == 'Wishlist') {
 
  
 +
if (mw.config.values.wgTitle == 'Wishlist' && false) {
  
var $subtotals = $('tr td b').filter(function(i) { return $(this).text()=='£subtotal'; });
 
  
console.log($subtotals[0]);
+
var $subtotals = $('tr td b').filter(function(i) { return $(this).text()=='£subtotal'; });
 
+
var running_total = 0;
 
+
var stretch_total = 0;
console.log('---');
+
var later_total = 0;
 
var prior = '';
 
var prior = '';
 +
var table = $subtotals.parents('table').first();
 +
var summary = document.createElement('div');
 +
$(summary).append('<h4>Summary:</h4>');
 +
 
$subtotals.each(function(i, e) {
 
$subtotals.each(function(i, e) {
  
if (prior=='') {
+
prior = $(e).parent().parent().prev().children('td:nth-child(3)').text().trim();
+
//prior = $(e).parent().parent().prev().children('td:nth-child(3)').text().trim();
}
+
prior = $(e).parent().siblings('th').text().trim();
 +
  
//p = $($subtotals.first()).parent().parent().prev().children('td:nth-child(3)').text().trim();
+
$costs = $('td:contains('+prior+')').filter(function(i) { return $(this).text().trim()==prior; }).nextAll('td:nth-child(7)');
$costs = $('td:contains('+prior+')').nextAll('td:nth-child(7)');
+
var costotal = 0, cost = 0;
var costotal, cost = 0;
+
 
$costs.each(function(ci,ce) {
 
$costs.each(function(ci,ce) {
 
cost = parseFloat($(ce).text().trim().replace('£',''));
 
cost = parseFloat($(ce).text().trim().replace('£',''));
Line 23: Line 26:
 
});
 
});
  
$(e).text('£' + costotal);
+
if (prior.indexOf(' Stretch')!=-1) {
console.log(prior);
+
stretch_total += costotal;
console.log(costotal);
+
} else if (prior.indexOf(' Later')!=-1) {
+
later_total += costotal;
 +
} else {
 +
        running_total += costotal;
 +
}
 +
$(e).text('£' + costotal.toFixed(2));
 +
$(summary).append('<p><strong>' + prior + '</strong> : £' + costotal.toFixed(2));
 +
 
 
});
 
});
  
 +
$('td b:contains(£tree.fiddy)').text('£'+running_total.toFixed(2));
 +
 +
 +
 +
$(table).after('<p><strong>Main + Stretch Total</strong> : £'+(running_total+stretch_total).toFixed(2)).after(summary);
 +
$(table).after('<p><strong>Later Total</strong> : £'+later_total.toFixed(2)).after(summary);
 +
$(table).after('<p><strong>Stretch Total</strong> : £'+stretch_total.toFixed(2)).after(summary);
 +
$(table).after('<p><strong>Total</strong> : £'+running_total.toFixed(2)).after(summary);
 
}
 
}

Latest revision as of 23:06, 7 February 2018


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


var $subtotals = $('tr td b').filter(function(i) { return $(this).text()=='£subtotal'; });
var running_total = 0;
var stretch_total = 0;
var later_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;
	});

if (prior.indexOf(' Stretch')!=-1) {
stretch_total += costotal;
} else if (prior.indexOf(' Later')!=-1) {
later_total += costotal;
} else {
        running_total += costotal;
}
	$(e).text('£' + costotal.toFixed(2));
	$(summary).append('<p><strong>' + prior + '</strong> : £' + costotal.toFixed(2));

});

$('td b:contains(£tree.fiddy)').text('£'+running_total.toFixed(2));



$(table).after('<p><strong>Main + Stretch Total</strong> : £'+(running_total+stretch_total).toFixed(2)).after(summary);
$(table).after('<p><strong>Later Total</strong> : £'+later_total.toFixed(2)).after(summary);
$(table).after('<p><strong>Stretch Total</strong> : £'+stretch_total.toFixed(2)).after(summary);
$(table).after('<p><strong>Total</strong> : £'+running_total.toFixed(2)).after(summary);
}