Skip to content

Instantly share code, notes, and snippets.

@errogaht
Forked from comm1x/jira-copy-task.js
Last active January 14, 2019 16:04
Show Gist options
  • Save errogaht/c8409ac0266d1c68b56fb32da61304d6 to your computer and use it in GitHub Desktop.
Save errogaht/c8409ac0266d1c68b56fb32da61304d6 to your computer and use it in GitHub Desktop.
Add button "Copy task name" to JIRA (version for suxx new JIRA interface)
// ==UserScript==
// @name Copy jira task name
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://kafoodle.atlassian.net/browse/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
window.addEventListener("load", function(){
setTimeout(function(){
var i = document.querySelectorAll('[name="ajs-issuekey"]').item(0).getAttribute('content');
const copyToClipboard = str => {
const el = document.createElement('textarea');
el.value = str;
el.setAttribute('readonly', '');
el.style.position = 'absolute';
el.style.left = '-9999px';
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
};
const copyTaskName = () => {
var d = document.querySelectorAll('#jira-frontend h1').item(0).innerText;
var desc = i + " " + d;
copyToClipboard(desc);
};
var btn = document.createElement("button");
btn.onclick = copyTaskName;
btn.innerText = "Copy task name";
btn.style = "margin-left: 10px;";
document.evaluate('//span[text()="' + i + '"]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE).snapshotItem(0).parentElement.parentElement.parentElement.append(btn);
}, 1000);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment