Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Angry Harvest Copy
// ==UserScript==
// @name Jira Copy Tickets
// @namespace se.angrycreative
// @version 0.1.3
// @description Why Should We Use Uglys Addons.
// @author Luigi Guevara @killua99
// @updateURL https://gist.github.com/killua99/da7f30d077a5ba638bbe9c1a97164021/raw/3847e2afa262b055857b410b170946262af58e00/jira-angry-magic.meta.js
// @downloadURL https://gist.github.com/killua99/602c24d822bae78d57877c4e95536a39/raw/0cce4e1bf0278718ff4758796d6f8f0ef8f0b58b/jira-angry-magic.user.js
// @match http*://jira.angrycreative.se/*
// ==/UserScript==
(function () {
const $gh = document.querySelector( '#ghx-view-selector' )
Element.prototype.remove = function() {
this.parentElement.removeChild( this )
}
NodeList.prototype.remove = HTMLCollection.prototype.remove = function() {
for ( var i = this.length - 1; i >= 0; i-- ) {
if ( this[i] && this[i].parentElement ) {
this[i].parentElement.removeChild( this[i] )
}
}
}
const observeDOMCallback = function( mutationsList ) {
let triggered = false
mutationsList.forEach( function( mutation ) {
if ( ! triggered && 'childList' === mutation.type ) {
angryMagic.init()
triggered = true
}
})
}
const MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver
let angryMagic = {
init () {
let articleFooter = document.querySelectorAll( '#ghx-pool .js-issue' )
let jiraIssuePageHeader = document.querySelector( '#jira .aui-page-panel-inner .issue-header-content')
if ( articleFooter.length > 0 ) {
angryMagic.cardButtons( articleFooter )
}
if ( jiraIssuePageHeader !== null ) {
angryMagic.jiraPageButton( jiraIssuePageHeader )
}
},
jiraPageButton ( jiraIssuePageHeader ) {
let button = document.createElement( 'a' )
let toolBarPlace = jiraIssuePageHeader.querySelector( '#opsbar-opsbar-transitions' )
button.className += 'aui-button toolbar-trigger issueaction-workflow-transition angry-copy'
button.title = 'Harvest Copy Issue Task'
let copyText = document.createTextNode( 'Harvest Copy' )
button.appendChild( copyText )
toolBarPlace.appendChild( button )
angryMagic.reactIssuePageButton( button )
},
cardButtons ( cards ) {
Array.from( cards ).forEach( card => {
let button = document.createElement( 'button' )
button.className += 'aui-button angry-copy'
let copyText = document.createTextNode( 'Copy' )
button.appendChild( copyText )
card.appendChild( button )
angryMagic.reactButton( button )
} )
},
reactIssuePageButton ( button ) {
let jiraIssueContrent = button.closest( '.issue-header-content' )
button.addEventListener( 'click', function ( e ) {
e.preventDefault()
e.stopPropagation()
let el = document.createElement('textarea');
let key = jiraIssueContrent.querySelector( '.aui-nav-breadcrumbs li:last-child a.issue-link' )
let summary = jiraIssueContrent.querySelector( '#summary-val' )
let textToCopy = '[' + key.textContent + ']\n'
textToCopy += summary.textContent
el.value = textToCopy
el.setAttribute('readonly', '')
el.style.position = 'absolute'
el.style.left = '-9999px'
document.body.appendChild(el)
el.select()
document.execCommand( 'copy' )
document.body.removeChild( el )
}, true )
},
reactButton ( button ) {
let jiraIssue = button.closest( '.js-issue' )
button.addEventListener( 'click', function ( e ) {
e.preventDefault()
e.stopPropagation()
let el = document.createElement('textarea');
let key = jiraIssue.querySelector( '.ghx-key a' )
let summary = jiraIssue.querySelector( '.ghx-summary .ghx-inner' )
let textToCopy = '[' + key.innerHTML + ']\n'
textToCopy += summary.innerText
el.value = textToCopy
el.setAttribute('readonly', '')
el.style.position = 'absolute'
el.style.left = '-9999px'
document.body.appendChild(el)
el.select()
document.execCommand( 'copy' )
document.body.removeChild( el )
}, true )
}
}
if ( 'loading' === document.readyState ) {
document.addEventListener( 'DOMContentLoaded', function( e ) {
angryMagic.init()
})
} else {
angryMagic.init()
}
if ( null !== $gh && $gh.nodeType ) {
setTimeout( function() {
new MutationObserver( observeDOMCallback ).observe( $gh, { attributes: true, childList: true, subtree: true } )
}, 3000 );
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.