Created
August 15, 2015 22:10
-
-
Save raf924/ff824f7fac9673c67fc5 to your computer and use it in GitHub Desktop.
Better autocompletion for hack.chat
This file contains 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
var orig_keydown = $("#chatinput").onkeydown; | |
$("#chatinput").onkeydown = function(e){ | |
if(e.keyCode==9){ | |
e.preventDefault(); | |
var pos = e.target.selectionStart || 0; | |
var text = e.target.value; | |
var index = text.lastIndexOf('@', pos); | |
if (index >= 0) { | |
var stub = text.substring(index + 1, pos); | |
// Search for nick beginning with stub | |
var nicks = onlineUsers.filter(function(nick) { | |
return nick.indexOf(stub) == 0; | |
}); | |
if(nicks.length==0){ | |
insertAtCursor(nicks[0].substr(stub.length)); | |
} | |
insertAtCursor(nicks[0].substr(stub.length)+" "); | |
} | |
} | |
else{ | |
orig_keydown(e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment