Skip to content

Instantly share code, notes, and snippets.

@fgnass
Last active May 7, 2018 10:03
Show Gist options
  • Save fgnass/3f1a8845163aacba5f9a851a1d5d190d to your computer and use it in GitHub Desktop.
Save fgnass/3f1a8845163aacba5f9a851a1d5d190d to your computer and use it in GitHub Desktop.
Use arrow keys to scroll through the input history in Amazon's Alexa simulator
(function() {
let i = 0;
const el = document.querySelector('.askt-utterance__input');
el.addEventListener('keyup', function(ev) {
const req = document.querySelectorAll('.askt-dialog__message--request');
if (ev.key == 'ArrowUp') i = i >= req.length - 1 ? 0 : i + 1;
else if (ev.key == 'ArrowDown') i = i > 0 ? i - 1 : req.length - 1;
else return;
el.value = '';
document.execCommand('insertText', false, req[i].innerText);
});
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment