Collapsable Diffs and Linked Branches (GitHub)

Some small changes to GitHub's pull request interface

As of 2016-01-26. See the latest version.

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