NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name Jira - easy copy id+name of tasks // @namespace http://tampermonkey.net/ // @version 0.2 // @description add button that will copy to clipboard branch name // @author Gandor // @license MIT // @match http*://jira.kistler.com/* // @grant none // ==/UserScript== (function() { if (!location.protocol.includes('s')) { window.location = location.href.replace('http:','https:') } const branchify = (rawBranchName) => rawBranchName.toLowerCase() .replace(/^(sdaq-[0-9]+)[\s-:]+ui/i,'$1') // remove UI: from name of branch .replace(/^\s+|\s+$/g, "") // trim leading and trailing spaces .replace(/[_|\s]+/g, "-") // change all spaces and underscores to a hyphen .replace(/[^a-z0-9-]+/g, "") // remove all non-alphanumeric characters except the hyphen .replace(/[-]+/g,"-") // replace multiple instances of the hyphen with a single instancesdsds .replace(/^-+|-+$/g, "") // trim leading and trailing hyphens) const insertCopyButton = (wrapper, idHolderSelector, titleHolderSelector) => { if (wrapper && !wrapper.querySelector('.branch-name-button')) { const content = document.createElement('span') content.className = 'branch-name-button' content.setAttribute('style','font-weight: bold; text-decoration: underline; color: #08f; cursor: pointer;'); content.innerText = 'COPY' content.onclick = () => { const tmp = document.createElement('input') const branchID = document.querySelector(idHolderSelector).innerText const branchTitle = document.querySelector(titleHolderSelector).innerText tmp.setAttribute('style','position:absolute;z-index:-10000'); tmp.value = branchify(branchID+' '+branchTitle) document.body.appendChild(tmp) tmp.select() tmp.setSelectionRange(0, 99999) document.execCommand("copy") document.body.removeChild(tmp) content.innerText = 'Copied..' content.style.color='#888' setTimeout(()=>{ content.style.color='#08f'; content.innerText = 'COPY' }, 400) } wrapper.appendChild(content) return content } return null } const insertToPage = ()=>{ // Open detail page let titleHolder = document.querySelector('.aui-page-panel #summary-val') if (titleHolder) { const wrapper = document.querySelector('.aui-page-panel .aui-page-header-main') insertCopyButton(wrapper,'.aui-nav-breadcrumbs li:last-child','.aui-page-panel #summary-val') } // sprint look titleHolder = document.querySelector('#ghx-detail-head .ghx-detail-summary') if (titleHolder) { const wrapper = document.querySelector('#ghx-detail-head .ghx-detail-summary .ghx-detail-list') const copyButton = insertCopyButton(wrapper,'#ghx-detail-head .ghx-key #issuekey-val','#ghx-detail-head .ghx-detail-summary #summary-val') if (copyButton) { copyButton.style.position='relative'; copyButton.style.right='50px'; copyButton.style.top='30px'; copyButton.style.zIndex='999999'; } } requestAnimationFrame(insertToPage) } requestAnimationFrame(insertToPage) })();