Skip to content

Instantly share code, notes, and snippets.

@andreasvirkus
Created November 5, 2018 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreasvirkus/04236a22b968dfa0a11c66a4dc28b54a to your computer and use it in GitHub Desktop.
Save andreasvirkus/04236a22b968dfa0a11c66a4dc28b54a to your computer and use it in GitHub Desktop.
export const copy = async (text) => {
try {
await navigator.clipboard.writeText(text)
console.log('Text copied:', text)
} catch (err) {
console.error('Failed to copy:', err)
}
}
export const paste = async (selector, readOnly = false) => {
const contents = await navigator.clipboard.readText()
if (!readOnly) document.querySelector(selector).innerText = contents
return contents
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment