Last active
July 9, 2020 21:23
-
-
Save nathanielbd/505954bab95ae905c9475ae976521962 to your computer and use it in GitHub Desktop.
Script for typing on morsecode.me
This file contains hidden or 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
// 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