Skip to content

Instantly share code, notes, and snippets.

@kkoziarski
Last active October 2, 2021 20:35
Show Gist options
  • Save kkoziarski/f861ba884f6e6faa0a0831c0d2f22b7c to your computer and use it in GitHub Desktop.
Save kkoziarski/f861ba884f6e6faa0a0831c0d2f22b7c to your computer and use it in GitHub Desktop.
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

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

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