-
Notifications
You must be signed in to change notification settings - Fork 1
/
jira_link.js
40 lines (35 loc) · 1.74 KB
/
jira_link.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
javascript: /* From either a Jira ticket or Kanban board, adds a formatted link to the selected Jira ticket to your clipboard, in Markdown and HTML format */
(function() {
function copyToClip(doc, html, text = null) {
function listener(e) {
e.clipboardData.setData("text/html", html);
e.clipboardData.setData("text/plain", text || html);
e.preventDefault();
}
doc.addEventListener("copy", listener);
doc.execCommand("copy");
doc.removeEventListener("copy", listener);
}
function __$(selector, attribute = 'innerText') {
var element = document.querySelector(selector);
if (!element) return ' ';
return attribute === 'innerText' ? element.innerText.trim() : element.getAttribute(attribute).trim();
}
var url = window.location.href.split(/[?#]/)[0];
var key = AJS.$('#key-val').text() || __$('#ghx-detail-issue', 'data-issuekey');
if (!key || key === ' ') {
alert("Please select a ticket.");
return;
}
var summary = AJS.$('#summary-val').text() || __$('#summary-val');
var status = AJS.$('#opsbar-transitions_more span').text() || __$('#status-val');
var priority = (AJS.$('#priority-val').text() || __$('#priority-val')).trim();
var type = (AJS.$('#type-val').text() || __$('#type-val')).trim();
var assignee = (AJS.$('#assignee-val').text() || __$('#assignee-val')).trim();
var markdownLink = `[${key}](${url})`;
var description = `${summary} (${status}/${priority}/${type}/${assignee})`;
var markdown = `_${markdownLink} - ${description}_`;
var htmlLink = `<a href="${url}">${key}</a>`;
var html = `<em>${htmlLink} - ${description}</em>`;
copyToClip(document, html, markdown);
})();