Skip to content

Instantly share code, notes, and snippets.

@filipstachura
Created October 13, 2020 06:58
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 filipstachura/d2a6613096d2dde0fccb3e7348626dcd to your computer and use it in GitHub Desktop.
Save filipstachura/d2a6613096d2dde0fccb3e7348626dcd to your computer and use it in GitHub Desktop.
YNAB multicurrency sidebar converter (support for EUR, USD, GBP).
// ==UserScript==
// @name YNAB multicurrency sidebar converter
// @version 0.1
// @author filip@appsilon.com
// @match https://app.youneedabudget.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function multicurrency_sidebar() {
var currencies = Array.from(document.querySelectorAll(".nav-account-row .nav-account-name")).map(x => x.innerText).map(x => x.match(/.* ([A-Z]{3})/m)[1])
var rates = currencies.map(x => ({PLN: 1, USD: 3.8, EUR: 4.48, GBP: 4.93})[x]);
var converted_balances = Array.from(document.querySelectorAll(".nav-account-row .nav-account-value .currency")).map(x => x.innerText).map(x => x.replace(/[, \sa-zł]/g, "").replace("−", "-")).map(Number).map((x,i) =>Math.round(x/rates[i]))
Array.from(document.querySelectorAll(".nav-account-row .nav-account-value")).map((el, i) => {
var currency = document.createElement("span");
if (currencies[i] !== "PLN") {
currency.innerHTML = (new Intl.NumberFormat('en-US', {
style: 'currency',
currency: currencies[i],
minimumFractionDigits: 2,
maximumFractionDigits: 2,
})).format(converted_balances[i]/100) + " (~)";
el.appendChild(currency);
}
})
document.styleSheets[0].insertRule(".sidebar a { height: 3em;}", 0);
}
var checkExist = setInterval(function() {
console.log('tick');
if (document.querySelectorAll(".nav-account-row .nav-account-value").length) {
multicurrency_sidebar();
clearInterval(checkExist);
}
}, 500);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment