jira-issue-navigate

Go to the next issue using a button

当前为 2022-04-13 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name jira-issue-navigate
  3. // @version 0.4.0
  4. // @description Go to the next issue using a button
  5. // @author Amin Yahyaabadi
  6. // @match https://*.atlassian.net/browse/*
  7. // @match https://*.atlassian.net/jira/software/projects/*
  8. // @grant none
  9. // @license MIT
  10. // @namespace AminYa
  11. // ==/UserScript==
  12. function $1994abed16d377af$var$main() {
  13. const currentURL = window.location.href;
  14. // parse the URL
  15. const urlMatch = /(.*)\.atlassian\.net\/(browse|jira\/software\/projects)\/(.*)-(\d*)(\?.*)?/;
  16. const res = urlMatch.exec(currentURL);
  17. // if the url doesn't match return
  18. if (res === null) return;
  19. const [, company, middle, project, issue, queries] = res;
  20. const issueNumber = parseInt(issue, 10);
  21. // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
  22. const queriesString = queries === undefined ? "" : queries;
  23. // create a button to go to the next issue
  24. const nextButton = document.createElement("a");
  25. nextButton.id = "next-issue-btn";
  26. nextButton.setAttribute("aria-label", "Go to next issue");
  27. nextButton.setAttribute("aria-expanded", "false");
  28. nextButton.setAttribute("aria-haspopup", "true");
  29. nextButton.setAttribute("type", "button");
  30. nextButton.style.borderRadius = "2px";
  31. nextButton.style.alignSelf = "center";
  32. nextButton.style.padding = "7px";
  33. const buttonIcon = document.createElement("div");
  34. buttonIcon.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 20.633 20.633" style="enable-background:new 0 0 20.633 20.633" xml:space="preserve">
  35. <path d="M15.621 9.844 5.971.195A.652.652 0 0 0 5.5 0a.664.664 0 0 0-.473.195l-.013.012a.677.677 0 0 0-.197.475v4.682c0 .178.071.348.197.471l4.481 4.482-4.481 4.479a.667.667 0 0 0-.197.475v4.68c0 .18.071.354.197.475l.013.01a.664.664 0 0 0 .947 0l9.647-9.646a.671.671 0 0 0 0-.946z" />
  36. </svg>`;
  37. nextButton.style.background = "none";
  38. nextButton.style.border = "none";
  39. // attach the icon
  40. nextButton.appendChild(buttonIcon);
  41. // create a tooltip for the button that shows "Go to next issue" on hover
  42. const buttonTooltip = document.createElement("div");
  43. buttonTooltip.id = "next-issue-btn-tooltip";
  44. buttonTooltip.setAttribute("style", `position: relative;`);
  45. nextButton.prepend(buttonTooltip);
  46. const buttonTooltipText = document.createElement("div");
  47. buttonTooltipText.innerHTML = "Next";
  48. buttonTooltipText.setAttribute("style", `width: 50px;
  49. text-align: center;
  50. border-radius: 4px;
  51. padding: 1px 0;
  52. font-size: small;
  53. background: #172B4D;
  54. color: white;
  55. position: absolute;
  56. z-index: 1;
  57. bottom: 100%;
  58. left: 50%;
  59. margin-left: -30px;
  60. margin-bottom: 15px;
  61. `);
  62. buttonTooltipText.style.visibility = "hidden";
  63. buttonTooltip.prepend(buttonTooltipText);
  64. // set the the button class
  65. const likeButtonSelector = "#jira-issue-header-actions > div > div > div:nth-child(4)";
  66. const likeButton = document.querySelector(likeButtonSelector);
  67. if (likeButton !== null) {
  68. console.debug(`${likeButtonSelector} was not found`);
  69. nextButton.className = likeButton.className;
  70. }
  71. // create the next issue url
  72. const nextIssueURL = `${company}.atlassian.net/${middle}/${project}-${issueNumber + 1}${queriesString}`;
  73. // navigate to the next issue on click
  74. nextButton.setAttribute("href", nextIssueURL);
  75. nextButton.addEventListener("mouseover", ()=>{
  76. nextButton.style.background = "#091e4214";
  77. buttonTooltipText.style.visibility = "visible";
  78. });
  79. nextButton.addEventListener("mouseleave", ()=>{
  80. nextButton.style.background = "none";
  81. buttonTooltipText.style.visibility = "hidden";
  82. });
  83. // attach the button to the toolbar
  84. const toolbarSelector = "#jira-issue-header-actions > div > div";
  85. const toolbar = document.querySelector(toolbarSelector);
  86. if (toolbar === null) {
  87. console.debug(`${toolbarSelector} was not found`);
  88. return;
  89. }
  90. toolbar.prepend(nextButton);
  91. }
  92. setTimeout($1994abed16d377af$var$main, 2000);
  93.  
  94.  
  95. //# sourceMappingURL=main.js.map