Skip to content

Instantly share code, notes, and snippets.

@matthewmorrone
Created January 16, 2015 20:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewmorrone/d4164e34fd376257d81a to your computer and use it in GitHub Desktop.
Save matthewmorrone/d4164e34fd376257d81a to your computer and use it in GitHub Desktop.
clipboard nonsense
//$(document).bind({ cut: function () {}, copy: function () {}, paste: function () {} });
window.logCut = function () {
$(document).on("cut", function (e) {
var selectedText = (window.getSelection ? window.getSelection() : document.getSelection ? document.getSelection() : document.selection.createRange().text);
if (!selectedText || selectedText == "") {
if (document.activeElement.selectionStart) {
selectedText = document.activeElement.value.substring(document.activeElement.selectionStart.document.activeElement.selectionEnd);
}
}
console.log(selectedText.toString());
});
}
window.logCopy = function () {
$(document).on("copy", function (e) {
var selectedText = (window.getSelection ? window.getSelection() : document.getSelection ? document.getSelection() : document.selection.createRange().text);
if (!selectedText || selectedText == "") {
if (document.activeElement.selectionStart) {
selectedText = document.activeElement.value.substring(document.activeElement.selectionStart.document.activeElement.selectionEnd);
}
}
console.log(selectedText.toString());
});
}
window.logPaste = function () {
$(document).on("paste", function (e) {
var pastedText = "";
if (window.clipboardData && window.clipboardData.getData) {
pastedText = window.clipboardData.getData('Text');
} else if (e.originalEvent.clipboardData && e.originalEvent.clipboardData.getData) {
pastedText = e.originalEvent.clipboardData.getData('text/plain');
}
console.log(pastedText);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment