一键复制Jira信息
背景
为什么我需要一个这样的工具
我在记录工作流水账的时候需要记录每个处理过的问题在md下我需要
这样三部分组成的问题地址,每次都要手动输入,太麻烦了,所以有了这个油猴插件
效果图
拼接1处和2处获得需要的格式 代码为了http做了粘贴到剪切板的兼容
代码
(function ($ ) { 'use strict' ; let btn = '<li><button id="CopyIt" class="aui-button" aria-disabled="false" original-title="" resolved="">复制Jira信息</button></li>' ; $(".filter-operations" ).prepend (btn); $("#CopyIt" ).click (function ( ) { let title = $("#summary-val" ).text () let link = $(".issue-link" )[0 ].href let jiraNo = $(".issue-link" ).attr ('data-issue-key' ) let text = `[${title} ${jiraNo} ](${link} )` copyToClipboard (text) }); function copyToClipboard (textToCopy ) { if (navigator.clipboard && window .isSecureContext ) { return navigator.clipboard .writeText (textToCopy); } else { let input = document .createElement ('input' ) input.style .position = 'fixed' input.style .top = '-10000px' input.style .zIndex = '-999' document .body .appendChild (input) input.value = textToCopy input.focus () input.select () try { let result = document .execCommand ('copy' ) document .body .removeChild (input) if (!result || result === 'unsuccessful' ) { console .log ('复制失败' ) } else { console .log ('复制成功' ) } } catch (e) { document .body .removeChild (input) alert ('当前浏览器不支持复制功能,请检查更新或更换其他浏览器操作' ) } } } })(jQuery);