Skip to content

Instantly share code, notes, and snippets.

@simonwep
Last active January 15, 2020 15:59
Show Gist options
  • Save simonwep/d2ac7a9a64347c8a99bb0e69c0535be5 to your computer and use it in GitHub Desktop.
Save simonwep/d2ac7a9a64347c8a99bb0e69c0535be5 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Kraken speech
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://trade.kraken.com/*
// @grant none
// ==/UserScript==
(() => {
function speak(message) {
const msg = new SpeechSynthesisUtterance(message);
const voices = speechSynthesis.getVoices();
msg.voice = voices.find(v => v.name === 'Google UK English Male') ||
voices.find(v => v.lang.startsWith('en'));
speechSynthesis.speak(msg);
}
function strip(number) {
return (parseFloat(number).toPrecision(12));
}
let lastValue = null;
setInterval(() => {
const raw = parseFloat(
document.querySelector('#price-ticker').innerText
);
if (lastValue === null) {
return lastValue = raw;
} else if (lastValue !== raw) {
const diff = strip(lastValue - raw);
let negative = diff < 0;
const absDiff = Math.abs(diff);
const eur = Number(parseInt(absDiff));
const cent = Number(parseInt((absDiff % 1) * 100));
const mid = (eur && cent && ' and ') || '';
if (eur || cent) {
const start = `Price ${negative ? 'went up to' : 'dropped'} `;
const end = `around ${eur ? `${eur} Euro ` : ''} ${mid} ${cent ? `${cent} Cent` : ''}`;
const str = start + end;
console.log({absDiff, eur, cent, str});
speak(str);
}
}
lastValue = raw;
}, 1000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment