PR Files Collapser

It collapses files on Github PR view

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

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