mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-16 06:18:35 +02:00
15 lines
316 B
JavaScript
15 lines
316 B
JavaScript
/*
|
|
copy the selected text to clipboard
|
|
*/
|
|
function copySelection() {
|
|
var selectedText = window.getSelection().toString().trim();
|
|
|
|
if (selectedText) {
|
|
document.execCommand("Copy");
|
|
}
|
|
}
|
|
|
|
/*
|
|
Add copySelection() as a listener to mouseup events.
|
|
*/
|
|
document.addEventListener("mouseup", copySelection); |