Forked from codycraven/jira-copy-story-summary.js
Last active
November 13, 2020 22:05
-
-
Save johnallers/375c59b6bb78fa38149c7af95bb1f68f to your computer and use it in GitHub Desktop.
TamperMonkey Jira Copy Story Summary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Jira copy story summary | |
// @namespace https://cravencode.com/ | |
// @version 0.1 | |
// @description Copies summary, issue link, and people associated with story to clipboard | |
// @match https://*.atlassian.net/* | |
// @copyright 2019, Cody Craven | |
// ==/UserScript== | |
(function(d) { | |
'use strict'; | |
function applyCSS() { | |
const h = d.getElementsByTagName("head")[0]; | |
const s = document.createElement("style"); | |
s.type = "text/css"; | |
s.textContent = ` | |
.summary-copy__textarea { | |
height: 0; | |
overflow: hidden; | |
} | |
.summary-copy__confirm { | |
display: none; | |
padding-left: .5rem; | |
} | |
.active .summary-copy__confirm { | |
display: initial; | |
} | |
.summary-copy .active svg { | |
fill: white; | |
} | |
`; | |
h.appendChild(s); | |
} | |
function copyIcon() { | |
const ns = "http://www.w3.org/2000/svg"; | |
const s = d.createElementNS(ns, "svg"); | |
const p = d.createElementNS(ns, "path"); | |
s.setAttributeNS(null, "viewBox", "0 0 512 512"); | |
p.setAttribute( | |
"d", | |
"M296 48H176.5C154.4 48 136 65.4 136 87.5V96h-7.5C106.4 96 88 113.4 88 135.5v288c0 22.1 18.4 40.5 40.5 40.5h208c22.1 0 39.5-18.4 39.5-40.5V416h8.5c22.1 0 39.5-18.4 39.5-40.5V176L296 48zm0 44.6l83.4 83.4H296V92.6zm48 330.9c0 4.7-3.4 8.5-7.5 8.5h-208c-4.4 0-8.5-4.1-8.5-8.5v-288c0-4.1 3.8-7.5 8.5-7.5h7.5v255.5c0 22.1 10.4 32.5 32.5 32.5H344v7.5zm48-48c0 4.7-3.4 8.5-7.5 8.5h-208c-4.4 0-8.5-4.1-8.5-8.5v-288c0-4.1 3.8-7.5 8.5-7.5H264v128h128v167.5z" | |
); | |
s.appendChild(p); | |
return s; | |
} | |
function copyWidget(fn) { | |
const l = d.createElement("span"); | |
const a = d.createElement("a"); | |
const s = d.createElement("span"); | |
const t = d.createElement("span"); | |
s.className = "aui-icon aui-icon-small"; | |
s.style.textIndent = "initial"; | |
t.className = "summary-copy__confirm"; | |
t.textContent = "Copied"; | |
a.href = "#"; | |
a.title = "Copy issue summary"; | |
s.appendChild(copyIcon()); | |
a.appendChild(s); | |
a.appendChild(t); | |
l.appendChild(a); | |
a.addEventListener("click", function(e) { | |
e.preventDefault(); | |
const z = d.createElement("textarea"); | |
z.value = fn(); | |
z.className = "summary-copy__textarea"; | |
l.appendChild(z); | |
z.focus(); | |
z.select(); | |
d.execCommand("copy"); | |
a.classList.add("active"); | |
window.setTimeout(function() { | |
a.classList.remove("active"); | |
}, 2000); | |
l.removeChild(z); | |
}); | |
return l; | |
} | |
function getSummary() { | |
const issue = document.querySelector('div[data-test-id="issue.views.issue-base.foundation.breadcrumbs.breadcrumb-current-issue-container"] > div:nth-child(2) > a > span > span').textContent; | |
const title = document.querySelector('h1[data-test-id="issue.views.issue-base.foundation.summary.heading"]').textContent; | |
return `${issue}: ${title}`; | |
} | |
applyCSS(); | |
setTimeout(function() { | |
const heading = d.querySelector('div[data-test-id="issue.views.issue-base.foundation.breadcrumbs.breadcrumb-current-issue-container"] > div:nth-child(2)'); | |
heading.append( | |
copyWidget(getSummary) | |
); | |
}, 5000) | |
})(document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment