[Azure] Auto Resolve All

[Azure] Auto Resolve

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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 });
})();