PR: Expand All "Show resolved" buttons

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

当前为 2020-02-03 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

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