Skip to content

Instantly share code, notes, and snippets.

@bigfang
Last active April 13, 2020 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bigfang/d49d1e71008f7dfd51a50be0b8b8bcf0 to your computer and use it in GitHub Desktop.
Save bigfang/d49d1e71008f7dfd51a50be0b8b8bcf0 to your computer and use it in GitHub Desktop.
user script :: autocopy
// ==UserScript==
// @name autocopy
// @namespace https://bigfang.github.io
// @description Auto copy selected text
// @match *://*/*
// @run-at document-end
// @grant GM_setClipboard
// ==/UserScript==
if (typeof GM_setClipboard != 'function') alert('Your UserScript client has no GM_setClipboard support');
document.addEventListener('mouseup',
(e) => {
if (e.button != 0 || ['INPUT', 'TEXTAREA'].includes(e.target.tagName))
return;
let stext = getSelection().toString();
if (stext) {
GM_setClipboard(stext)
}
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment