87 lines
No EOL
2 KiB
JavaScript
87 lines
No EOL
2 KiB
JavaScript
let apiKey = 112097099066099101105123089051052072032056049055067048049078032054048051053032085080125;
|
|
let price;
|
|
let red = document.getElementById('red');
|
|
let orange = document.getElementById('orange');
|
|
let green = document.getElementById('green');
|
|
|
|
window.onload=function(){
|
|
var screen = document.getElementById('screen');
|
|
var text = [
|
|
'Peer-at Code'
|
|
];
|
|
|
|
type(text, screen);
|
|
dofetch();
|
|
};
|
|
|
|
setInterval(dofetch,60000);
|
|
|
|
function dofetch() {
|
|
fetch('https://apiv2.bitcoinaverage.com/indices/global/ticker/BTCUSD')
|
|
.then(a => {
|
|
if(!a.ok) {
|
|
throw new Error(a);
|
|
}
|
|
return a;
|
|
})
|
|
.then(a => a.json())
|
|
.then(a => {
|
|
let newp = a.ask;
|
|
if(!price) {
|
|
orange.style.display = "inherit";
|
|
price = newp;
|
|
return;
|
|
}
|
|
console.log(`${price} VS ${newp}`);
|
|
if(price < newp) {
|
|
green.style.display = "inherit";
|
|
red.style.display = "none";
|
|
orange.style.display = "none";
|
|
} else if(price > newp) {
|
|
red.style.display = "inherit";
|
|
green.style.display = "none";
|
|
orange.style.display = "none";
|
|
} else {
|
|
}
|
|
price = newp;
|
|
})
|
|
.catch(e => console.log(e));
|
|
}
|
|
|
|
function type(text, screen) {
|
|
//You have to check for lines and if the screen is an element
|
|
if(!text || !text.length || !(screen instanceof Element)) {
|
|
return;
|
|
}
|
|
|
|
//if it is not a string, you will want to make it into one
|
|
if('string' !== typeof text) {
|
|
text = text.join('\n');
|
|
}
|
|
|
|
//normalize newlines, and split it to have a nice array
|
|
text = text.replace(/\r\n?/g,'\n').split('');
|
|
|
|
//the prompt is always the last child
|
|
var prompt = screen.lastChild;
|
|
prompt.className = 'typing';
|
|
|
|
var typer = function(){
|
|
var character = text.shift();
|
|
screen.insertBefore(
|
|
//newlines must be written as a `<br>`
|
|
character === '\n'
|
|
? document.createElement('br')
|
|
: document.createTextNode(character),
|
|
prompt
|
|
);
|
|
|
|
//only run this again if there are letters
|
|
if( text.length ) {
|
|
setTimeout(typer, 300);
|
|
} else {
|
|
prompt.className = 'idle';
|
|
}
|
|
};
|
|
setTimeout(typer, 300);
|
|
}; |