@@ -21,6 +21,13 @@ if (settings.has("user.currency")) {
2121 settings . set ( "user.currency" , "USD" ) ;
2222}
2323
24+ //default secondary currency
25+ if ( settings . has ( "user.secondaryCurrency" ) ) {
26+ //do nothing because secondary currency already set
27+ } else {
28+ settings . set ( "user.secondaryCurrency" , "BRL" ) ;
29+ }
30+
2431/* Base Currency */
2532base = settings . get ( "user.currency" ) ; // get the user's base currency
2633var currSel = document . getElementById ( "base" ) ; //select the currency select box
@@ -35,6 +42,20 @@ setBase = function () {
3542 updateData ( ) ; //immediately reflect the changed currency
3643} ;
3744
45+ /* Secondary Currency */
46+ secondary = settings . get ( "user.secondaryCurrency" ) ; // get the user's secondary currency
47+ var currSel = document . getElementById ( "secondary" ) ; //select the currency select box
48+ currSel . value = settings . get ( "user.secondaryCurrency" ) ; //select the option that corresponds to the user's secondary currency
49+ setSecondary = function ( ) {
50+ //selected secondary currency
51+ var sel = document . getElementById ( "secondary" ) ;
52+ var x = sel . selectedIndex ;
53+ var y = sel . options ;
54+ secondary = y [ x ] . text ;
55+ settings . set ( "user.secondaryCurrency" , secondary ) ; //save the user's selection
56+ updateData ( ) ; //immediately reflect the changed secondary currency
57+ } ;
58+
3859//Functions for creating/appending elements
3960function createNode ( element ) {
4061 return document . createElement ( element ) ;
@@ -64,7 +85,7 @@ function initData() {
6485 "https://min-api.cryptocompare.com/data/pricemultifull?fsyms=" +
6586 settings . get ( "user.coins" ) +
6687 "&tsyms=" +
67- base +
88+ [ base , secondary ] . join ( ',' ) +
6889 "&extraParams=crypto-price-widget" ;
6990 fetch ( url )
7091 . then (
@@ -166,7 +187,7 @@ function updateData() {
166187 "https://min-api.cryptocompare.com/data/pricemultifull?fsyms=" +
167188 settings . get ( "user.coins" ) +
168189 "&tsyms=" +
169- base +
190+ [ base , secondary ] . join ( ',' ) +
170191 "&extraParams=crypto-price-widget" ;
171192 /*
172193 ** What data needs to be grabbed/changed?
@@ -187,13 +208,15 @@ function updateData() {
187208 for ( let key of Object . keys ( pricesRAW ) ) {
188209 let coinDISPLAY = pricesDISPLAY [ key ] ;
189210 let coinDISPLAYchange = coinDISPLAY [ base ] . CHANGEPCT24HOUR ;
211+ let secondaryCoinDISPLAYchange = coinDISPLAY [ secondary ] . CHANGEPCT24HOUR ;
190212 let coinRAW = pricesRAW [ key ] ;
191213 //console.log(coinDISPLAY);
192214 let li = document . getElementById ( "coin-" + [ key ] ) ,
193215 span = document . querySelector ( "#coin-" + [ key ] + " span" ) ;
194216
195217 let coinSymbol = coinRAW [ base ] . FROMSYMBOL ;
196218 let coinRate = coinDISPLAY [ base ] . PRICE . replace ( / / g, "" ) ; //.replace(/ /g,'') removes space after $
219+ let secondaryCoinRate = coinDISPLAY [ secondary ] . PRICE . replace ( / / g, "" ) ; //.replace(/ /g,'') removes space after $
197220
198221 //replace currencies that have no symbols with easier to read formats
199222 if ( coinRate . includes ( "AUD" ) ) {
@@ -227,12 +250,47 @@ function updateData() {
227250 coinRate = coinRate . replace ( "ZAR" , "R" ) ;
228251 }
229252
253+ if ( secondaryCoinRate . includes ( "AUD" ) ) {
254+ secondaryCoinRate = secondaryCoinRate . replace ( "AUD" , "A$" ) ;
255+ }
256+ if ( secondaryCoinRate . includes ( "CAD" ) ) {
257+ secondaryCoinRate = secondaryCoinRate . replace ( "CAD" , "C$" ) ;
258+ }
259+ if ( secondaryCoinRate . includes ( "HKD" ) ) {
260+ secondaryCoinRate = secondaryCoinRate . replace ( "HKD" , "HK$" ) ;
261+ }
262+ if ( secondaryCoinRate . includes ( "MXN" ) ) {
263+ secondaryCoinRate = secondaryCoinRate . replace ( "MXN" , "$" ) ;
264+ }
265+ if ( secondaryCoinRate . includes ( "NOK" ) ) {
266+ secondaryCoinRate = secondaryCoinRate . replace ( "NOK" , "kr" ) ;
267+ }
268+ if ( secondaryCoinRate . includes ( "NZD" ) ) {
269+ secondaryCoinRate = secondaryCoinRate . replace ( "NZD" , "NZ$" ) ;
270+ }
271+ if ( secondaryCoinRate . includes ( "SEK" ) ) {
272+ secondaryCoinRate = secondaryCoinRate . replace ( "SEK" , "kr" ) ;
273+ }
274+ if ( secondaryCoinRate . includes ( "SGD" ) ) {
275+ secondaryCoinRate = secondaryCoinRate . replace ( "SGD" , "S$" ) ;
276+ }
277+ if ( secondaryCoinRate . includes ( "TRY" ) ) {
278+ secondaryCoinRate = secondaryCoinRate . replace ( "TRY" , "₺" ) ;
279+ }
280+ if ( secondaryCoinRate . includes ( "ZAR" ) ) {
281+ secondaryCoinRate = secondaryCoinRate . replace ( "ZAR" , "R" ) ;
282+ }
283+
230284 //console.log(span);
231285 span . innerHTML =
232286 '<span class="sym">' +
233287 coinSymbol +
234- "</span> " +
288+ "</span>" +
289+ ' <div class="block">' +
235290 coinRate +
291+ '<br />' +
292+ secondaryCoinRate +
293+ '</div>' +
236294 '<span class="change">' +
237295 coinDISPLAYchange +
238296 "%</span>" ;
0 commit comments