Skip to content

Instantly share code, notes, and snippets.

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 szymonkaliski/6d0b4d759cb4aaf2bd9c to your computer and use it in GitHub Desktop.
Save szymonkaliski/6d0b4d759cb4aaf2bd9c to your computer and use it in GitHub Desktop.
UserScript for converting everything in BZWBK panel into PLN, keeping it here so I won't loose it.
// ==UserScript==
// @name BZWBK Currency Converter
// @version 0.1
// @description computes currency in BZWBK online panel to display everything in PLN
// @author You
// @require https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.6.15/browser-polyfill.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.6.15/browser.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js
// @require https://cdnjs.cloudflare.com/ajax/libs/money.js/0.2.0/money.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/accounting.js/0.4.1/accounting.min.js
// @match https://www.centrum24.pl/centrum24-web/portfolio
// ==/UserScript==
/* jshint ignore:start */
var inline_src = (<><![CDATA[
/* jshint ignore:end */
/* jshint esnext:true */
GM_xmlhttpRequest({
method: "GET",
url: "http://api.fixer.io/latest",
onload: ({ response }) => {
fx.base = 'EUR';
fx.rates = JSON.parse(response).rates;
const currencies = [ 'GBP', 'USD', 'EUR' ];
const parseMoney = (moneyString) => {
return parseFloat(moneyString
.replace(/\s+/g, '')
.replace(',', '.'));
};
const formatMoney = (moneyNumber) => {
return accounting.formatMoney(
moneyNumber,
{
symbol: 'PLN',
format: '%v %s',
thousand: ' ',
decimal: ','
}
);
};
$("td.money").each((i, item) => {
const $item = $(item);
const text = $item.text();
if (currencies.some(currency => text.indexOf(currency) >= 0)) {
const currency = currencies.filter(currency => text.indexOf(currency) >= 0);
const parsedMoney = parseMoney(text);
const convertedMoney = fx.convert(parsedMoney, { from: currency, to: 'PLN' }).toFixed(2);
$item.text(formatMoney(convertedMoney));
$item.append(`<span style="font-size: 11px">${text}</span>`);
}
});
}
})
/* jshint ignore:start */
]]></>).toString();
var c = babel.transform(inline_src);
eval(c.code);
/* jshint ignore:end */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment