Last active
December 29, 2017 21:04
-
-
Save MicrowaveDev/6a913eed6c8de36f27a3f772bdd385b6 to your computer and use it in GitHub Desktop.
Hashparty add hours column and "per hour" caption to payments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//PASTE THIS TO BROWSER CONSOLE(F12) AND EXECUTE(ENTER) | |
//RESULT: https://pasteboard.co/H0vltKF.jpg | |
var payments = []; | |
$('#payments_rows').find('tr').each(function(){ | |
var $tr = $(this); | |
var dateStr = $tr.find('td').first().html().replace(/,/g, ''); | |
var amountStr = $tr.find('td:nth-child(3)').first().html(); | |
payments.unshift({date: new Date(dateStr), amount: parseFloat(amountStr), el: $tr}); | |
}) | |
var totalHours = 0, | |
totalAmount = 0; | |
payments.forEach(function(pay, index){ | |
var hoursEl = null; | |
if(!pay.el.find('.hours').length) | |
hoursEl = pay.el.append('<td class="hours"></td>'); | |
hoursEl = pay.el.find('.hours').first(); | |
if(!index) | |
return; | |
var prevPay = payments[index-1]; | |
var timeStampDiff = Math.round((pay.date.getTime() - prevPay.date.getTime())/1000); | |
var hoursCount = Math.round((timeStampDiff/3600) * 100)/100; | |
totalHours += hoursCount; | |
totalAmount += pay.amount; | |
hoursEl.html(hoursCount); | |
}); | |
if(!$('.yourStats table th.hours').length) | |
$('.yourStats table thead tr').append('<th class="hours">Hours</th>'); | |
$('.stats h4.yourStats').text('Payments (' + (Math.round(totalAmount/totalHours * 100)/100) + ' per hour)'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment