Github PRs: Collapse/expand file

1 min read Original article ↗
// Add a button to Collapse or Expand files in a Github PR
//
// See it in action: http://cl.ly/image/1r3q3d0d3b0p
//
// Install Tampermonkey and add this as a script
// ==UserScript==
// @name Github PRs: Collapse/expand file
// @namespace https://gist.github.com/micho/855b272d2f408f04729e
// @version 0.1
// @description Add a button to expand or collapse files in PRs
// @author You
// @match https://github.com/*/pull/*/files
// @grant none
// ==/UserScript==
$(function () {
$(".js-conduit-openfile-check").remove();
$(".file .actions").prepend(function () {
$button = $('<a href="#" class="minibutton">Collapse</a>')
$button.click(function (e) {
e.preventDefault();
$(this).parents(".file").find(".data").toggle()
$(this).text($(this).text() == "Collapse" ? "Expand" : "Collapse");
});
$(this).find(".minibutton").after($button).after(" ");
})
});