PR Files Collapser

It collapses files on Github PR view

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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.

(I already have a user style manager, let me install it!)

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