Skip to content

Instantly share code, notes, and snippets.

@nathanielbd
Last active July 9, 2020 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathanielbd/505954bab95ae905c9475ae976521962 to your computer and use it in GitHub Desktop.
Save nathanielbd/505954bab95ae905c9475ae976521962 to your computer and use it in GitHub Desktop.
Script for typing on morsecode.me
// CTRL-SHIFT-i, copy and paste into the console, hit `ENTER`:
// You can now focus on the screen and type
// ---BEGIN---
var table = Object.fromEntries(Object.entries(Translator.alphabet()).map(([k, v]) => ([v, k])))
var button = document.getElementById("key");
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function dit() {
$(button).trigger("mousedown");
await sleep(100);
$(button).trigger("mouseup");
return this;
}
async function dah() {
$(button).trigger("mousedown");
await sleep(300);
$(button).trigger("mouseup");
return this;
}
document.addEventListener("keypress", async function(e){
for (var character in table) {
if (character === e.key) {
var ditdah = table[e.key];
[...ditdah].reduce((composing, curr) => curr === '.' ? composing.then(dit) : composing.then(dah), sleep(100));
}
}
});
// ---END---
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment