chrome bookmarklet copy text code example

Example: chrome bookmarklet copy text

// This needs to be minified (and prefixed) to work
// I just put the full function here to better show what the code is doing

// Use the bottom line of code and replace "Text To Copy" with your own
// text and you're good to go! 

(function (text) {
  var node = document.createElement('textarea')
  var selection = document.getSelection()

  node.textContent = text
  document.body.appendChild(node)

  selection.removeAllRanges()
  node.select()
  document.execCommand('copy')

  selection.removeAllRanges()
  document.body.removeChild(node)
})('Text To Copy')

// here is the minified:
javascript:!function(a){var b=document.createElement("textarea"),c=document.getSelection();b.textContent=a,document.body.appendChild(b),c.removeAllRanges(),b.select(),document.execCommand("copy"),c.removeAllRanges(),document.body.removeChild(b)}("Text To Copy");