Skip to content

Instantly share code, notes, and snippets.

@rlemon
Last active March 4, 2016 14:20
Show Gist options
  • Save rlemon/4633f03d82f8e021c7f3 to your computer and use it in GitHub Desktop.
Save rlemon/4633f03d82f8e021c7f3 to your computer and use it in GitHub Desktop.
tab reply
"use strict";
const input = document.getElementById('input');
const chat = document.getElementById('chat');
input.addEventListener('keydown', processKeydown);
function processKeydown(event) {
if( event.which === 9 && input.value.length === 0 ) {
event.preventDefault();
const last = getLastReply();
input.value = `:${last} `;
}
}
function getLastReply() {
const mentions = chat.querySelectorAll('.mention');
const lastMention = Array.from(mentions).pop();
return lastMention.parentNode.parentNode.id.split('-')[1];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment