// ==UserScript== // @name jira-issue-navigate // @version 0.5.0 // @description Go to the next/prev issue using buttons // @author Amin Yahyaabadi // @match https://*.atlassian.net/browse/* // @match https://*.atlassian.net/jira/software/projects/* // @grant none // @license MIT // @namespace AminYa // @homepage https://github.com/aminya/jira-issue-navigate // @downloadURL none // ==/UserScript== function $1994abed16d377af$var$praseUrl() { const currentURL = window.location.href; // parse the URL const urlMatch = /(.*)\.atlassian\.net\/(browse|jira\/software\/projects)\/(.*)-(\d*)(\?.*)?/; const res = urlMatch.exec(currentURL); // if the url doesn't match return if (res === null) return null; const [, company, middle, project, issue, queries] = res; const issueNumber = parseInt(issue, 10); // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition const queriesString = queries === undefined ? "" : queries; return { company: company, middle: middle, project: project, issueNumber: issueNumber, queriesString: queriesString }; } function $1994abed16d377af$var$createButton(company, middle, project, issueNumber, queriesString, direction) { // create a button to go to the next issue const button = document.createElement("a"); button.id = `${direction}-issue-btn`; button.setAttribute("aria-label", `Go to ${direction} issue`); button.setAttribute("aria-expanded", "false"); button.setAttribute("aria-haspopup", "true"); button.setAttribute("type", "button"); button.style.borderRadius = "2px"; button.style.alignSelf = "center"; button.style.padding = "7px"; const buttonIcon = document.createElement("div"); buttonIcon.innerHTML = ` `; button.style.background = "none"; button.style.border = "none"; // rotate the icon if it's the prev button if (direction === "prev") button.style.transform = "rotate(180deg) translate(0px, 3px)"; // attach the icon button.appendChild(buttonIcon); // create a tooltip for the button that shows "Go to next issue" on hover $1994abed16d377af$var$addTooltip(button); // set the the button class const likeButtonSelector = "#jira-issue-header-actions > div > div > div:nth-child(4)"; const likeButton = document.querySelector(likeButtonSelector); if (likeButton !== null) { console.debug(`${likeButtonSelector} was not found`); button.className = likeButton.className; } // issue number let targetIssueNumber; if (direction === "next") targetIssueNumber = issueNumber + 1; else targetIssueNumber = issueNumber - 1; // create the next issue url const issueURL = `${company}.atlassian.net/${middle}/${project}-${targetIssueNumber}${queriesString}`; // navigate to the next issue on click button.setAttribute("href", issueURL); return button; } function $1994abed16d377af$var$addTooltip(button, direction = "next") { // create a tooltip for the button that shows "Go to next issue" on hover const buttonTooltip = document.createElement("div"); buttonTooltip.id = `${direction}-issue-btn-tooltip`; buttonTooltip.setAttribute("style", `position: relative;`); button.prepend(buttonTooltip); const buttonTooltipText = document.createElement("div"); buttonTooltipText.innerHTML = direction[0].toUpperCase() + direction.slice(1); buttonTooltipText.setAttribute("style", `width: 50px; text-align: center; border-radius: 4px; padding: 1px 0; font-size: small; background: #172B4D; color: white; position: absolute; z-index: 1; bottom: 100%; left: 50%; margin-left: -30px; margin-bottom: 15px; `); buttonTooltipText.style.visibility = "hidden"; buttonTooltip.prepend(buttonTooltipText); button.addEventListener("mouseover", ()=>{ button.style.background = "#091e4214"; buttonTooltipText.style.visibility = "visible"; }); button.addEventListener("mouseleave", ()=>{ button.style.background = "none"; buttonTooltipText.style.visibility = "hidden"; }); } function $1994abed16d377af$var$main() { const parseResult = $1994abed16d377af$var$praseUrl(); if (parseResult === null) return; const { company: company , middle: middle , project: project , issueNumber: issueNumber , queriesString: queriesString } = parseResult; // create a button to go to the next issue const nextButton = $1994abed16d377af$var$createButton(company, middle, project, issueNumber, queriesString, "next"); const prevButton = $1994abed16d377af$var$createButton(company, middle, project, issueNumber, queriesString, "prev"); // get the toolbar const toolbarSelector = "#jira-issue-header-actions > div > div"; const toolbar = document.querySelector(toolbarSelector); if (toolbar === null) { console.debug(`${toolbarSelector} was not found`); return; } // attach the button to the toolbar toolbar.prepend(prevButton); toolbar.prepend(nextButton); } setTimeout($1994abed16d377af$var$main, 2000); //# sourceMappingURL=main.js.map