Skip to content

Instantly share code, notes, and snippets.

@allardhoeve
Forked from stefanmaric/copy-to-clipboard-bookmarklet.md
Last active October 7, 2020 14:10
Show Gist options
  • Save allardhoeve/7b138166cebcc051516624dc89bc21f4 to your computer and use it in GitHub Desktop.
Save allardhoeve/7b138166cebcc051516624dc89bc21f4 to your computer and use it in GitHub Desktop.
Create Bookmarklet (browser bookmark that executes Javsacript) to copy a given text to Clipboard

Copy Jira template to browser

Create Bookmarklet (browser bookmark that executes Javsacript) to copy a given text to Clipboard.

This is the base javascript:

(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)
})(`
*{{Context}}*
what, where, how to reproduce

*{{Goal}}*
desired behavior for the user, or the question to be answered

*{{QA}}*
AC and scenarios

*{{UX/UI}}* 
wireframes, UI designs

*{{Solution space}}* 
describing possibilities, starting points and discussion results
`)

Minify it (you can use UglifyJS to get something like this:

!function(e){...}}()

Prefix it with javascript::

javascript:!function(e){var n=document.createElement("textarea"),o=document.getSelection();n.textContent="\n*{{Context}}*\nwhat, where, how to reproduce\n\n*{{Goal}}*\ndesired behavior for the user, or the question to be answered\n\n*{{QA}}*\nAC and scenarios\n\n*{{UX/UI}}* \nwireframes, UI designs\n\n*{{Solution space}}* \ndescribing possibilities, starting points and discussion results\n\n",document.body.appendChild(n),o.removeAllRanges(),n.select(),document.execCommand("copy"),o.removeAllRanges(),document.body.removeChild(n)}();
@Rhuijgen
Copy link

Rhuijgen commented Sep 23, 2020

h3. "What is the goal of the story?"
h4. Scenario's

  • AC**
  • -Out of scope-

h4. Detailing
Anything useful for implementation

javascript:!function(e){var n=document.createElement("textarea"),o=document.getSelection();n.textContent="h3. What is the goal of the story?\n\n h4. Scenario's\n * AC**\n * -Out of scope-\n\n h4. Detailing\n Anything useful for implementation \n\n",document.body.appendChild(n),o.removeAllRanges(),n.select(),document.execCommand("copy"),o.removeAllRanges(),document.body.removeChild(n)}();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment