-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.user.js
65 lines (55 loc) · 1.73 KB
/
main.user.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// ==UserScript==
// @name JIRA Copy Title Links
// @namespace Violentmonkey Scripts
// @match https://carscommerce.atlassian.net/browse/*
// @match https://carscommerce.atlassian.net/jira/software/c/projects/*
// @grant none
// @version 1.0
// @author -
// @description 7/19/2024, 2:08:47 PM
// ==/UserScript==
const BUTTON_ID = "jira-copy-button";
async function setClipboard(text) {
const type = "text/html";
const blob = new Blob([text], { type });
const data = [new ClipboardItem({ [type]: blob })];
await navigator.clipboard.write(data);
animateButton();
}
function animateButton() {
const animation = [{ transform: "scale(0.5)" }];
const timing = {
duration: 100,
iterations: 1,
};
document.getElementById(BUTTON_ID).animate(animation, timing);
}
function makeLink(text, url) {
return `<a href="${url}">${text}</a>`;
}
function findTitle() {
return document.querySelector(
'h1[data-testid="issue.views.issue-base.foundation.summary.heading"]'
).textContent;
}
function findUrl() {
return document.querySelector(
'a[data-testid="issue.views.issue-base.foundation.breadcrumbs.current-issue.item"]'
).href;
}
function findIssueKey() {
return document.querySelector(
'a[data-testid="issue.views.issue-base.foundation.breadcrumbs.current-issue.item"] span'
).innerText;
}
function createButton(listener) {
const button = document.createElement("button");
button.id = BUTTON_ID;
button.style = "position: absolute; top: 0px; left: 0px; z-index: 1000;";
button.textContent = "copy";
document.body.prepend(button);
button.addEventListener("click", listener, false);
}
createButton(() => {
setClipboard(makeLink(findIssueKey() + " " + findTitle(), findUrl()));
});