Difference between revisions of "MediaWiki:Common.js"
From ipswichmakerspace
m |
m |
||
(8 intermediate revisions by the same user not shown) | |||
Line 23: | Line 23: | ||
− | $costs = $('td:contains('+prior+')').filter(function(i) { return $(this).text().trim()==prior; }).nextAll('td:nth-child(7)'); | + | $costs = $('table.magitable td:contains('+prior+')').filter(function(i) { return $(this).text().trim()==prior; }).nextAll('td:nth-child(7)'); |
var costotal = 0, cost = 0; | var costotal = 0, cost = 0; | ||
$costs.each(function(ci,ce) { | $costs.each(function(ci,ce) { | ||
Line 58: | Line 58: | ||
− | $('b:contains($blocktotal)').each(function(i, e) { | + | var $all = $('b:contains($blocktotal)').each(function(i, e) { |
Line 64: | Line 64: | ||
string = $(e).parent('pre').html(); | string = $(e).parent('pre').html(); | ||
− | + | ||
− | var regex = / | + | var regex = /£\d*\.\d{2}/gi, result, indices = []; |
+ | |||
while ( (result = regex.exec(string)) ) { | while ( (result = regex.exec(string)) ) { | ||
indices.push(result.index); | indices.push(result.index); | ||
− | got = string.substring(result.index, result.index + 6); | + | got = string.substring(result.index, result.index + 6); |
− | console.log(got); | + | console.log(got); |
− | + | add = parseFloat(got.trim().replace('£','')); | |
− | + | console.log(add); | |
+ | total = total + add; | ||
} | } | ||
Line 81: | Line 83: | ||
− | + | console.log($all); | |
Latest revision as of 18:10, 16 July 2018
/* Any JavaScript here will be loaded for all users on every page load. */ if (mw.config.values.wgTitle == 'Wishlist' || mw.config.values.wgTitle == 'Current wishlist') { 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.parents('table').addClass('magitable'); $subtotals.parents('tr').addClass('subtotal'); $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 = $('table.magitable 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)); if (mw.config.values.wgTitle == 'Wishlist') { $(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); } else if (mw.config.values.wgTitle == 'Current wishlist') { $(table).after('<p><strong>Total</strong> : £'+running_total.toFixed(2)).after(summary); } var $all = $('b:contains($blocktotal)').each(function(i, e) { total = 0; string = $(e).parent('pre').html(); var regex = /£\d*\.\d{2}/gi, result, indices = []; while ( (result = regex.exec(string)) ) { indices.push(result.index); got = string.substring(result.index, result.index + 6); console.log(got); add = parseFloat(got.trim().replace('£','')); console.log(add); total = total + add; } $(e).text('£' + total.toFixed(2)); }); console.log($all); }