PR: Expand All "Show resolved" buttons

Expand All "Show resolved" buttons in pull request reviews.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         PR: Expand All "Show resolved" buttons
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Expand All "Show resolved" buttons in pull request reviews.
// @author       Marcin Warpechowski
// @match        https://github.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const pluginName = 'processed-by-warpech-expand-show-resolved';

    let scheduledTimeout;

    function findAndApplyChanges() {
        console.log('Running... Expand All "Show resolved" buttons in PRs');
        Array.from(document.querySelectorAll(`button:not([${pluginName}]), .btn-link:not([${pluginName}])`)).forEach((elem) => {
            elem.setAttribute(pluginName, '');
            if ((elem.innerText === 'Show resolved' || elem.innerText === ' Show conversation')) {
                elem.dispatchEvent(new MouseEvent('click', {
                    bubbles: true,
                    cancelable: true
                }));
            }
        });
    }

    // console.log('Postponing... Expand All "Show resolved" buttons in PRs');
    scheduledTimeout = setTimeout(findAndApplyChanges, 1000);

    const targetNode = document.querySelector("div.application-main");
    const observerOptions = {
        childList: true,
        subtree: true
    }

    const mutationCallback = (mutationList, observer) => {
        mutationList.forEach((mutation) => {
            switch(mutation.type) {
                case 'childList':
                    // console.log('Postponing... Expand All "Show resolved" buttons in PRs');
                    clearTimeout(scheduledTimeout);
                    scheduledTimeout = setTimeout(findAndApplyChanges, 1000);
                    break;
            }
        });
    }

    const observer = new MutationObserver(mutationCallback);
    observer.observe(targetNode, observerOptions);
})();