Azure DevOps URL Base Toggle

Toggle Azure DevOps URL between dev.azure.com/{org} and {org}.visualstudio.com

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Azure DevOps URL Base Toggle
// @namespace    https://tampermonkey.net/
// @version      1.1
// @author       Jatin Sharma
// @description  Toggle Azure DevOps URL between dev.azure.com/{org} and {org}.visualstudio.com
// @icon         https://www.google.com/s2/favicons?sz=64&domain=visualstudio.com
// @match        https://dev.azure.com/*
// @match        https://*.visualstudio.com/*
// @run-at       document-idle
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    const BUTTON_ID = 'ado-url-toggle-btn';

    function toggleUrl() {
        const url = new URL(window.location.href);

        if (url.hostname === 'dev.azure.com') {
            const parts = url.pathname.split('/').filter(Boolean);
            if (!parts.length) return;

            const org = parts.shift();
            url.hostname = `${org}.visualstudio.com`;
            url.pathname = '/' + parts.join('/');
        } else if (url.hostname.endsWith('.visualstudio.com')) {
            const org = url.hostname.split('.')[0];
            url.hostname = 'dev.azure.com';
            url.pathname = `/${org}${url.pathname}`;
        } else {
            return;
        }

        window.location.href = url.toString();
    }

    function createButton() {
        if (document.getElementById(BUTTON_ID)) return;

        const menuBar = document.querySelector('div.region-header-menubar');
        if (!menuBar) return;

        const button = document.createElement('button');
        button.id = BUTTON_ID;
        button.textContent = 'URL';
        button.title = 'Toggle Azure DevOps URL base';
        button.className = 'bolt-button bolt-icon-button enabled subtle bolt-focus-treatment';
        button.style.marginRight = '8px';
        button.style.cursor = 'pointer';

        button.addEventListener('click', toggleUrl);

        menuBar.prepend(button);
    }

    const observer = new MutationObserver(createButton);
    observer.observe(document.documentElement, { childList: true, subtree: true });

    createButton();
})();