mirror of https://github.com/Chocobozzz/PeerTube
25 lines
519 B
TypeScript
25 lines
519 B
TypeScript
function copyToClipboard (text: string, container?: HTMLElement) {
|
|
if (!container) container = document.body
|
|
|
|
const el = document.createElement('textarea')
|
|
el.value = text
|
|
el.setAttribute('readonly', '')
|
|
el.style.position = 'absolute'
|
|
el.style.left = '-9999px'
|
|
container.appendChild(el)
|
|
el.select()
|
|
document.execCommand('copy')
|
|
container.removeChild(el)
|
|
}
|
|
|
|
function wait (ms: number) {
|
|
return new Promise<void>(res => {
|
|
setTimeout(() => res(), ms)
|
|
})
|
|
}
|
|
|
|
export {
|
|
copyToClipboard,
|
|
wait
|
|
}
|