Skip to content

Instantly share code, notes, and snippets.

@codycraven
Created August 2, 2019 19:19
Show Gist options
  • Save codycraven/e8163a1aa559ec4aa7fe05ec1e401452 to your computer and use it in GitHub Desktop.
Save codycraven/e8163a1aa559ec4aa7fe05ec1e401452 to your computer and use it in GitHub Desktop.
TamperMonkey Jira Copy Story Summary
// ==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/browse/*
// @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 u = d.createElement("ul");
const l = d.createElement("li");
const a = d.createElement("a");
const s = d.createElement("span");
const t = d.createElement("span");
u.className = "toolbar-group pluggable-ops summary-copy";
l.className = "toolbar-item";
a.className = "toolbar-trigger";
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);
u.appendChild(l);
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 u;
}
function getSummary() {
const l = window.location;
const people = [];
const rs = []
const ps = []
d.querySelectorAll("#peoplemodule .mod-content dl").forEach(el => {
const r = el.querySelector("dt");
const p = el.querySelector(".user-hover");
if (r.hasAttribute("title") && p) {
people.push(`${r.textContent}${"\t".repeat(7 - Math.floor(r.textContent.length / 4))}${p.textContent}`);
}
});
return `${d.getElementById("summary-val").textContent}
${l.origin}/${l.pathname}
${people.join("\n")}`;
}
applyCSS();
const tabs = d.querySelector(".toolbar-split.toolbar-split-right");
tabs.insertBefore(
copyWidget(getSummary),
tabs.children[0]
);
})(document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment