Collapsable Diffs and Linked Branches (GitHub)

Adds a toggle to collapse diffs in GitHub's pull request and commit diff interfaces

Verze ze dne 27. 01. 2016. Zobrazit nejnovější verzi.

  1. // ==UserScript==
  2. // @name Collapsable Diffs and Linked Branches (GitHub)
  3. // @namespace chriskim06
  4. // @description Adds a toggle to collapse diffs in GitHub's pull request and commit diff interfaces
  5. // @include /^https://github\.com/.*/.*/(commit|pull)/.*$/
  6. // @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
  7. // @version 1.3.8
  8. // @grant none
  9. // @locale en
  10. // ==/UserScript==
  11.  
  12. this.$ = this.jQuery = jQuery.noConflict(true);
  13.  
  14. $(function() {
  15.  
  16. function collapsable() {
  17. console.log('collapsable');
  18. if ($('#files').length) {
  19. console.log('area found');
  20. var expanded = '<a class="octicon-btn custom-collapsable" href="javascript:void(0)" onclick="return false;"><span class="octicon octicon-triangle-down "></span></a>';
  21. $('#files').find('div[id^="diff-"]').each(function() {
  22. var diff = $(this);
  23. var info = diff.find('.file-info');
  24. if (!info.children().first().is('a')) {
  25. info.prepend(expanded);
  26. diff.find('.octicon-btn.custom-collapsable').on('click', function() {
  27. var icon = $(this).children().first();
  28. if (icon.hasClass('octicon-triangle-down')) {
  29. icon.attr('class', 'octicon octicon-triangle-right');
  30. } else {
  31. icon.attr('class', 'octicon octicon-triangle-down');
  32. }
  33. diff.children('.data.highlight.blob-wrapper').slideToggle('fast');
  34. });
  35. }
  36. });
  37. }
  38. }
  39. function makeLinks() {
  40. if ($('#partial-discussion-header').length) {
  41. $('span.commit-ref.current-branch').each(function() {
  42. var elem = $(this);
  43. var repo = $('.entry-title').find('a[data-pjax]');
  44. var url = 'https://github.com';
  45. var branch = elem.text();
  46. if (branch.indexOf(':') === -1) {
  47. url += repo.attr('href') + '/tree/' + branch;
  48. } else {
  49. var fork = branch.split(':');
  50. url += '/' + fork[0] + '/' + repo.text() + '/tree/' + fork[1];
  51. }
  52. elem.wrap('<a href="' + url + '"></a>');
  53. });
  54. }
  55. }
  56. makeLinks();
  57. collapsable();
  58.  
  59. window.$(document).on('pjax:end', function() {
  60. console.log('pjax:end');
  61. makeLinks();
  62. collapsable();
  63. });
  64. });