added five minute refresh interval

This commit is contained in:
Joshua Seigler 2016-04-29 00:35:04 -04:00
parent 2965e90656
commit 94da47ae9d
2 changed files with 36 additions and 26 deletions

View file

@ -15,17 +15,22 @@
httpRequest.send(); httpRequest.send();
} }
// this requests the file and executes a callback with the parsed result once it is available function updatePrices() {
fetchJSONFile('https://coinmarketcap-nexuist.rhcloud.com/api/dash/price', function (data) { // this requests the Dash price JSON and executes a callback with the parsed result once it is available
var keys = Object.keys(data), fetchJSONFile('https://coinmarketcap-nexuist.rhcloud.com/api/dash/price', function (data) {
currencyListHTML = ""; var keys = Object.keys(data),
for (var i = 0; i < keys.length; i++) { currencyListHTML = "";
var thisCurrency = keys[i]; for (var i = 0; i < keys.length; i++) {
var nextCurrency = keys[(i < keys.length - 1 ? i + 1 : 0)]; var thisCurrency = keys[i];
var currencyValue = data[keys[i]]; var nextCurrency = keys[(i < keys.length - 1 ? i + 1 : 0)];
var currencyString = (currencyValue.toPrecision(3).length > currencyValue.toFixed(2) ? currencyValue.toPrecision(3) : currencyValue.toFixed(2)); var currencyValue = data[keys[i]];
currencyListHTML += '<input type="radio" name="currency" id="dash-ticker-currencies-' + thisCurrency + '"' + (i === 0 ? ' checked' : '') + ' /><label for="dash-ticker-currencies-' + nextCurrency + '"><span class="dash-ticker--price">' + currencyString + '</span> <span class="dash-ticker--currency">' + thisCurrency.toUpperCase() + '</span></label>'; var currencyString = (currencyValue.toPrecision(3).length > currencyValue.toFixed(2) ? currencyValue.toPrecision(3) : currencyValue.toFixed(2));
} currencyListHTML += '<input type="radio" name="currency" id="dash-ticker-currencies-' + thisCurrency + '"' + (i === 0 ? ' checked' : '') + ' /><label for="dash-ticker-currencies-' + nextCurrency + '"><span class="dash-ticker--price">' + currencyString + '</span> <span class="dash-ticker--currency">' + thisCurrency.toUpperCase() + '</span></label>';
document.getElementById('dash-ticker--price-container').innerHTML = currencyListHTML; }
}); document.getElementById('dash-ticker--price-container').innerHTML = currencyListHTML;
});
}
updatePrices(); // update prices now
setInterval(updatePrices, 5 * 60 * 1000); // ...and every five minutes after this
})(); })();

31
dist/index.html vendored
View file

@ -86,18 +86,23 @@
httpRequest.send(); httpRequest.send();
} }
// this requests the file and executes a callback with the parsed result once it is available function updatePrices() {
fetchJSONFile('https://coinmarketcap-nexuist.rhcloud.com/api/dash/price', function (data) { // this requests the Dash price JSON and executes a callback with the parsed result once it is available
var keys = Object.keys(data), fetchJSONFile('https://coinmarketcap-nexuist.rhcloud.com/api/dash/price', function (data) {
currencyListHTML = ""; var keys = Object.keys(data),
for (var i = 0; i < keys.length; i++) { currencyListHTML = "";
var thisCurrency = keys[i]; for (var i = 0; i < keys.length; i++) {
var nextCurrency = keys[(i < keys.length - 1 ? i + 1 : 0)]; var thisCurrency = keys[i];
var currencyValue = data[keys[i]]; var nextCurrency = keys[(i < keys.length - 1 ? i + 1 : 0)];
var currencyString = (currencyValue.toPrecision(3).length > currencyValue.toFixed(2) ? currencyValue.toPrecision(3) : currencyValue.toFixed(2)); var currencyValue = data[keys[i]];
currencyListHTML += '<input type="radio" name="currency" id="dash-ticker-currencies-' + thisCurrency + '"' + (i === 0 ? ' checked' : '') + ' /><label for="dash-ticker-currencies-' + nextCurrency + '"><span class="dash-ticker--price">' + currencyString + '</span> <span class="dash-ticker--currency">' + thisCurrency.toUpperCase() + '</span></label>'; var currencyString = (currencyValue.toPrecision(3).length > currencyValue.toFixed(2) ? currencyValue.toPrecision(3) : currencyValue.toFixed(2));
} currencyListHTML += '<input type="radio" name="currency" id="dash-ticker-currencies-' + thisCurrency + '"' + (i === 0 ? ' checked' : '') + ' /><label for="dash-ticker-currencies-' + nextCurrency + '"><span class="dash-ticker--price">' + currencyString + '</span> <span class="dash-ticker--currency">' + thisCurrency.toUpperCase() + '</span></label>';
document.getElementById('dash-ticker--price-container').innerHTML = currencyListHTML; }
}); document.getElementById('dash-ticker--price-container').innerHTML = currencyListHTML;
});
}
updatePrices(); // update prices now
setInterval(updatePrices, 5 * 60 * 1000); // ...and every five minutes after this
})(); })();
</script> </script>