From 5158b1e7a29d5ed57809553be7be8297b5d4ef22 Mon Sep 17 00:00:00 2001 From: Mayel de Borniol Date: Mon, 30 Apr 2018 17:49:22 +0300 Subject: [PATCH] support for faircoin 1 blockchain --- extension/extension.js | 54 ++++++++++++++++++++++++++++++++++------- extension/manifest.json | 5 +++- 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/extension/extension.js b/extension/extension.js index e9099e3..ae0e4d0 100644 --- a/extension/extension.js +++ b/extension/extension.js @@ -15,26 +15,50 @@ $(function() { // $(".inner-cont").append("priceData: "); // $(".inner-cont").append(priceData); - var heads = "

If you're happy with the FairCoin Calculator, you can donate at fMGcrP9nAFic4356F4oHDDWVq8YvtJSXZL"; + var heads = "

If you're happy with the FairCoin Calculator, you can donate at fMGcrP9nAFic4356F4oHDDWVq8YvtJSXZL"; $("body").append(heads); if (priceData) { var heads = 'Official RateOfficial ValueMarket Value'; - $("thead tr").append(heads); - $('tbody').each(function() { + if($("thead tr").length){ // faircoin 2 - total_fair = total_euro = total_market = 0; + $("thead tr").append(heads); - $(this).find('tr').each(function() { + $('tbody').each(function() { + total_fair = total_euro = total_market = 0; - var dateVar = $(this).find('td:first').text(); + $(this).find('tr').each(function() { + + var dateVar = $(this).find('td:first').text(); + var d = new Date(dateVar); + var dateISO = d.toISOString().slice(0, 10); + + var faircoins = parseFloat($(this).find('td:nth-child(3)').text()); + + // $(this).append(''+faircoins+''); + + calculateEuros(dateISO, faircoins, this); + + }); + + $(this).append('Totals' + (Math.round(total_fair * 100) / 100) + ' FAIR€ ' + (Math.round(total_euro * 100) / 100) + '€ ' + (Math.round(total_market * 100) / 100) + ''); + + }); + + } else { // faircoin 1 + + $("tbody tr:first-child").append(heads); + + $('tbody tr.direct').each(function() { + + var dateVar = $(this).find('td:nth-child(3)').text(); var d = new Date(dateVar); var dateISO = d.toISOString().slice(0, 10); - var faircoins = parseFloat($(this).find('td:nth-child(3)').text()); + var faircoins = cleanUpCurrency($(this).find('td:nth-child(4)').text()); // $(this).append(''+faircoins+''); @@ -42,9 +66,8 @@ $(function() { }); - $(this).append('Totals' + (Math.round(total_fair * 100) / 100) + ' FAIR€ ' + (Math.round(total_euro * 100) / 100) + '€ ' + (Math.round(total_market * 100) / 100) + ''); + } - }); } }; @@ -107,5 +130,18 @@ $(function() { return (r); } + function cleanUpCurrency(s){ + var expression = /\(.(.+)\)/; + + //Check if it is in the proper format + if(s.match(expression)){ + //It matched - strip out parentheses and append - at front + return parseFloat('-' + s.replace(/[\$\(\),]/g,'')); + } + else{ + return parseFloat(s); + } + } + }); \ No newline at end of file diff --git a/extension/manifest.json b/extension/manifest.json index 8cc1021..daeecc5 100644 --- a/extension/manifest.json +++ b/extension/manifest.json @@ -9,7 +9,10 @@ ], "content_scripts": [ { - "matches": [ "https://chain.fair.to/address*" ], + "matches": [ + "https://chain.fair.to/address*", + "https://chain.fair-coin.org/address/*" + ], "js": [ "jquery-3.3.1.min.js", "extension.js" ] } ],