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 यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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);
})();