[Azure] Auto Resolve All

[Azure] Auto Resolve

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         [Azure] Auto Resolve All
// @namespace    Azure
// @version      1.10.12
// @description  [Azure] Auto Resolve
// @author       N.Duong
// @icon         https://www.google.com/s2/favicons?sz=64&domain=microsoft.com
// @run-at       document-start
// @grant        none
// @license      MIT
// @match        https://*/*/pullrequest/*
// @match        https://*/*/pullrequest/*
// ==/UserScript==

(function() {
    'use strict';

    function addResolveAllButton() {
        if (document.querySelector('#resolve')) {
            return; // Button already exists
        }

        let targetDiv = document.querySelector('.repos-activity-filter-dropdown');
        if (targetDiv) {
            let resolveButton = document.createElement('button');
            resolveButton.id = "resolve";
            resolveButton.textContent = 'Resolve All';
            resolveButton.className = 'bolt-button enabled bolt-focus-treatment';
            resolveButton.type = 'button';
            resolveButton.tabIndex = '0';
            resolveButton.style.marginLeft = '12px';

            resolveButton.addEventListener('click', function() {
                let xpath = "//div[contains(@class, 'repos-comment-editor-max-width')]//button[contains(@class, 'bolt-button')]";
                let button = document.evaluate(xpath, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
                for (let i = 0; i < button.snapshotLength; i++) {
                    let element = button.snapshotItem(i);
                    if (element.textContent.trim().toLowerCase() === 'resolve') {
                        console.log(element.textContent);
                        element.click();
                    }
                }
            });

            targetDiv.appendChild(resolveButton);
        }
    }
    
    // Option 1:
    window.addEventListener('DOMContentLoaded', addResolveAllButton, false);
    
    // Option 2:
    //addResolveAllButton();
    //const observer = new MutationObserver(addResolveAllButton);
    //observer.observe(document.body, { childList: true, subtree: true });
})();