-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUserscript-Jira-CopyTitle.js
84 lines (67 loc) · 2.26 KB
/
Userscript-Jira-CopyTitle.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// ==UserScript==
// @name Jira-CopyTitle
// @namespace https://github.com/Tharkis/Userscript-Jira-CopyTitle/blob/master/Userscript-Jira-CopyTitle.js
// @version 0.1.0
// @description Adds a "Copy Task Title" button to the right of the "Workflow" dropdown in Jira.
// @author Joe Etten
// @license MIT
// @match https://*.atlassian.net/secure/*
// @match https://*.atlassian.net/browse/*
// @grant none
// @require https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/1.7.1/clipboard.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/notify/0.4.2/notify.min.js
// ==/UserScript==
(function($, JIRA) {
'use strict';
function addCopyButton() {
// console.info('addCopyButton');
if(!$('#clipboardBtn').next().length) {
$('#clipboardBtn').remove();
var container = $("#THIRD_PARTY_TAB .call-to-actions, .toolbar-split-left");
container.append("<a id='clipboardBtn' class='btn aui-button aui-button-primary aui-style'>Copy Task Title</a>");
}
}
function getIssueFullTitle () {
var issueKey = "";
var issueTitle = $('#summary-val').text();
if($('#issuekey-val').length){
issueKey = $('#issuekey-val').text();
}
if($('#key-val').length){
issueKey = $('#key-val').text();
}
return issueKey + ' - ' + issueTitle;
}
function handleCopyButton () {
var clipboard = new Clipboard('#clipboardBtn', {
text: function(trigger) {
return getIssueFullTitle();
}
});
clipboard.on('success', function(e) {
$.notify("Copied to clipboard", "success");
$.notify(getIssueFullTitle(), "success");
});
clipboard.on('error', function(e) {
$.notify("Access granted", "error");
});
}
function init() {
// console.info("init");
updateHandlers();
handleCopyButton();
addCopyButton();
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function() {
updateHandlers();
});
}
function updateHandlers() {
addCopyButton();
}
// init when page ready
document.onreadystatechange = function() {
if (document.readyState == "complete") {
init();
}
};
})(window.$, window.JIRA);