Skip to content

Instantly share code, notes, and snippets.

@refs
Last active December 13, 2018 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save refs/e4a014551cf312a9ffbf0b41745a8b68 to your computer and use it in GitHub Desktop.
Save refs/e4a014551cf312a9ffbf0b41745a8b68 to your computer and use it in GitHub Desktop.
// ==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==
// https://greasyfork.org/en/scripts/375488-pr-files-collapser
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()
})()
@jebbinBjss
Copy link

This isn't a well advertised feature, but you can collapse all but alt clicking on one of the collapse buttons for the files, so this is unecessary.

@refs
Copy link
Author

refs commented Dec 13, 2018

nice! I was completely oblivious of it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment