GitHub expand files button

Adds a button to expand all files in a GitHub pull request or commit view.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         GitHub expand files button
// @namespace    https://puac.de/
// @version      0.1.1
// @description  Adds a button to expand all files in a GitHub pull request or commit view.
// @author       Hans Puac
// @match        https://github.com/*/pull/*/files
// @match        https://github.com/*/commit/*
// @run-at       document-end
// ==/UserScript==

(function () {
    'use strict';

    var expanding = false;
    var expandButton = document.createElement('button');

    var btnClicked = function () {
        if (!expanding) {
            expanding = true;
            expandAllFiles();
        }
    };

    var expandAllFiles = function () {
        expandButton.innerText = 'Expanding files ...';
        expandButton.classList.add('btn-outline', 'bg-gray-light', 'text-gray-light');
        expandButton.setAttribute('disabled', true);

        var expand = function () {
            var anchors = document.querySelectorAll('.js-expand');
            var len = anchors.length;
            if (len < 1) {
                expandButton.innerText = 'All Files expanded';

                return;
            }

            anchors.forEach(function (item) {
                item.click();
            });

            setTimeout(function () {
                expand();
            }, 1000);
        };
        expand();
    };

    expandButton.innerText = 'Expand all files';
    expandButton.classList.add('btn', 'btn-sm');
    expandButton.style.float = 'left';
    expandButton.style.marginRight = '20px';
    expandButton.addEventListener('click', btnClicked, false);

    var btnWrapper = document.querySelector('.pr-review-tools');
    if (btnWrapper === null) {
        btnWrapper = document.querySelector('.js-details-container .BtnGroup');
    }
    btnWrapper.prepend(expandButton);
})();