Created
July 20, 2015 08:08
-
-
Save iGhost/8d8403c2247f4f8e5229 to your computer and use it in GitHub Desktop.
Additional calculations for Upwork reports (GreaseMonkey script)
This file contains hidden or 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
// ==UserScript== | |
// @name UpWork additional calculations | |
// @namespace Ghost | |
// @include https://www.upwork.com/reports/* | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
var myRate = 22; | |
var wFee100 = 4.95; | |
var wFee200 = 6.75; | |
function getTime(time) { | |
// Source: https://gist.github.com/peterchester/2980896 | |
// Number of decimal places to round to | |
var decimal_places = 2; | |
// Maximum number of hours before we should assume minutes were intended. Set to 0 to remove the maximum. | |
var maximum_hours = 0; | |
var int_format = time.match(/^\d+$/); | |
var time_format = time.match(/([\d]*):([\d]+)/); | |
var minute_string_format = time.toLowerCase().match(/([\d]+)m/); | |
var hour_string_format = time.toLowerCase().match(/([\d]+)h/); | |
if (time_format != null) { | |
hours = parseInt(time_format[1]); | |
minutes = parseFloat(time_format[2] / 60); | |
time = hours + minutes; | |
} else if (minute_string_format != null || hour_string_format != null) { | |
if (hour_string_format != null) { | |
hours = parseInt(hour_string_format[1]); | |
} else { | |
hours = 0; | |
} | |
if (minute_string_format != null) { | |
minutes = parseFloat(minute_string_format[1] / 60); | |
} else { | |
minutes = 0; | |
} | |
time = hours + minutes; | |
} else if (int_format != null) { | |
// Entries over 15 hours are likely intended to be minutes. | |
time = parseInt(time); | |
if (maximum_hours > 0 && time > maximum_hours) { | |
time = (time / 60).toFixed(decimal_places); | |
} | |
} | |
// make sure what ever we return is a 2 digit float | |
time = parseFloat(time).toFixed(decimal_places); | |
return time; | |
} | |
function recalculateValue(subElement) { | |
var mainElement = $(".oBigDataNavBarContainer").find(subElement).find("a > .oDataNavData"); | |
var value = parseFloat(mainElement.text().replace(/^[\s\$]+|\s+$/g, '')); | |
var realValue = (value - value / 10).toFixed(2); | |
var hint = '$' + value + ' - $' + (value / 10).toFixed(2) + ' = $' + realValue; | |
var smallAddition = "<br/><small style='font-size:13px' title='" + hint + "'>$" + value + "</small>"; | |
mainElement.html('$' + realValue + smallAddition); | |
} | |
function getWFee(amount) { | |
var hundreds = Math.floor(amount / 100); | |
var feeFor200 = Math.floor(hundreds / 2) * wFee200; | |
var feeFor100 = Math.floor(hundreds % 2) * wFee100; | |
return feeFor200 + feeFor100; | |
} | |
function recalculateStats() { | |
var row = $(".oSumRow"); | |
var statField = row.find($(".oSumRow td:first")[0]); | |
var totalTimeString = row.find($(".oSumRow td.txtCenter")[0]).text().replace(/^[\s\$]+|\s+$/g, ''); | |
var totalTime = getTime(totalTimeString); | |
var totalAmount = totalTime * myRate; | |
var amountWithFees = totalAmount - 4.5; | |
amountWithFees = amountWithFees < 0 ? 0 : amountWithFees; | |
var withdrawFee = getWFee(amountWithFees); | |
var finalAmount = Math.floor((amountWithFees - withdrawFee) / 100) * 100; | |
if ((amountWithFees - withdrawFee) < (Math.floor(amountWithFees / 100) * 100)) { | |
withdrawFee = getWFee(amountWithFees - 100); | |
var finalAmount = Math.floor((amountWithFees - 100) / 100) * 100; | |
} | |
var statString = totalTime + ' * ' + myRate + ' = <b>' + totalAmount.toFixed(2) + '</b>, - 2.0 upwrk, -2.5 paynr imdt = <b>' | |
+ amountWithFees.toFixed(2) + '</b> (wthdr: -' + withdrawFee.toFixed(2) + ' = <b style="text-decoration:underline">' | |
+ finalAmount.toFixed(2) + '</b> available to withdraw)'; | |
statField.html('<span style="font-family:\'Gotham Book\';">' + statString + '</span>'); | |
} | |
recalculateValue($(".oDataNavBarTab")[0]); | |
recalculateValue($(".oDataNavBarTab")[1]); | |
recalculateStats(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment