Last active
March 4, 2016 14:20
-
-
Save rlemon/4633f03d82f8e021c7f3 to your computer and use it in GitHub Desktop.
tab reply
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
"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