Last active
June 3, 2017 07:26
-
-
Save crakaC/1f82000865e150c648667d7eb9fcb48b to your computer and use it in GitHub Desktop.
Shiftキー単押しで:poop:をtextareaに挿入するやつ
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 shit = false; | |
var emoji = ':nicoru:'; | |
var ta = document.querySelector("textarea"); | |
document.onkeydown = function(e){ | |
shit = e.shiftKey; | |
} | |
document.onkeyup = function(e){ | |
if(e.keyCode == 16 && shit){ | |
var cursorPos = ta.selectionStart; | |
var v = ta.value; | |
var before = v.substring(0, cursorPos); | |
var after = v.substring(cursorPos, v.length); | |
ta.value = before + emoji + after; | |
ta.selectionStart = ta.selectionEnd = before.length + emoji.length; | |
} | |
shit = false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
トゥート直前にShitキーで挿入した文字は消える。
なにかしら内容をキーボードで触っているとちゃんと残る。