Skip to content

Commit

Permalink
v0.0.7 history data
Browse files Browse the repository at this point in the history
  • Loading branch information
SteakOverCooked authored and SteakOverCooked committed Feb 23, 2018
1 parent a47fd00 commit 717f663
Show file tree
Hide file tree
Showing 15 changed files with 1,082 additions and 11 deletions.
894 changes: 894 additions & 0 deletions js/canvasjs.min.js

Large diffs are not rendered by default.

118 changes: 117 additions & 1 deletion js/cointools.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

// https://min-api.cryptocompare.com/data/histominute?fsym='+symbol+'&tsym=USD&limit=1440&e=CCCAGG

// save settings
const saveSettings = (msgbox = true) => {
let settings = {};
Expand All @@ -9,6 +11,8 @@ const saveSettings = (msgbox = true) => {
settings['amount'] = $('input#amount').val();
settings['convert_from'] = $('input#convert_from').val();
settings['convert_to'] = $('input#convert_to').val();
settings['convert_from_history'] = $('input#convert_from_history').val();
settings['convert_to_history'] = $('input#convert_to_history').val();
chrome.storage.sync.set({
cointools: settings
}, function() {
Expand Down Expand Up @@ -209,6 +213,7 @@ const getRankingTable = (currency, dom, limit = 200) => {
logit('Response: ' + request.responseText);
logit('Error: ' + error );
logit('Status: ' + status);
dom.html("");
},
complete: function(data) {
logit(get_text("api_finished", "API Finished") + ": " + api);
Expand All @@ -219,6 +224,7 @@ const getRankingTable = (currency, dom, limit = 200) => {
logit('Response: ' + request.responseText);
logit('Error: ' + error );
logit('Status: ' + status);
dom.html("");
},
complete: function(data) {
logit(get_text("api_finished", "API Finished") + ": " + api);
Expand Down Expand Up @@ -320,7 +326,9 @@ const getCoinReport = (result, currency = '') => {
s += get_text("24h_volume_cur", "24 Hour Total Market Cap") + " (" + cur + "): " + result['24h_volume_' + currency] + "\n";
s += get_text("market_cap_cur", "Total Market Cap") + " (" + cur + "): " + result['market_cap_' + currency] + "\n";
}
s += get_text("last_updated", "Last Updated") + ": " + result['last_updated'] + "\n";
let dateobject = new Date(result['last_updated'] * 1000);
let datestring = dateobject.toISOString();
s += get_text("last_updated", "Last Updated") + ": " + datestring + "\n";
return s;
}

Expand Down Expand Up @@ -364,6 +372,103 @@ const processConversion = (s) => {
}
}

// get history
const getHistory = (a, b, dom) => {
let api = "https://min-api.cryptocompare.com/data/histoday?fsym=" + a + "&tsym=" + b + "&limit=30&e=CCCAGG";
logit("calling " + api);
dom.html('<img src="images/loading.gif" />');
$.ajax({
type: "GET",
url: api,
success: function(data) {
if (data && data.Data && data.Response == 'Success') {
let data_open = [];
let data_close = [];
let data_high = [];
let data_low = [];
let arr = data.Data;
let datalen = arr.length;
for (let i = 0; i < datalen; ++ i) {
let date = new Date(arr[i].time * 1000);
data_open.push({x: date, y: arr[i].open});
data_close.push({x: date, y: arr[i].close});
data_high.push({x: date, y: arr[i].high});
data_low.push({x: date, y: arr[i].low});
}
let chart = new CanvasJS.Chart("chartContainer", {
title:{
text: a + " => " + b
},
axisY:[{
title: b,
lineColor: "#C24642",
tickColor: "#C24642",
labelFontColor: "#C24642",
titleFontColor: "#C24642",
suffix: "k"
}],
toolTip: {
shared: true
},
legend: {
cursor: "pointer",
itemclick: function(e) {
if (typeof (e.dataSeries.visible) === "undefined" || e.dataSeries.visible) {
e.dataSeries.visible = false;
} else {
e.dataSeries.visible = true;
}
e.chart.render();
}
},
data: [{
type: "line",
name: "Open",
color: "#369EAD",
showInLegend: true,
axisYIndex: 1,
dataPoints: data_open
},
{
type: "line",
name: "Close",
color: "#C24642",
axisYIndex: 0,
showInLegend: true,
dataPoints: data_close
},
{
type: "line",
name: "Low",
color: "blue",
axisYIndex: 0,
showInLegend: true,
dataPoints: data_low
},
{
type: "line",
name: "High",
color: "#7F6084",
axisYType: "secondary",
showInLegend: true,
dataPoints: data_high
}]
});
chart.render();
}
},
error: function(request, status, error) {
logit('Response: ' + request.responseText);
logit('Error: ' + error );
logit('Status: ' + status);
dom.html("");
},
complete: function(data) {
logit(get_text("api_finished", "API Finished") + ": " + api);
}
});
}

// on document ready
document.addEventListener('DOMContentLoaded', function() {
// init tabs
Expand Down Expand Up @@ -401,6 +506,8 @@ document.addEventListener('DOMContentLoaded', function() {
$("input#amount").val(settings['amount']);
$("input#convert_from").val(settings['convert_from']);
$("input#convert_to").val(settings['convert_to']);
$("input#convert_from_history").val(settings['convert_from_history']);
$("input#convert_to_history").val(settings['convert_to_history']);
processConversion(conversion);
//general - api https://api.coinmarketcap.com/v1/global/
getGeneralData(currency, $('div#general_div'));
Expand Down Expand Up @@ -449,4 +556,13 @@ document.addEventListener('DOMContentLoaded', function() {
$('button#btn_clear').click(function() {
$('textarea#convert_result').text('');
});
// history data
$('button#btn_history').click(function() {
saveSettings(false);
let a = $('input#convert_from_history').val();
let b = $('input#convert_to_history').val();
if ((a != '') && (b != '')) {
getHistory(a, b, $('div#chartContainer'));
}
});
}, false);
5 changes: 5 additions & 0 deletions js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,9 @@ const validateResponse = (response) => {
// remove invalid characters for HTML id
const removeInvalid = (x) => {
return x.replace("-", "");
}

// timestamp to Date
const getDateString = (ts) => {
return new Date(ts * 1000).toISOString().substring(0, 10);
}
8 changes: 8 additions & 0 deletions js/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ const translation = (lang) => {
translate_text($('h4#text_total_market_cap_usd_24'), lang, 'total_market_cap_24_usd');
translate_text($('option#text_select_a_currency'), lang, 'text_select_a_currency');
translate_text($('a#text_tool'), lang, 'text_tool');
translate_text($('a#text_history'), lang, 'history');
translate_text($('h4#text_currency_convertor'), lang, 'text_currency_convertor');
translate_text($('h4#text_history_data'), lang, 'text_history_data');
translate_text($('button#btn_convert'), lang, 'convert');
translate_text($('button#btn_history'), lang, 'query');
translate_text($('button#btn_clear'), lang, 'clear');
translate_text($('option#source_type'), lang, 'source_type');
translate_text($('option#target_type'), lang, 'target_type');
Expand All @@ -52,6 +55,11 @@ const get_lang = () => {
case 'en-us': return (translation_english);
case 'zh-hk': return (translation_traditional_chinese);
case 'pt-br': return (translation_portuguese);
case 'nl-nl': return (translation_dutch);
case 'tr-tr': return (translation_turkish);
case 'es-sp': return (translation_spanish);
case 'it-it': return (translation_italian);
case 'bn-bd': return (translation_bengali);
}
}

Expand Down
3 changes: 3 additions & 0 deletions lang/bn-bd.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
'use strict';

let translation_bengali = {
'history': 'ইতিহাস',
'text_history_data': 'ইতিহাস তথ্য',
'query': 'প্রশ্ন',
'id': 'আইডি',
'available_supply': 'উপলব্ধ সরবরাহ',
'total_supply': 'সর্বমোট সরবরাহ',
Expand Down
3 changes: 3 additions & 0 deletions lang/en-us.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
'use strict';

let translation_english = {
'history': 'History',
'text_history_data': 'History Data',
'query': 'Query',
'id': 'ID',
'available_supply': 'Available Supply',
'total_supply': 'Total Supply',
Expand Down
3 changes: 3 additions & 0 deletions lang/es-sp.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
'use strict';

let translation_spanish = {
'history': 'historia',
'text_history_data': 'Datos históricos',
'query': 'Consulta',
'id': 'ID',
'available_supply': 'Oferta Disponible',
'total_supply': 'Oferta Total',
Expand Down
5 changes: 4 additions & 1 deletion lang/it-it.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
'use strict';

let translation_italian = {
'history': 'storia',
'text_history_data': 'Dati storici',
'query': 'domanda',
'id': 'ID',
'available_supply': 'Quantità Erogata',
'total_supply': 'Quantità Totale',
Expand Down Expand Up @@ -51,4 +54,4 @@ let translation_italian = {
'total_market_cap': 'Capitalizzazione di Mercato totale',
'total_24_hour_volumn': 'Volume delle ultime 24 ore',
'last_updated': 'Ultimo aggiornamento'
}
}
3 changes: 3 additions & 0 deletions lang/nl-nl.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
'use strict';

let translation_dutch = {
'history': 'geschiedenis',
'text_history_data': 'Geschiedenisgegevens',
'query': 'vraag',
'id': 'ID',
'available_supply': 'Beschikbare levering',
'total_supply': 'Totale levering',
Expand Down
3 changes: 3 additions & 0 deletions lang/pt-br.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
'use strict';

let translation_portuguese = {
'history': 'história',
'text_history_data': 'Dados da história',
'query': 'Inquerir',
'id': 'Identidade',
'available_supply': 'Suprimento disponível',
'total_supply': 'Suprimento total',
Expand Down
3 changes: 3 additions & 0 deletions lang/tr-tr → lang/tr-tr.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
'use strict';

let translation_turkish = {
'history': 'Tarihçe',
'text_history_data': 'Geçmiş Verileri',
'query': 'Sorgu',
'id': 'Kimlik',
'available_supply': 'Kullanılabilir Miktar',
'total_supply': 'Toplam Miktar',
Expand Down
3 changes: 3 additions & 0 deletions lang/zh-cn.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
'use strict';

let translation_simplified_chinese = {
'history': '历史',
'text_history_data': '历史数据',
'query': '查询',
'id': 'ID',
'available_supply': '存量',
'total_supply': '总供给量',
Expand Down
3 changes: 3 additions & 0 deletions lang/zh-hk.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
'use strict';

let translation_traditional_chinese = {
'history': '歷史',
'text_history_data': '歷史數據',
'query': '詢問',
'id': 'ID',
'available_supply': '存量',
'total_supply': '總供給量',
Expand Down
37 changes: 29 additions & 8 deletions main.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@
<meta charset="UTF-8"/>
<title>SteemIt Tools</title>
<meta name="author" content="@justyy">
<script src="lang/bn-bd.js"></script>
<script src="lang/en-us.js"></script>
<script src="lang/zh-cn.js"></script>
<script src="lang/zh-hk.js"></script>
<script src="lang/pt-br.js"></script>
<script src="js/constants.js"></script>
<script src="lang/nl-nl.js"></script>
<script src="lang/tr-tr.js"></script>
<script src="lang/it-it.js"></script>
<script src="lang/es-sp.js"></script>
<script src="js/constants.js"></script>
<script src="js/jquery-3.2.1.min.js"></script>
<script src="js/canvasjs.min.js"></script>
<script src="js/Chart.min.js"></script>
<script src="js/chartjs-plugin-streaming.js"></script>
<script src="js/amcharts.js"></script>
Expand Down Expand Up @@ -38,6 +44,7 @@
<li><a id="text_rank" href="#tabs-rank">Rank</a></li>
<li><a id="text_chart" href="#tabs-chart">Charts</a></li>
<li><a id="text_tool" href="#tabs-tool">Tools</a></li>
<li><a id="text_history" href="#tabs-history">History</a></li>
<li><a id="text_setting" href="#tabs-setting">Setting</a></li>
<li><a id="text_log" href="#tabs-log">Log</a></li>
</ul>
Expand All @@ -60,19 +67,28 @@ <h4 id="text_total_market_cap_usd_24">24 Hour Total Market Cap (USD)</h4>
<h4 id="text_currency_convertor">Cryptocurrency Converter Calculator</h4>
<form class='form-inline'>
<input class="form-control" style='width: 180px' type='number' value="1.0" id='amount' placeholder="Amount">
<input type=text list='convert_from_list' class="form-control" style='width: 170px' id='convert_from' />
<input type=text list='convert_from_list' class="form-control" style='width: 150px' id='convert_from' />
<datalist id='convert_from_list'>
<option id='source_type' value=''>From Currency</option>
</datalist>
<input type=text list='convert_to_list' class="form-control" style='width: 170px' id='convert_to'>
<input type=text list='convert_to_list' class="form-control" style='width: 150px' id='convert_to'>
<datalist id='convert_to_list'>
<option id='target_type' value=''>Convert To</option>
</datalist>
<button type='button' class="form-control" style='width: 90px' id='btn_convert'>Convert</button>
<button type='button' class="form-control" style='width: 90px' id='btn_clear'>Clear</button>
<button type='button' class="form-control" style='width: 120px' id='btn_convert'>Convert</button>
<button type='button' class="form-control" style='width: 120px' id='btn_clear'>Clear</button>
</form>
<textarea style='background:black; color:white;' readonly id='convert_result' class=form-control rows=20></textarea>
</div>
</div>
<div id="tabs-history">
<h4 id="text_history_data">History Data</h4>
<form class='form-inline'>
<input type=text list='convert_from_list' class="form-control" style='width: 150px' id='convert_from_history' />
<input type=text list='convert_to_list' class="form-control" style='width: 150px' id='convert_to_history'>
<button type='button' class="form-control" style='width: 120px' id='btn_history'>Query</button>
</form>
<div id="chartContainer" style="height: 450px; width: 750px;"></div>
</div>
<div id="tabs-setting">
<h4 id="text_local_currency">Local Currency</h4>
<select class="form-control" id="currency">
Expand All @@ -84,11 +100,16 @@ <h4 id="text_ui_language">UI Language</h4>
<option value="zh-cn">简体中文</option>
<option value="zh-hk">繁體中文</option>
<option value="pt-br">Português</option>
<option value="nl-nl">Nederlands</option>
<option value="tr-tr">Türk</option>
<option value="es-sp">Español</option>
<option value="it-it">italiano</option>
<option value="bn-bd">বাঙালি</option>
</select>
<h4 id="text_convert">Conversion</h4>
<textarea class="form-control" id='conversion' rows=10 style='width:100%'>steem-dollars bitcoin</textarea>
<br />
<button class="form-control" style='width: 70px' id="setting_save_btn">Save</button>
<button class="form-control" style='width: 130px' id="setting_save_btn">Save</button>
</div>
<div id="tabs-log">
<h4><span id='proudly_brought_to_you_by'>Proudly brought to you by</span> <a target=_blank href="https://steemit.com/@justyy">@justyy</a></h4>
Expand All @@ -97,4 +118,4 @@ <h4><span id='proudly_brought_to_you_by'>Proudly brought to you by</span> <a tar
</div>
</div>
</body>
</html>
</html>
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Coin Tools",
"short_name": "cointools",
"default_locale": "en",
"version": "0.0.6",
"version": "0.0.7",
"browser_action": {
"default_icon": "icon.png",
"default_title": "Coin Tools",
Expand Down

0 comments on commit 717f663

Please sign in to comment.