jira-issue-navigate

Go to the next issue using a button

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

  1. // ==UserScript==
  2. // @name jira-issue-navigate
  3. // @version 0.3.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("button");
  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. const buttonIcon = document.createElement("div");
  32. 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">
  33. <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" />
  34. </svg>`;
  35. nextButton.style.background = "none";
  36. nextButton.style.border = "none";
  37. // attach the icon
  38. nextButton.appendChild(buttonIcon);
  39. // create a tooltip for the button that shows "Go to next issue" on hover
  40. const buttonTooltip = document.createElement("div");
  41. buttonTooltip.id = "next-issue-btn-tooltip";
  42. buttonTooltip.setAttribute("style", `position: relative;`);
  43. nextButton.prepend(buttonTooltip);
  44. const buttonTooltipText = document.createElement("div");
  45. buttonTooltipText.innerHTML = "Next";
  46. buttonTooltipText.setAttribute("style", `width: 50px;
  47. text-align: center;
  48. border-radius: 4px;
  49. padding: 1px 0;
  50. font-size: small;
  51. background: #172B4D;
  52. color: white;
  53. position: absolute;
  54. z-index: 1;
  55. bottom: 100%;
  56. left: 50%;
  57. margin-left: -30px;
  58. margin-bottom: 15px;
  59. `);
  60. buttonTooltipText.style.visibility = "hidden";
  61. buttonTooltip.prepend(buttonTooltipText);
  62. // set the the button class
  63. const likeButtonSelector = "#jira-issue-header-actions > div > div > div:nth-child(4)";
  64. const likeButton = document.querySelector(likeButtonSelector);
  65. if (likeButton !== null) {
  66. console.debug(`${likeButtonSelector} was not found`);
  67. nextButton.className = likeButton.className;
  68. }
  69. // button functionality
  70. nextButton.addEventListener("click", ()=>{
  71. // get the next issue number
  72. const nextIssueNumber = issueNumber + 1;
  73. // create the next issue url
  74. const nextIssueURL = `${company}.atlassian.net/${middle}/${project}-${nextIssueNumber}${queriesString}`;
  75. // navigate to the next issue
  76. window.location.href = nextIssueURL;
  77. });
  78. nextButton.addEventListener("mouseover", ()=>{
  79. nextButton.style.background = "#091e4214";
  80. buttonTooltipText.style.visibility = "visible";
  81. });
  82. nextButton.addEventListener("mouseleave", ()=>{
  83. nextButton.style.background = "none";
  84. buttonTooltipText.style.visibility = "hidden";
  85. });
  86. // attach the button to the toolbar
  87. const toolbarSelector = "#jira-issue-header-actions > div > div";
  88. const toolbar = document.querySelector(toolbarSelector);
  89. if (toolbar === null) {
  90. console.debug(`${toolbarSelector} was not found`);
  91. return;
  92. }
  93. toolbar.prepend(nextButton);
  94. }
  95. setTimeout($1994abed16d377af$var$main, 2000);
  96.  
  97.  
  98. //# sourceMappingURL=main.js.map