NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name Jira Cloud: Copy suggested Git branch name to Clipboard // @version 1.2.3 // @copyright 2023 - Milan Farkas, Dominik Varadi, Zoltan Szepe / WRD Labs Zrt. (https://wrd.hu) // @namespace www.wrd.hu // @description Adds a button to Jira Cloud that copies the suggested Git branch name to the clipboard. Jira server is not supported. // @author milanfarkas // @license MIT // @include /https?:\/\/.*atlassian.net\/browse\/.* // @include /https?:\/\/.*atlassian.net\/jira.* // @include /https?:\/\/.*atlassian.net\/.*issues.* // @require https://code.jquery.com/jquery-3.6.0.min.js // @require https://rawgit.com/notifyjs/notifyjs/master/dist/notify.js // @updateURL https://openuserjs.org/meta/milanfarkas/Jira_Cloud_Copy_suggested_Git_branch_name_to_Clipboard.meta.js // @downloadURL https://openuserjs.org/install/milanfarkas/Jira_Cloud_Copy_suggested_Git_branch_name_to_Clipboard.user.js // ==/UserScript== $(function() { setInterval(initPlugin, 2000); }); const initPlugin = () => { if ($('section[role=dialog]').length) { if ($('section[role=dialog] #gitClipboardBtn2').length < 1) { $('div#jira-issue-header button[data-testid=\'issue-field-voters.ui.button.styled-button\']').parent().parent().parent().parent().prepend("<button id='gitClipboardBtn2' style='margin-left:0px;margin-top: 3px;margin-right:16px;' class='copy-gitbranch-button aui-button ghx-actions aui-button-compact aui-button-subtle'><span class='icon icon-default aui-icon aui-icon-small aui-iconfont-devtools-branch-small'></span> Branch</button>"); } } else { if ($('#gitClipboardBtn1').length < 1) { $('header[role=\'banner\'] > div').last().prepend("<button id='gitClipboardBtn1' style='margin-left:0px;margin-right:16px;' class='copy-gitbranch-button aui-button ghx-actions aui-button-compact aui-button-subtle'><span class='icon icon-default aui-icon aui-icon-small aui-iconfont-devtools-branch-small'></span> Branch</button>"); } } $(".copy-gitbranch-button").off("click"); $(".copy-gitbranch-button").click(copyTaskKeyAndTitle); }; let copyTaskKeyAndTitle = () => { const issueKey = $('a[data-testid="issue.views.issue-base.foundation.breadcrumbs.current-issue.item"] span').text(); if (issueKey === '') { $.notify("No issue was selected", 'error'); return; } const issueTitle = $('h1[data-testid="issue.views.issue-base.foundation.summary.heading"]').text(); const issueTitleNormalized = issueTitle .trim() .toLowerCase() .normalize("NFD") .replace(/[\u0300-\u036f]/g, "") .replace(/\W+/g, '-') .toLowerCase(); const plainText = (issueKey + '-' + issueTitleNormalized).substring(0, 50) copyToClipboard(plainText); $.notify(plainText, 'success'); }; let copyToClipboard = (plainText) => { function listener(e) { e.clipboardData.setData("text/plain", plainText); e.preventDefault(); } document.addEventListener("copy", listener); document.execCommand("copy"); document.removeEventListener("copy", listener); }; (function() { 'use strict'; })();