floodmeadows / Jira get issue types

// ==UserScript==
// @name         Jira get issue types
// @description  Adds a button to get the list of issue types, and the fields for a chosen type
// @namespace    https://openuserjs.org/users/floodmeadows
// @copyright    2021, floodmeadows (https://openuserjs.org/users/floodmeadows)
// @license      MIT
// @version      0.1
// @include      https://jira.*.uk/browse/*
// @updateURL https://openuserjs.org/meta/floodmeadows/Jira_get_issue_types.meta.js
// @downloadURL https://openuserjs.org/install/floodmeadows/Jira_get_issue_types.user.js
// @grant        none
// ==/UserScript==

/* jshint esversion: 6 */

//--- Jira instance / project info ---//
const currentUrl = new URL(document.URL);
const jiraBaseUrl = currentUrl.protocol + '//' + currentUrl.host;
// Parse the Jira project key out of the current URL. e.g. if the current issue key is "ABC-1234" then the project key will be ABC.
const pathArr = location.pathname.split("/");
const jiraProjectKey = pathArr[pathArr.length-1].split("-")[0];
const issueTypesUrl = jiraBaseUrl + '/rest/api/2/issue/createmeta/' + jiraProjectKey + '/issuetypes';

(function () {
    'use strict';

    addLinkGetIssueTypes();
})();

function addLinkGetIssueTypes() {
    const newElement = document.createElement("a");
    newElement.setAttribute("href", "#");
    newElement.setAttribute("class", "aui-button toolbar-trigger issueaction-workflow-transition");
    newElement.addEventListener("click", getIssueTypes);
    const text = document.createTextNode("Get issue types");
    newElement.appendChild(text);
    const target = document.getElementById('opsbar-transitions_more');
    target.parentNode.appendChild(newElement);
}

function getIssueTypes() {
    var headers = new Headers();
    headers.append("Content-Type", "application/json");

    var requestOptions = {
        method: 'GET',
        headers: headers
    };

    fetch(issueTypesUrl, requestOptions)
        .then(response => console.log(response.text()))
        .catch(error => console.log('error', error));

    /* Output includes...
          {
             "self":"https://jira.tools.tax.service.gov.uk/rest/api/2/issuetype/5",
             "id":"5",
             "description":"The sub-task of the issue",
             "iconUrl":"https://jira.tools.tax.service.gov.uk/secure/viewavatar?size=xsmall&avatarId=10916&avatarType=issuetype",
             "name":"Sub-task",
             "subtask":true
          },
          {
             "self":"https://jira.tools.tax.service.gov.uk/rest/api/2/issuetype/7",
             "id":"7",
             "description":"Created by Jira Software - do not edit or delete. Issue type for a user story.",
             "iconUrl":"https://jira.tools.tax.service.gov.uk/secure/viewavatar?size=xsmall&avatarId=10915&avatarType=issuetype",
             "name":"Story",
             "subtask":false
          },
    */

}