Jenkins - Redirect Native UI to Blue Ocean

Redirect the native Jenkins UI to Blue Ocean

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Jenkins - Redirect Native UI to Blue Ocean
// @namespace    https://greasyfork.org/en/scripts?by=1388261
// @version      1.1
// @description  Redirect the native Jenkins UI to Blue Ocean
// @author       [email protected]
// @match        https://jenkins.audibene.net/job/*/job/*/job/*/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=audibene.net
// @tag          productivity
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const shouldConfirm = (window.localStorage.getItem('AUTO_REDIRECT') ?? 'false').toLowerCase() === 'false'
    const url = window.location.href
    const parameterizedUrl = "https://jenkins.audibene.net/blue/organizations/jenkins/:organizationId%2F:repo/detail/:pr/:run/pipeline/";

    const regex = /https:\/\/jenkins\.audibene\.net\/job\/(?<organizationId>[^\/]+)\/job\/(?<repo>[^\/]+)\/job\/(?<pr>[^\/]+)\/(?<run>[^\/]+)\/pipeline-graph\//;

    const match = url.match(regex);

    if (match) {
        const { organizationId, repo, pr, run } = match.groups;

        const hydratedUrl = parameterizedUrl
        .replace(':organizationId', organizationId)
        .replace(':repo', repo)
        .replace(':pr', pr)
        .replace(':run', run);

        if (!shouldConfirm) {
            const div = document.createElement('div')

            div.style.position = 'fixed'
            div.style.backgroundColor = '#ffffffee'
            div.style.display = 'grid'
            div.style.gap = '0.5rem'
            div.style.placeContent = 'center'
            div.style.top = 0
            div.style.bottom = 0
            div.style.left = 0
            div.style.padding = '1rem'
            div.style.right = 0
            div.style.zIndex = 9999
            div.style.transition = 'all 0.3s'

            const text = document.createElement('div')

            text.innerText = 'Redirecting to Blue Ocean...'

            div.appendChild(text)

            const button = document.createElement('button')

            const timeout = setTimeout(() => {
               window.location.href = hydratedUrl
            }, 1_500)

            button.onclick = () => {
                clearTimeout(timeout)
                div.style.opacity = 0

                setTimeout(() => {
                    div.remove()
                }, 300)
            }

            button.innerText = 'Cancel'

            div.appendChild(button)
            document.body.appendChild(div)
            button.focus()
        } else if (confirm('Redirect to Blue Ocean?')) {
            window.location.href = hydratedUrl;
        }
    } else {
        console.log("No match found");
    }
})();