[Azure] Auto Resolve All

[Azure] Auto Resolve

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

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.

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

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

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.

ستحتاج إلى تثبيت إضافة مثل 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 });
})();