Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Copy JIRA issue number bookmarklet
javascript: (function() {
var id;
var descr;
var a = document.querySelector('#ghx-detail-issue .ghx-group .ghx-key dl.ghx-detail-list dd a');
if (a) {
/*side details*/
id = a.textContent;
descr = document.querySelector('#ghx-detail-issue .ghx-group .ghx-detail-summary dl.ghx-detail-list dd.ghx-detail-description').textContent;
} else if (a = document.getElementById("key-val")) {
/*full page details*/
id = a.textContent;
descr = document.querySelector('#summary-val').textContent;
} else {
var qsParam = getQueryStringParameterByName('selectedIssue');
if (qsParam) {
descr = document.querySelector('#summary-val').textContent;
id = qsParam;
}
}
if (id) {
/*window.prompt("Copy to clipboard: Ctrl+C, Enter", id);*/
sendToClipbord(id + ' ' + (descr || ''));
}
function sendToClipbord(myString) {
var textarea = document.createElement('textarea');
document.body.appendChild(textarea);
textarea.value = myString;
textarea.style.position = 'fixed';
textarea.focus();
textarea.select();
document.execCommand('Copy');
textarea.remove();
}
function getQueryStringParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
})();
javascript: (function() {
var id;
var a = document.querySelector('#ghx-detail-issue .ghx-group .ghx-key dl.ghx-detail-list dd a');
if (a) {
id = a.textContent;
} else if (a = document.getElementById("key-val")) {
id = a.textContent;
} else {
var qsParam = getQueryStringParameterByName('selectedIssue');
if (qsParam) {
id = qsParam;
}
}
if (id) {
/*window.prompt("Copy to clipboard: Ctrl+C, Enter", id);*/
sendToClipbord(id);
}
function sendToClipbord(myString) {
var textarea = document.createElement('textarea');
document.body.appendChild(textarea);
textarea.value = myString;
textarea.style.position = 'fixed';
textarea.focus();
textarea.select();
document.execCommand('Copy');
textarea.remove();
}
function getQueryStringParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
})();
@BenjaminHerbert
Copy link

BenjaminHerbert commented Aug 24, 2021

I think there is a small typo athttps://gist.github.com/kkoziarski/f861ba884f6e6faa0a0831c0d2f22b7c#file-jira-copy-id-bookmarklet-js-L9

var qsParam = etQueryStringParameterByName('selectedIssue');

should be

var qsParam = getQueryStringParameterByName('selectedIssue');

@kkoziarski
Copy link
Author

kkoziarski commented Aug 25, 2021

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