Azure DevOps URL Base Toggle

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

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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();
})();