Last active
May 29, 2019 10:49
-
-
Save DanielSundberg/5edbcefb0231b29db87d to your computer and use it in GitHub Desktop.
Greasemonkey script. In JIRA, insert a summary line next to the project/case number path. This is what I usually want to copy when composing a mail or a refer to a case.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name JiraCopyKeyAndSummary | |
// @author Daniel Sundberg | |
// @namespace https://github.com/DanielSundberg | |
// @include https://jira.*/browse/* | |
// @version 0.2 | |
// @grant GM.setClipboard | |
// ==/UserScript== | |
// v0.2 2019-05-29 | |
// -Updated for JIRA 7.12 | |
// -Replaced key and summary label with copy button | |
var keyVal = document.getElementById('key-val').innerHTML | |
var summaryVal = document.getElementById('summary-val') | |
// Create a string that looks nice when copied (ID-1234: This is a title) | |
var keySummary = keyVal + ': ' + summaryVal.textContent.replace(/\n|\r/g, '').trim() | |
// Insert button to the right of project/key breadcrumb | |
var breadcrumbs = document.getElementsByClassName('aui-nav-breadcrumbs') | |
function btnClick(ev) { | |
GM.setClipboard(keySummary) | |
} | |
// Create a nice looking button | |
var btn = document.createElement ('button'); | |
btn.innerHTML = 'Copy' | |
btn.setAttribute('id', 'btnContainer'); | |
breadcrumbs[0].appendChild(btn) | |
document.getElementById("btnContainer").addEventListener ( | |
"click", btnClick, false | |
); | |
addStyle = function (css) { | |
var style = document.createElement('style'); | |
style.textContent = css; | |
document.documentElement.appendChild(style); | |
return style; //optional, but convenient for changing the styling later. | |
}; | |
addStyle(` | |
#btnContainer { | |
top: 0; | |
left: 0; | |
font-size: 10px; | |
background: #091E4221; | |
border: none; | |
border-radius: 2px; | |
color: #454545; | |
opacity: 0.9; | |
padding: 2px 10px; | |
cursor: pointer; | |
margin: auto; | |
} | |
#btnContainer:hover { | |
background: #45454538; | |
} | |
#btnContainer:active { | |
background: #45454555; | |
} | |
`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment