Collapsable Diffs and Linked Branches (GitHub)

Some small changes to GitHub's pull request interface

Verze ze dne 20. 12. 2015. Zobrazit nejnovější verzi.

  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.4
  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. area.hide();
  27. } else {
  28. icon.attr('class', 'octicon octicon-triangle-down');
  29. area.show();
  30. }
  31. });
  32. });
  33. }
  34. }
  35. function makeLinks() {
  36. if ($('#partial-discussion-header').length) {
  37. $('span.commit-ref.current-branch').each(function() {
  38. var repo = $('.entry-title a[data-pjax]').text();
  39. var baseUrl = 'https://github.com';
  40. var branch = $(this).text();
  41. if (branch.indexOf(':') === -1) {
  42. baseUrl += $('.entry-title a[data-pjax]').attr('href') + '/tree/';
  43. $(this).wrap('<a href="' + baseUrl + branch + '"></a>');
  44. } else {
  45. var fork = branch.split(':');
  46. baseUrl += '/' + fork[0] + '/' + repo + '/tree/';
  47. $(this).wrap('<a href="' + baseUrl + fork[1] + '"></a>');
  48. }
  49. });
  50. }
  51. }
  52. makeLinks();
  53. collapsable();
  54.  
  55. window.$(document).on('pjax:end', function() {
  56. makeLinks();
  57. collapsable();
  58. });
  59. });