Skip to content

Commit

Permalink
More descriptive comments and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
xangelix committed Jan 5, 2018
1 parent c854178 commit c3641ed
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ This adds the value of each wallet in Binance (under deposits and withdraws) aft

Please use the [issues tracker on this github repository](https://github.com/Matrix-Guy/binance-valuations/issues)!

## Current Features
WIP

## Upcoming Features
* Only request values above 0
* Dropdown for links to different resources when hovering over value
* Removal of nasty global variables
* Migration to ES6+ features
* More customization options of formatting and features in the GUI

## Prerequisites

Expand Down
18 changes: 11 additions & 7 deletions content.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*jshint esversion: 6 */

// Asynchronous HTTP Requestor
var HttpClient = function() {
this.get = function(aUrl, aCallback) {
Expand All @@ -13,6 +14,7 @@ var HttpClient = function() {
};
};

// Key of currencies
function getCurrency(currency) {
const symbols = {
USD: '$',
Expand All @@ -31,18 +33,22 @@ return symbols[currency];
var names = document.getElementsByClassName('coin ng-binding');
var amounts = document.getElementsByClassName('total f-right ng-binding');
var btcs = document.getElementsByClassName('equalValue f-right ng-binding');

// Global variables
var namesIndex = [];
var index;
var currency = 'USD';
var prefix = `<br><button class="btn btn-success" onclick=" window.open('https://www.cryptocompare.com/coins/`;

// Links formatting constants
var prefix0 = `<br><button class="btn btn-success" onclick=" window.open('https://www.cryptocompare.com/coins/`;
var suffix0 = `/overview/`;
var suffix1 = `','_blank')">`;
var suffix2 = `</button>`;

// Test if prices have already been added
if (amounts[1].innerHTML.includes('<button class="btn btn-success"')) {
for (var i = 1; i < amounts.length; i++) {
// Removal of previous prices
// Removal of previous prices and formatting
amounts[i].innerHTML = amounts[i].innerHTML.substring(0, amounts[i].innerHTML.indexOf('-'));
amounts[i].innerHTML = amounts[i].innerHTML.replace('<br>', '');
}
Expand Down Expand Up @@ -75,16 +81,14 @@ function parseP(coinName, coinValue) {
index = indexFinder(coinName);
if (parseFloat(btcs[index + 1].innerHTML) > 0) {
var output = parseFloat(coinValue) * parseFloat(btcs[index + 1].innerHTML);

output = getCurrency(currency) + output.toFixed(2);
//console.log('TOTAL: ' + output);
// To-do: Add tradingview graphs to changed elements

// Dropdown for links to different resources when hovering over value
// Final posting of data
amounts[index + 1].innerHTML += prefix + coinName.replace(/<(?:.|\n)*?>/gm, '').toLowerCase() + suffix0 + currency + suffix1 + output + suffix2;
amounts[index + 1].innerHTML += prefix0 + coinName.replace(/<(?:.|\n)*?>/gm, '').toLowerCase() + suffix0 + currency + suffix1 + output + suffix2;
}
}


//Indexing agent for matching asynchronous replies to page
function indexFinder(coinName) {
function finding(element) {
Expand Down
13 changes: 10 additions & 3 deletions popup.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
/*jshint esversion: 6 */

// Saves currency info to chrome.storage.sync
function saveCurrency(val) {
var data = {};
data.currency = val;
chrome.storage.sync.set(data);
}

// Updates Binance page to show currencies by executing content.js
function changeCurrency() {
chrome.tabs.executeScript(null, {file: "content.js"}, () => {
});
}

chrome.tabs.executeScript(null, {file: "jquery-3.2.1.min.js"});

// Listener to run whenever the GUI is opened
document.addEventListener('DOMContentLoaded', () => {

// Reads default setting of currency from popup.html
var dropdown = document.getElementById('dropdown');

// Tests if current setting matches what is stored in chrome.storage.sync
// If they match, neither are modified
// If they are different, the dropdown is updated to what is stored in chrome.storage.sync
chrome.storage.sync.get('currency', (data) => {
if (typeof data.currency === 'undefined') {
saveCurrency(dropdown.value);
Expand All @@ -24,7 +30,8 @@ document.addEventListener('DOMContentLoaded', () => {
}
changeCurrency(data.currency);


// Listener to run if dropdown value changes
// If triggered chrome.storage.sync is updated and content.js is reloaded
dropdown.addEventListener('change', () => {
changeCurrency(dropdown.value);
saveCurrency(dropdown.value);
Expand Down

0 comments on commit c3641ed

Please sign in to comment.