mirror of
https://github.com/v1k45/pastepass.git
synced 2026-01-10 07:58:08 +00:00
23 lines
751 B
JavaScript
23 lines
751 B
JavaScript
function copyText(event, selector) {
|
|
var pastedContent = document.querySelector(selector);
|
|
|
|
// Create a range and select the text
|
|
var range = document.createRange();
|
|
range.selectNode(pastedContent);
|
|
window.getSelection().removeAllRanges();
|
|
window.getSelection().addRange(range);
|
|
|
|
// Copy the selected text
|
|
if (navigator.clipboard) {
|
|
navigator.clipboard.writeText(pastedContent.innerText).then(function () {
|
|
event.dataset.tooltip = 'Copied!';
|
|
event.innerText = 'Copied!';
|
|
setTimeout(function () {
|
|
event.innerText = 'Copy content';
|
|
event.dataset.tooltip = 'Click to copy';
|
|
event.blur();
|
|
}, 1000);
|
|
});
|
|
}
|
|
}
|