Last active
January 30, 2021 04:25
-
-
Save KevCui/e6dc31474a7af0a91c79d777ec765cca to your computer and use it in GitHub Desktop.
Auto copy selected text
This file contains hidden or 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
// ==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