Created
October 21, 2014 19:04
-
-
Save DanBrink91/7c130e71506942335332 to your computer and use it in GitHub Desktop.
Get highlighted text
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 getSelectionText() { | |
var text = ""; | |
if (window.getSelection) { | |
text = window.getSelection().toString(); | |
} else if (document.selection && document.selection.type != "Control") { | |
text = document.selection.createRange().text; | |
} | |
return text; | |
} | |
var keysDown = {}; | |
window.addEventListener("keyup", function(e){ | |
keysDown[e.keyCode] = false; | |
}); | |
window.addEventListener("keydown", function(e){ | |
keysDown[e.keyCode] = true; | |
// ctrl + ` | |
if(keysDown[192] && keysDown[17]){ | |
var text = getSelectionText(); | |
// do something with selected text | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment