Skip to content

Instantly share code, notes, and snippets.

@andraaspar
Last active January 3, 2023 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andraaspar/cabfad388eddf9e37c14 to your computer and use it in GitHub Desktop.
Save andraaspar/cabfad388eddf9e37c14 to your computer and use it in GitHub Desktop.
Tampermonkey: Sets JIRA comment order to ascending & loads all comments.
// ==UserScript==
// @name JIRA
// @namespace andraaspar
// @version 0.10.2
// @description Reverses JIRA comment order & loads all comments, tweaks issue list.
// @author AP
// @match https://ovitas.atlassian.net/*
// @run-at document-idle
// ==/UserScript==
try {
let styleAdded = false;
let intervalId = setInterval(() => {
try {
if (!styleAdded) {
document.head.insertAdjacentHTML(
"beforeend",
`<style id="greasemonkey-jira-style">
.summary .issue-link:not(#__NEVER__)
{
font-weight: bold;
}
.summary .issue-link.parentIssue + .issue-link:not(#__NEVER__)
{
font-size: smaller;
font-weight: normal;
}
.issuekey .issue-link:not(#__NEVER__),
.created,
.updated,
.resolution,
.status,
.reporter,
.assignee,
.customfield_10020
{
font-size: smaller;
}
tt
{
border: 1px solid rgba(0, 0, 0, .2);
border-radius: 3px;
background: rgba(0, 0, 0, .1);
}
.image-wrap > img
{
max-width: 100%;
}
:not(#__NEVER__)
{
letter-spacing: 0;
}
</style>`
);
styleAdded = true;
}
let sortElem = document.querySelector(
"[data-testid='issue-activity-feed.ui.activity-sorting-toggle.sorting-button']"
);
if (/newest/i.test(sortElem?.textContent ?? "")) {
sortElem.children.item(0).click();
console.log("Fixing sort.");
} else {
let collapsedCommentsElems =
document.querySelectorAll(`[data-testid="issue.activity.common.component.load-more-button.loading-button"]`);
for (const collapsedCommentsElem of collapsedCommentsElems) {
if (/view.*older.*comments/i.test(collapsedCommentsElem.innerText)) {
collapsedCommentsElem.click();
console.log("Expanding comments.");
}
}
}
/** @type {HTMLElement[]} */
let parentIssueLinkElems = document.querySelectorAll(
"td.summary a.issue-link.parentIssue[title]"
);
for (let parentIssueLinkElem of parentIssueLinkElems) {
if (parentIssueLinkElem.matches("[data-monkey]")) continue;
let id = parentIssueLinkElem.innerText;
parentIssueLinkElem.innerText = handle(parentIssueLinkElem.title);
parentIssueLinkElem.title = id;
parentIssueLinkElem.dataset.monkey = true;
}
/** @type {HTMLElement[]} */
let issueLinkElems = document.querySelectorAll("td.summary a.issue-link");
for (let issueLinkElem of issueLinkElems) {
issueLinkElem.innerText = handle(issueLinkElem.innerText);
issueLinkElem.dataset.monkey = true;
}
} catch (e) {
console.error(e);
}
}, 1000);
function handle(s) {
s = s.replace(
/^\s*As\s*an?.*?,?\s*I\s*(?:would like|would|want|need|should|'d like)\s*/i,
""
);
s = s.replace(
/^\s*I\s*(?:would like|would|want|need|should|'d like)\s*/i,
""
);
s = s.replace(/mockups?/gi, "Visual");
return s.charAt(0).toUpperCase() + s.slice(1);
}
} catch (e) {
console.error(e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment