Chocobozzz/PeerTube

View on GitHub
client/src/root-helpers/utils.ts

Summary

Maintainability
A
0 mins
Test Coverage
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
}