bigbuffet-rw/app/soapbox/utils/copy.ts
marcin mikołajczak 3855d966af Add 'View event on {domain}'
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
2022-12-06 22:33:17 +01:00

23 lines
487 B
TypeScript

const copy = (text: string) => {
if (navigator.clipboard) {
navigator.clipboard.writeText(text);
} else {
const textarea = document.createElement('textarea');
textarea.textContent = text;
textarea.style.position = 'fixed';
document.body.appendChild(textarea);
try {
textarea.select();
document.execCommand('copy');
} catch {
// Do nothing
} finally {
document.body.removeChild(textarea);
}
}
};
export default copy;