Skip to content

Instantly share code, notes, and snippets.

@KevCui
Last active January 30, 2021 04:25
Show Gist options
  • Save KevCui/e6dc31474a7af0a91c79d777ec765cca to your computer and use it in GitHub Desktop.
Save KevCui/e6dc31474a7af0a91c79d777ec765cca to your computer and use it in GitHub Desktop.
Auto copy selected text
// ==UserScript==
// @name auto-copy
// @include *
// @grant GM_setClipboard
// ==/UserScript==
function getSelectedText() {
// console.log(getSelection().anchorNode.nodeName);
if (window.getSelection().anchorNode.nodeName== "#text") {
return window.getSelection().toString();
}
return false;
}
function doSomethingWithSelectedText() {
var selectedText = getSelectedText();
if (selectedText) {
GM_setClipboard (selectedText);
}
}
document.onmouseup = doSomethingWithSelectedText;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment