diff --git a/assets/scripts/app.js b/assets/scripts/app.js index c3a2930..0e0afa1 100644 --- a/assets/scripts/app.js +++ b/assets/scripts/app.js @@ -15,17 +15,22 @@ httpRequest.send(); } - // this requests the file and executes a callback with the parsed result once it is available - fetchJSONFile('https://coinmarketcap-nexuist.rhcloud.com/api/dash/price', function (data) { - var keys = Object.keys(data), - currencyListHTML = ""; - for (var i = 0; i < keys.length; i++) { - var thisCurrency = keys[i]; - var nextCurrency = keys[(i < keys.length - 1 ? i + 1 : 0)]; - var currencyValue = data[keys[i]]; - var currencyString = (currencyValue.toPrecision(3).length > currencyValue.toFixed(2) ? currencyValue.toPrecision(3) : currencyValue.toFixed(2)); - currencyListHTML += ''; - } - document.getElementById('dash-ticker--price-container').innerHTML = currencyListHTML; - }); + function updatePrices() { + // this requests the Dash price JSON and executes a callback with the parsed result once it is available + fetchJSONFile('https://coinmarketcap-nexuist.rhcloud.com/api/dash/price', function (data) { + var keys = Object.keys(data), + currencyListHTML = ""; + for (var i = 0; i < keys.length; i++) { + var thisCurrency = keys[i]; + var nextCurrency = keys[(i < keys.length - 1 ? i + 1 : 0)]; + var currencyValue = data[keys[i]]; + var currencyString = (currencyValue.toPrecision(3).length > currencyValue.toFixed(2) ? currencyValue.toPrecision(3) : currencyValue.toFixed(2)); + currencyListHTML += ''; + } + document.getElementById('dash-ticker--price-container').innerHTML = currencyListHTML; + }); + } + + updatePrices(); // update prices now + setInterval(updatePrices, 5 * 60 * 1000); // ...and every five minutes after this })(); diff --git a/dist/index.html b/dist/index.html index 0c30d27..653880a 100644 --- a/dist/index.html +++ b/dist/index.html @@ -86,18 +86,23 @@ httpRequest.send(); } - // this requests the file and executes a callback with the parsed result once it is available - fetchJSONFile('https://coinmarketcap-nexuist.rhcloud.com/api/dash/price', function (data) { - var keys = Object.keys(data), - currencyListHTML = ""; - for (var i = 0; i < keys.length; i++) { - var thisCurrency = keys[i]; - var nextCurrency = keys[(i < keys.length - 1 ? i + 1 : 0)]; - var currencyValue = data[keys[i]]; - var currencyString = (currencyValue.toPrecision(3).length > currencyValue.toFixed(2) ? currencyValue.toPrecision(3) : currencyValue.toFixed(2)); - currencyListHTML += ''; - } - document.getElementById('dash-ticker--price-container').innerHTML = currencyListHTML; - }); + function updatePrices() { + // this requests the Dash price JSON and executes a callback with the parsed result once it is available + fetchJSONFile('https://coinmarketcap-nexuist.rhcloud.com/api/dash/price', function (data) { + var keys = Object.keys(data), + currencyListHTML = ""; + for (var i = 0; i < keys.length; i++) { + var thisCurrency = keys[i]; + var nextCurrency = keys[(i < keys.length - 1 ? i + 1 : 0)]; + var currencyValue = data[keys[i]]; + var currencyString = (currencyValue.toPrecision(3).length > currencyValue.toFixed(2) ? currencyValue.toPrecision(3) : currencyValue.toFixed(2)); + currencyListHTML += ''; + } + document.getElementById('dash-ticker--price-container').innerHTML = currencyListHTML; + }); + } + + updatePrices(); // update prices now + setInterval(updatePrices, 5 * 60 * 1000); // ...and every five minutes after this })();