-
-
Save iwathi/34f2f2802486e61eea54c6096f9c7773 to your computer and use it in GitHub Desktop.
coincheck checker for Simply.js (Pebble Watch)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$status = { | |
btc: "xxxx", | |
eth: "xx.xx", | |
etc: "xx.xx", | |
lsk: "xx.xxx", | |
fct: "xx.xx", | |
xmr: "xx.xx", | |
rep: "xx.xx", | |
xrp: "xx.xxxx", | |
zec: "xx.xx" | |
}; | |
function floatFormat( number, n ) { | |
var _pow = Math.pow( 10 , n ) ; | |
return Math.round( number * _pow ) / _pow ; | |
} | |
function updateSubtitle() { | |
var fmt = "BTC:$btc\nETH:$eth\nZEC:$zec\nXRP:$xrp"; | |
simply.subtitle(util2.format(fmt, $status)); | |
} | |
function updateBody() { | |
//var fmt = "B:$btc\nE:$eth\nZ:$zec"; | |
//simply.body(util2.format(fmt, $status)); | |
simply.body(""); | |
} | |
function zeroFill(num, fill) { | |
var padd = "0000000000"; | |
return (padd + num).slice(-fill); | |
} | |
function timeText() { | |
var now = new Date(); | |
var n = { | |
month: zeroFill(now.getMonth()+1, 2), | |
date: zeroFill(now.getDate(), 2), | |
hours: zeroFill(now.getHours(), 2), | |
minutes: zeroFill(now.getMinutes(), 2) | |
} | |
return util2.format("$month/$date - $hours:$minutes", n); | |
} | |
$tasks = { | |
btc: function() { | |
ajax({ url: 'https://coincheck.com/api/rate/btc_jpy', type:'json'}, function(data) { | |
$status.btc = Math.floor(data["rate"]); | |
updateSubtitle(); | |
}); | |
}, | |
eth: function() { | |
ajax({ url: 'https://coincheck.com/api/rate/eth_jpy', type:'json'}, function(data) { | |
$status.eth = floatFormat(data["rate"], 2); | |
updateSubtitle(); | |
}); | |
}, | |
etc: function() { | |
ajax({ url: 'https://coincheck.com/api/rate/etc_jpy', type:'json'}, function(data) { | |
$status.etc = floatFormat(data["rate"], 2); | |
updateSubtitle(); | |
}); | |
}, | |
lsk: function() { | |
ajax({ url: 'https://coincheck.com/api/rate/lsk_jpy', type:'json'}, function(data) { | |
$status.lsk = floatFormat(data["rate"], 3); | |
updateSubtitle(); | |
}); | |
}, | |
fct: function() { | |
ajax({ url: 'https://coincheck.com/api/rate/fct_jpy', type:'json'}, function(data) { | |
$status.fct = floatFormat(data["rate"], 2); | |
updateSubtitle(); | |
}); | |
}, | |
xmr: function() { | |
ajax({ url: 'https://coincheck.com/api/rate/xmr_jpy', type:'json'}, function(data) { | |
$status.xmr = floatFormat(data["rate"], 2); | |
updateSubtitle(); | |
}); | |
}, | |
rep: function() { | |
ajax({ url: 'https://coincheck.com/api/rate/rep_jpy', type:'json'}, function(data) { | |
$status.rep = floatFormat(data["rate"], 2); | |
updateSubtitle(); | |
}); | |
}, | |
xrp: function() { | |
ajax({ url: 'https://coincheck.com/api/rate/xrp_jpy', type:'json'}, function(data) { | |
$status.xrp = floatFormat(data["rate"], 4); | |
updateSubtitle(); | |
}); | |
}, | |
zec: function() { | |
ajax({ url: 'https://coincheck.com/api/rate/zec_jpy', type:'json'}, function(data) { | |
$status.zec = floatFormat(data["rate"], 2); | |
updateSubtitle(); | |
}); | |
} | |
} | |
function refresh() { | |
simply.title(timeText()); | |
for (var task in $tasks) { | |
$tasks[task](); | |
} | |
updateSubtitle(); | |
updateBody(); | |
} | |
// イベントハンドラ | |
simply.on('singleClick', function(e) { | |
simply.vibe(); | |
refresh(); | |
}); | |
simply.on('accelTap', function(e) { | |
simply.vibe(); | |
refresh(); | |
}); | |
// エントリポイント | |
simply.begin = function() { | |
try { | |
console.log('Simply.js start!'); | |
simply.fullscreen(true); | |
refresh(); | |
setInterval(refresh, 60000); | |
} catch (e) { | |
console.log(e); | |
simply.body(e); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment