PR Files Collapser

It collapses files on Github PR view

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         PR Files Collapser
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  It collapses files on Github PR view
// @author       Alex. U
// @match        https://github.com/*
// @require      https://code.jquery.com/jquery-2.1.4.min.js
// @grant        none
// @noframes
// ==/UserScript==

var filesLandingPage = () => {
    if (window.location.href.includes('files')) {
        renderCollapseAll()
    }
}

var setListener = () => {
  $(document).on('pjax:success', function(event, data, status, xhr, options) {
    if (window.location.href.match(/https:\/\/github.com\/[\D]+\/[\d]+\/files/g)) {
      renderCollapseAll()
    }
  });
}

var renderCollapseAll = () => {
    var zNode = document.createElement ('details')
    zNode.innerHTML = '<summary id="collapseAll" class="btn btn-sm" style="margin-left: 20px;"> Collapse all</summary>'

    $('.pr-review-tools')[0].append(zNode)
    $('.pr-review-tools').css('display', 'flex')

    document.getElementById('collapseAll').addEventListener('click', (event) => {
        document.querySelectorAll('button.js-details-target').forEach(button => button.click())
    })
}

(() => {
    console.info("Github Files Collapser Injected")
    filesLandingPage()
    setListener()
})()