Last active
March 4, 2019 11:17
-
-
Save geff21st/02d8bc40603878d0ae3712858f3b28e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name uplabJiraActions | |
// @description Кастомные действия для Jira | |
// @author Uplab | |
// @license MIT | |
// @version 20180710.03.18.23 | |
// @grant GM_addStyle | |
// @include https://j.uplab.ru/* | |
// ==/UserScript== | |
var css = `.up-actions-row { | |
/*font-size: 0;*/ | |
padding: 0; | |
margin-top: 10px; | |
margin-bottom: 20px; | |
display: flex; | |
} | |
.up-actions-item { | |
/*display: inline-block;*/ | |
padding: 0; | |
font-size: .8rem; | |
line-height: 1.4rem; | |
border: 1px solid #ccc; | |
background-color: #f5f5f5; | |
list-style: none; | |
} | |
.up-actions-item + | |
.up-actions-item { | |
border-left-width: 0; | |
} | |
.up-actions-item:hover { | |
background-color: #eee; | |
border-color: #999; | |
/*box-shadow: inset 0 0 0 1px #999;*/ | |
} | |
.up-actions-item:not(:first-child):hover { | |
box-shadow: -1px 0 #999; | |
} | |
.up-actions-item:hover a { | |
color: #000000; | |
} | |
.up-actions-item a { | |
color: #333; | |
padding: 0 8px; | |
text-decoration: none; | |
display: block; | |
} | |
.up-actions-item:first-child, | |
.up-actions-item:last-child { | |
border-radius: 3px; | |
} | |
.up-actions-item:first-child { | |
border-top-right-radius: 0; | |
border-bottom-right-radius: 0; | |
} | |
.up-actions-item:last-child { | |
border-top-left-radius: 0; | |
border-bottom-left-radius: 0; | |
} | |
.up-actions-link-eidt { | |
position: absolute; | |
right: 30px; | |
top: 3px; | |
color: #9aa1b2; | |
display: block; | |
width: 24px; | |
height: 24px; | |
line-height: 24px; | |
text-align: center; | |
border-radius: 3px; | |
} | |
.up-actions-link-eidt:hover { | |
background-color: #f5f5f5; | |
} | |
.up-actions-trigger--red, | |
.up-actions-trigger--yellow, | |
.up-actions-trigger--green { | |
/*font-size: 0;*/ | |
/*width: 40px;*/ | |
/*background-color: #f00;*/ | |
} | |
.up-actions-trigger--red { | |
}`; | |
var actions = `<ul class="up-actions-row"> | |
<li class="up-actions-item"> | |
<a class="up-actions-trigger up-actions-trigger--yellow js-up-action" | |
href="/secure/WorkflowUIDispatcher.jspa?id=__TASK_ID__&action=41&atl_token=__JIRA_TOKEN__"> | |
<span class="trigger-label">HTML</span> | |
</a> | |
</li> | |
<li class="up-actions-item"> | |
<a class="up-actions-trigger up-actions-trigger--yellow js-up-action" | |
href="/secure/WorkflowUIDispatcher.jspa?id=__TASK_ID__&action=51&atl_token=__JIRA_TOKEN__"> | |
<span class="trigger-label">PROG</span> | |
</a> | |
</li> | |
<li class="up-actions-item"> | |
<a class="up-actions-trigger up-actions-trigger--green js-up-action" | |
href="/secure/WorkflowUIDispatcher.jspa?id=__TASK_ID__&action=61&atl_token=__JIRA_TOKEN__"> | |
<span class="trigger-label">TEST</span> | |
</a> | |
</li> | |
<li class="up-actions-item"> | |
<a class="up-actions-trigger up-actions-trigger--green js-up-action" | |
href="/secure/WorkflowUIDispatcher.jspa?id=__TASK_ID__&action=31&atl_token=__JIRA_TOKEN__"> | |
<span class="trigger-label">DONE</span> | |
</a> | |
</li> | |
<li class="up-actions-item"> | |
<a class="up-actions-trigger aui-list-item-link issueaction-clone-issue" | |
href="/secure/CloneIssueDetails!default.jspa?id=__TASK_ID__&returnUrl=__LOCATION_HREF__">Клон</a> | |
</li> | |
<li class="up-actions-item"> | |
<a class="up-actions-trigger aui-list-item-link js-issueaction issueaction-edit-issue" | |
href="/secure/EditIssue!default.jspa?id=__TASK_ID__&returnUrl=__LOCATION_HREF__"> | |
<span class="icon aui-icon aui-icon-small aui-iconfont-edit"></span> | |
</a> | |
</li> | |
</ul>`; | |
var linkTaskActions = `<a class="js-issueaction issueaction-edit-issue up-actions-link-eidt" | |
href="/secure/EditIssue!default.jspa?id=__TASK_ID__&returnUrl=__LOCATION_HREF__"> | |
<span class="icon aui-icon aui-icon-small aui-iconfont-edit"></span> | |
</a>`; | |
(function (window, undefined) { | |
var w; | |
if (typeof unsafeWindow != undefined) w = unsafeWindow; else w = window; | |
if (w.self != w.top) return; | |
if (!/https:\/\/j.uplab.ru/.test(w.location.href)) return; | |
GM_addStyle(css); | |
require([ | |
"jquery", | |
"underscore", | |
"wrm/require", | |
"quick-edit/util/loading-indicator", | |
"jira/ajs/keyboardshortcut/keyboard-shortcut-toggle" | |
], function (jQuery, underScore, e, f, b) { | |
var jiraToken, commonParams, activeClass = 'js-uplab-updated'; | |
jiraToken = jQuery('#atlassian-token').attr('content'); | |
commonParams = { | |
'__JIRA_TOKEN__': jiraToken, | |
'__LOCATION_HREF__': location.href | |
}; | |
var disable = function () { | |
b.disable(); | |
f.showLoadingIndicator() | |
}; | |
var enable = function (status) { | |
f.hideLoadingIndicator(!!status); | |
b.enable(); | |
}; | |
// window.jQuery = window.jQuery || jQuery; | |
// window.underScore = window.underScore || underScore; | |
function replaceHtml(string, replace) { | |
var tmpActions = string; | |
replace = jQuery.extend( | |
commonParams, | |
replace | |
); | |
jQuery.each(replace, function (key, value) { | |
tmpActions = tmpActions.replace(new RegExp(key, 'g'), value); | |
}); | |
return tmpActions; | |
} | |
function updateJira() { | |
updateTask(); | |
updateLinks(); | |
} | |
function updateLinks() { | |
jQuery('.links-container dd').each(function (i, item) { | |
var $item = $(item); | |
if ($item.hasClass(activeClass)) { | |
return; | |
} else { | |
$item.addClass(activeClass); | |
} | |
var id = $item.attr('id').split(/[-_]/)[1]; | |
$item.append(replaceHtml( | |
linkTaskActions, {'__TASK_ID__': id} | |
)); | |
}); | |
} | |
function updateTask() { | |
var $issue = $('#ghx-detail-issue'); | |
var taskId = $issue.attr('data-issueid'); | |
if (!$issue.length || $issue.hasClass(activeClass)) return; | |
var actionsHtml = replaceHtml(actions, {'__TASK_ID__': taskId}); | |
$issue.find('.ghx-statistic-group').after(actionsHtml) | |
$issue.addClass(activeClass); | |
} | |
document.addEventListener('DOMNodeInserted', underScore.throttle(function () { | |
updateJira(); | |
}, 1000)); | |
jQuery(document).on('click', '.js-up-action', function (event) { | |
event.preventDefault(); | |
disable(); | |
jQuery.post(this.href, function () { | |
// enable(); | |
location.reload(); | |
}); | |
}) | |
}); | |
})(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment