Generate Launchpad Bug Links from tags

Parse tags, create buttons for originate-from bug links and JIRA links

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Generate Launchpad Bug Links from tags
// @namespace    http://anthonywong.net/
// @version      1.4
// @description  Parse tags, create buttons for originate-from bug links and JIRA links
// @match        https://bugs.launchpad.net/*/+bug/*
// @grant        none
// @license      GPLv2
// ==/UserScript==

(function () {
    'use strict';

    // Locate the <span id="tag-list"> element
    const tagsElement = document.querySelector('#tag-list');

    if (tagsElement) {
        // Extract the tags as text
        const tagsText = tagsElement.textContent;

        // Find all "originate-from-XXXX" patterns
        const originateMatches = tagsText.match(/originate-from-(\d+)/g);

        // Find all "jira-$JIRA_TICKET" patterns
        const jiraMatches = tagsText.match(/jira-([a-zA-Z0-9\-]+)/g);

        // Create a container for the buttons
        const buttonContainer = document.createElement("div");
        buttonContainer.style.marginTop = "10px";

        // Process originate-from tags
        if (originateMatches) {
            originateMatches.forEach((tag) => {
                const bugNumber = tag.replace("originate-from-", "");

                // Create a button
                const button = document.createElement("button");
                button.textContent = `Go to Bug ${bugNumber}`;
                button.style.marginRight = "5px";
                button.style.padding = "5px 10px";

                // Set up the button click event
                button.addEventListener("click", () => {
                    const bugUrl = `https://bugs.launchpad.net/ubuntu/+bug/${bugNumber}`;
                    window.open(bugUrl, "_blank");
                });

                // Add the button to the container
                buttonContainer.appendChild(button);
            });
        }

        // Process JIRA tags
        if (jiraMatches) {
            jiraMatches.forEach((tag) => {
                const jiraTicket = tag.replace("jira-", "").toUpperCase();

                // Create a button
                const button = document.createElement("button");
                button.textContent = `Go to JIRA ${jiraTicket}`;
                button.style.marginRight = "5px";
                button.style.padding = "5px 10px";

                // Set up the button click event
                button.addEventListener("click", () => {
                    const jiraUrl = `https://warthogs.atlassian.net/browse/${jiraTicket}`;
                    window.open(jiraUrl, "_blank");
                });

                // Add the button to the container
                buttonContainer.appendChild(button);
            });
        }

        // Append the container below the tags element
        if (buttonContainer.childNodes.length > 0) {
            tagsElement.parentNode.appendChild(buttonContainer);
        }
    }
})();