Skip to content

Instantly share code, notes, and snippets.

@RightHandedMonkey
Last active May 18, 2023 12:11
Show Gist options
  • Save RightHandedMonkey/5b4ae02e5013a5fbce62a04e31209ea0 to your computer and use it in GitHub Desktop.
Save RightHandedMonkey/5b4ae02e5013a5fbce62a04e31209ea0 to your computer and use it in GitHub Desktop.
JIRA Issue Copy Button (tampermonkey script) - Adds a copy button to JIRA issues for pasting into slack and others
// ==UserScript==
// @name Jira Issue Copy Button
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Add a copy button on the tickets so we can Copy ticket number and summary with just one click to share somewhere else
// @author Sam Bossen
// @match https://jira.audible.com/*
// @grant none
// ==/UserScript==
(function() {
function copyToClipboard(element) {
var $temp = $("<input>");
$("body").append($temp);
$temp.val($(element).text()).select();
document.execCommand("copy");
$temp.remove();
}
function cleanUpUrl(text) {
let result = text.replace(/\[/g, "(");
result = result.replace(/\]/g, ")");
return result;
}
function setupCopyButton() {
//Create text to copy
var $issuetext = $('<p id="issue-copy-text" style="display: none;"></p>');
$("#issue-copy-text").remove();
$('.aui-page-header-main #summary-val').after($issuetext);
//Create link to copy
var $linktext = $('<p id="issue-copy-link" style="display: none;"></p>');
$("#issue-copy-link").remove();
$('.aui-page-header-main #summary-val').after($linktext);
//source key
var $keyval = $('#key-val')
var $summaryval = $('#summary-val')
//create text button
$("#issue-copy-text").html("https://jira.audible.com/browse/"+$keyval.text()+" - "+$summaryval.text());
var $yourButton = $('<a id="issue-copy-button" class="aui-button toolbar-trigger">Copy</a>');
$yourButton.on('click', function() {
copyToClipboard('#issue-copy-text');
});
$("#issue-copy-button").remove();
$('.aui-page-header-main #summary-val').after($yourButton);
//create copy link
$("#issue-copy-link").html("["+$keyval.text()+" - "+cleanUpUrl($summaryval.text())+"](https://jira.audible.com/browse/"+$keyval.text()+")");
var $linkButton = $('<a id="issue-copy-link-button" class="aui-button toolbar-trigger">Slack Link</a>');
$linkButton.on('click', function() {
copyToClipboard('#issue-copy-link');
});
$("#issue-copy-link-button").remove();
$('.aui-page-header-main #summary-val').after($linkButton);
}
setupCopyButton();
Events.bind(EventTypes.NEW_CONTENT_ADDED, function(e, jiraContext, reason) {
setupCopyButton();
});
$(document).ready(function () {
setupCopyButton();
$(window).resize(function() {
setupCopyButton();
});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment