Collapsable Diffs (GitHub)

Adds a button that allows you to collapse an individual diff in a pull request

Fra 19.12.2015. Se den seneste versjonen.

  1. // ==UserScript==
  2. // @name Collapsable Diffs (GitHub)
  3. // @namespace chriskim06
  4. // @description Adds a button that allows you to collapse an individual diff in a pull request
  5. // @include https://github.com/*/*/pull/*
  6. // @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
  7. // @version 1.3
  8. // @grant none
  9. // @locale en
  10. // ==/UserScript==
  11.  
  12. this.$ = this.jQuery = jQuery.noConflict(true);
  13.  
  14. $(function() {
  15. function collapsable() {
  16. if ($('#diff').length) {
  17. var expanded = '<a class="octicon-btn custom-collapsable" href="javascript:void(0)" onclick="return false;"><span class="octicon octicon-triangle-down "></span></a>';
  18. $('#diff').find('#files > div[id^="diff-"]').each(function() {
  19. var diff = $(this);
  20. diff.find('.file-info').prepend(expanded);
  21. var area = diff.children('.data.highlight.blob-wrapper');
  22. diff.find('.octicon-btn.custom-collapsable').on('click', function() {
  23. var icon = $(this).children(':first');
  24. if (icon.hasClass('octicon-triangle-down')) {
  25. icon.attr('class', 'octicon octicon-triangle-right');
  26. } else {
  27. icon.attr('class', 'octicon octicon-triangle-down');
  28. }
  29. area.slideToggle('fast');
  30. });
  31. });
  32. }
  33. }
  34. });