-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjira_list_links.js
50 lines (43 loc) · 1.93 KB
/
jira_list_links.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
41
42
43
44
45
46
47
48
49
50
javascript:(function(){
function getTextContent(selector, parent=document) {
const element = parent.querySelector(selector);
return element ? element.textContent.trim() : '';
}
function getAttribute(selector, attribute, parent=document) {
const element = parent.querySelector(selector);
return element ? element.getAttribute(attribute) : '';
}
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);
}
const rows = document.querySelectorAll('tr.issuerow');
const baseURL = window.location.origin;
let markdownList = '';
let htmlList = '';
rows.forEach(row => {
const key = getTextContent('.issuekey a', row);
const link = getAttribute('.issuekey a', 'href', row);
const summary = getTextContent('.summary a', row);
const status = getTextContent('.status span', row);
const priority = getAttribute('.priority img', 'alt', row);
const type = getAttribute('.issuetype img', 'alt', row);
const assignee = getTextContent('.assignee a', row) || 'Unassigned';
const url = `${baseURL}${link}`;
const markdownLink = `[${key}](${url})`;
const description = `${summary} (${status}/${priority}/${type}/${assignee})`;
const markdown = `_${markdownLink} - ${description}_`;
const htmlLink = `<a href="${url}">${key}</a>`;
const html = `<em>${htmlLink} - ${description}</em>`;
markdownList += `* ${markdown}\n`;
htmlList += `<li>${html}</li>`;
});
const fullHtml = `<ul>${htmlList}</ul>`;
copyToClip(document, fullHtml, markdownList);
})();