GitHub - Make PRs easier

Collapsing Headers on diffs

Tính đến 22-09-2015. Xem phiên bản mới nhất.

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

Bạn sẽ cần cài đặt một tiện ích mở rộng như Tampermonkey hoặc Violentmonkey để cài đặt kịch bản này.

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.

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

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         GitHub - Make PRs easier
// @namespace    http://adamwknox.com
// @version      0.6
// @description  Collapsing Headers on diffs
// @author       DrKnoxy
// @include      https://github.com/*
// @grant        none
// ==/UserScript==

var blobSelector = '.blob-wrapper, .render-wrapper, .file-header + .empty';
function monitorHeaderToggle() {
  $(document).on('click', '.file-header', function(e){
    $(this).next(blobSelector).toggle();
  });
}

var toggleID = 'js-blob-collapser';
function addToggle() {
  if (!$('#'+toggleID).length){
    $('#toc .btn-group').before('<a id="'+toggleID+'" class="btn btn-sm right" style="margin-left:4px;">Collapse</a>');
  }
}

var allVisible = true;
function monitorToggle() {
  $(document).on('click', '#'+toggleID, function(e) {
    e.preventDefault();
    if (allVisible) {
      $(this).addClass('selected');
      $(blobSelector).hide();
    } else {
      $(this).removeClass('selected');
      $(blobSelector).show();
    }

    allVisible = !allVisible;
  });
}

$(function(){
  // Toggling with the header
  monitorHeaderToggle();

  // Collapsing all
  addToggle();
  monitorToggle();

  $(document).on('pjax:complete pjax:popstate', function(e){
    addToggle();
  });
});