wmosakowskicraft / Jira HPSM Ticket

// ==UserScript==
// @name         Jira HPSM Ticket
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  This script is written to allow easy navigating to HPSM ticket
// @author       Wieslaw Mosakowski
// @updateURL    https://openuserjs.org/meta/wmosakowskicraft/Jira_HPSM_Ticket.meta.js
// @match        https://jira.atlassian.com/browse/*
// @match        http://jira.intranet.roche.com/jira/browse/*
// @match        http://jira.intranet.roche.com/jira/projects/MEDINF/issues/*
// ==/UserScript==

$(document).ajaxComplete(function() {

    if(!$('#hpsmTicket').next().length) {

        let hpsmID = $('#customfield_10624-val').text().replace(/\s/g,'');  // also remove whitespaces

        if(hpsmID != '' && hpsmID != 'n/a')
        {
            $('#hpsmTicket').remove();
            $('.toolbar-split-left').append("<button id='hpsmTicket'  class='aui-button aui-button-secondary aui-style'>HPSM Ticket</button>");
            $("#hpsmTicket").click(function(){ window.open('http://servicemanager.roche.com/sm9/index.do?ctx=docEngine&file=probsummary&query=number%3D%22' + hpsmID + '%22&action=&title=Incident%3A%20' + hpsmID); });

        }


    }

});