Skip to content

Instantly share code, notes, and snippets.

@truthdoug
Created September 13, 2023 13:26
Show Gist options
  • Save truthdoug/d7e6bfc60f333d7800f555e221dc2533 to your computer and use it in GitHub Desktop.
Save truthdoug/d7e6bfc60f333d7800f555e221dc2533 to your computer and use it in GitHub Desktop.
Bookmarklet for copying some info about a JIRA ticket in a format that works well for slack
const title=document.querySelector("title");
var text=title.innerText.replace(' - JIRA','');
if (text.length > 75) {
text=text.substr(0,75) + '…';
}
const link=`<a href="${document.location.href}">${text}</a>`;
const blobHtml = new Blob([link], { type: "text/html" });
const blobText = new Blob([text], { type: "text/plain" });
const data = [new ClipboardItem({
["text/plain"]: blobText,
["text/html"]: blobHtml,
})];
navigator.clipboard.write(data).then(
() => {alert('Ticket info copied');},
() => {}
);
/**
generated from https://caiorss.github.io/bookmarklet-maker/
javascript:(function()%7Bconst%20title%3Ddocument.querySelector(%22title%22)%3B%0Avar%20text%3Dtitle.innerText.replace('%20-%20JIRA'%2C'')%3B%0Aif%20(text.length%20%3E%2075)%20%7B%0A%20%20%20%20text%3Dtext.substr(0%2C75)%20%2B%20'%E2%80%A6'%3B%20%0A%7D%0Aconst%20link%3D%60%3Ca%20href%3D%22%24%7Bdocument.location.href%7D%22%3E%24%7Btext%7D%3C%2Fa%3E%60%3B%0Aconst%20blobHtml%20%3D%20new%20Blob(%5Blink%5D%2C%20%7B%20type%3A%20%22text%2Fhtml%22%20%7D)%3B%0Aconst%20blobText%20%3D%20new%20Blob(%5Btext%5D%2C%20%7B%20type%3A%20%22text%2Fplain%22%20%7D)%3B%0Aconst%20data%20%3D%20%5Bnew%20ClipboardItem(%7B%0A%20%20%20%20%5B%22text%2Fplain%22%5D%3A%20blobText%2C%0A%20%20%20%20%5B%22text%2Fhtml%22%5D%3A%20blobHtml%2C%0A%7D)%5D%3B%0A%0Anavigator.clipboard.write(data).then(%0A%20%20%20%20()%20%3D%3E%20%7Balert('Ticket%20info%20copied')%3B%7D%2C%0A%20%20%20%20()%20%3D%3E%20%7B%7D%0A)%3B%7D)()%3B
**/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment