Browse Source

support for faircoin 1 blockchain

pull/1/head
Mayel de Borniol 6 years ago
parent
commit
5158b1e7a2
2 changed files with 49 additions and 10 deletions
  1. +45
    -9
      extension/extension.js
  2. +4
    -1
      extension/manifest.json

+ 45
- 9
extension/extension.js

@ -15,26 +15,50 @@ $(function() {
// $(".inner-cont").append("priceData: "); // $(".inner-cont").append("priceData: ");
// $(".inner-cont").append(priceData); // $(".inner-cont").append(priceData);
var heads = "<p style='text-align:center;'>If you're happy with the FairCoin Calculator, you can donate at <a href='faircoin:fMGcrP9nAFic4356F4oHDDWVq8YvtJSXZL'>fMGcrP9nAFic4356F4oHDDWVq8YvtJSXZL</a>";
var heads = "<p style='text-align:center; background:#fff'>If you're happy with the FairCoin Calculator, you can donate at <a href='faircoin:fMGcrP9nAFic4356F4oHDDWVq8YvtJSXZL'>fMGcrP9nAFic4356F4oHDDWVq8YvtJSXZL</a>";
$("body").append(heads); $("body").append(heads);
if (priceData) { if (priceData) {
var heads = '<th>Official Rate</th><th>Official Value</th><th>Market Value</th>'; var heads = '<th>Official Rate</th><th>Official Value</th><th>Market Value</th>';
$("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('<td>'+faircoins+'</td>');
calculateEuros(dateISO, faircoins, this);
});
$(this).append('<tr><td><strong>Totals</strong></td><td></td><td>' + (Math.round(total_fair * 100) / 100) + ' FAIR</td><td></td><td>€ ' + (Math.round(total_euro * 100) / 100) + '</td><td>€ ' + (Math.round(total_market * 100) / 100) + '</td></tr>');
});
} 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 d = new Date(dateVar);
var dateISO = d.toISOString().slice(0, 10); 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('<td>'+faircoins+'</td>'); // $(this).append('<td>'+faircoins+'</td>');
@ -42,9 +66,8 @@ $(function() {
}); });
$(this).append('<tr><td><strong>Totals</strong></td><td></td><td>' + (Math.round(total_fair * 100) / 100) + ' FAIR</td><td></td><td>€ ' + (Math.round(total_euro * 100) / 100) + '</td><td>€ ' + (Math.round(total_market * 100) / 100) + '</td></tr>');
}
});
} }
}; };
@ -107,5 +130,18 @@ $(function() {
return (r); 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);
}
}
}); });

+ 4
- 1
extension/manifest.json

@ -9,7 +9,10 @@
], ],
"content_scripts": [ "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" ] "js": [ "jquery-3.3.1.min.js", "extension.js" ]
} }
], ],

Loading…
Cancel
Save