Skip to content

Instantly share code, notes, and snippets.

@bumbeishvili
Last active May 8, 2019 04:47
Show Gist options
  • Save bumbeishvili/927fc64f83df37fffe7c59fbbe81a619 to your computer and use it in GitHub Desktop.
Save bumbeishvili/927fc64f83df37fffe7c59fbbe81a619 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Upwork Total Earnings
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.upwork.com/ab/payments/reports/relationship-values
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Get all billed amounts
let billed = [...document.querySelectorAll('.text-right')].map(d=>d.innerText)
.map(d=>d.replace(/\$/g,' '))
.map(d=>d.replace(/,/g,''))
.map(d=>d.replace(/\s/g,''))
.map(d=>+d)
.filter(d=>!isNaN(d))
// Calculate total billed amount
let sumWithoutCharging = billed.reduce((a,b)=>a+b)
// Calculate amount after upwork charge
let sumWithCharging = billed.map(d=>{
return charge(d)
})
.reduce((a,b)=>a+b)
// Display amounts on Upwork page
document.querySelector('.m-md-left.m-sm-top').innerHTML = `$ ${formatMoney(Math.round(sumWithoutCharging))} - Total Before charge <br>$ ${formatMoney(Math.round(sumWithCharging))} - Total After charge `
// Func, which calculates how much upwork charges
function charge(d){
if(d<500) return d*0.8;
if(d<10000) return d*0.9-50;
return charge(9999)+(d-9999)*.95
}
// Money formatting utility
function formatMoney(n) {
var c = isNaN(c = Math.abs(c)) ? 0 : c,
d = d == undefined ? "." : d,
t = t == undefined ? "," : t,
s = n < 0 ? "-" : "",
i = String(parseInt(n = Math.abs(Number(n) || 0).toFixed(c))),
j = (j = i.length) > 3 ? j % 3 : 0;
return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment