mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-20 00:04:14 +02:00
b1154b6caf
* selection-to-text example * update icon * update icon * use clipboard icon * update with requested changes * updated strict version and wrapped clipboard copy in setTimeout to force permissions * add note about clipboardWrite permissions inside browser event. removed permissions and setTimeout
15 lines
317 B
JavaScript
15 lines
317 B
JavaScript
/*
|
|
copy the selected text to clipboard
|
|
*/
|
|
function copySelection(e) {
|
|
var selectedText = window.getSelection().toString().trim();
|
|
|
|
if (selectedText) {
|
|
document.execCommand("Copy");
|
|
}
|
|
}
|
|
|
|
/*
|
|
Add copySelection() as a listener to mouseup events.
|
|
*/
|
|
document.addEventListener("mouseup", copySelection); |