Skip to content

Instantly share code, notes, and snippets.

@clrxbl
Created March 22, 2021 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clrxbl/57d8712ed5f17ec759ba3f9fbd337aa0 to your computer and use it in GitHub Desktop.
Save clrxbl/57d8712ed5f17ec759ba3f9fbd337aa0 to your computer and use it in GitHub Desktop.
Harvest Project Currency Conversion
// ==UserScript==
// @name Harvest Currency Exchange
// @namespace Violentmonkey Scripts
// @match https://*.harvestapp.com/projects/*
// @run-at document-idle
// @grant none
// @version 1.0
// @author -
// @description 3/22/2021, 3:47:59 PM
// ==/UserScript==
// this may not look like it but this is peak performance
const convertUninvoicedAmount = async () => {
const uninvoicedAmount = document.getElementsByClassName('test-uninvoiced-amount')[0].innerText.match(/\d.+,/g)[0].replace(/\D/g,'');
const json = await fetch('https://api.exchangeratesapi.io/latest?base=GBP&symbols=EUR').then(response => response.json());
const exchangeRate = json.rates.EUR;
console.log("Current GBP -> EUR exchange rate: " + exchangeRate);
const convertedUninvoicedAmount = uninvoicedAmount * exchangeRate;
const roundedConvertedUninvoicedAmount = convertedUninvoicedAmount.toFixed(2).replace(".", ",");
console.log(roundedConvertedUninvoicedAmount + " EUR");
document.getElementsByClassName('test-uninvoiced-amount')[0].innerHTML += "€" + roundedConvertedUninvoicedAmount + " EUR";
}
convertUninvoicedAmount().catch(console.error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment