jira-issue-navigate

Go to the next issue using a button

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

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