Created
March 22, 2021 16:51
-
-
Save clrxbl/57d8712ed5f17ec759ba3f9fbd337aa0 to your computer and use it in GitHub Desktop.
Harvest Project Currency Conversion
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 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