Created
November 6, 2019 16:59
-
-
Save GitHub30/28f88a2406212caab968dc4109f957ba to your computer and use it in GitHub Desktop.
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
function getSelectedText() { | |
const activeElement = document.activeElement | |
if(activeElement && ['input', 'textarea'].includes(activeElement.tagName.toLowerCase())) { | |
return activeElement.value.substring(activeElement.selectionStart, activeElement.selectionEnd) | |
} else { | |
return getSelection().toString() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment