Widen Code Container and Hide Whitespace (GitHub)

Adds buttons to allow you to widen the container when viewing files and hide whitespace when viewing pull request diffs

Versión del día 14/02/2016. Echa un vistazo a la versión más reciente.

  1. // ==UserScript==
  2. // @name Widen Code Container and Hide Whitespace (GitHub)
  3. // @namespace chriskim06
  4. // @description Adds buttons to allow you to widen the container when viewing files and hide whitespace when viewing pull request diffs
  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.  
  16. if ($('#user-links').length) {
  17.  
  18. // Add buttons in the header navbar for widening and hiding whitespace
  19. $('#user-links').prepend(
  20. '<li class="header-nav-item">' +
  21. '<a href="javascript:void(0)"' +
  22. 'id="hide-whitespace-button"' +
  23. 'class="header-nav-link tooltipped tooltipped-s"' +
  24. 'aria-label="Hide whitespace"' +
  25. 'onclick="return false;">' +
  26. '<svg height="16" width="14" xmlns="http://www.w3.org/2000/svg"><path d="M7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7S10.86 1 7 1z m0 1.3c1.3 0 2.5 0.44 3.47 1.17L2.47 11.47c-0.73-0.97-1.17-2.17-1.17-3.47 0-3.14 2.56-5.7 5.7-5.7z m0 11.41c-1.3 0-2.5-0.44-3.47-1.17l8-8c0.73 0.97 1.17 2.17 1.17 3.47 0 3.14-2.56 5.7-5.7 5.7z" /></svg>' +
  27. '</a>' +
  28. '</li>'
  29. );
  30. $('#user-links').prepend(
  31. '<li class="header-nav-item">' +
  32. '<a href="javascript:void(0)"' +
  33. 'id="code-widen-button"' +
  34. 'class="header-nav-link tooltipped tooltipped-s"' +
  35. 'aria-label="Widen code container"' +
  36. 'onclick="return false;">' +
  37. '<svg height="16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="M15.5 4.7L8.5 0 1.5 4.7c-0.3 0.19-0.5 0.45-0.5 0.8v10.5l7.5-4 7.5 4V5.5c0-0.34-0.2-0.61-0.5-0.8z m-0.5 9.8L9 11.25v-1.25h-1v1.25L2 14.5V5.5L8 1.5v4.5h1V1.5l6 4v9zM6 7h5V5l3 3-3 3V9H6v2L3 8l3-3v2z" /></svg>' +
  38. '</a>' +
  39. '</li>'
  40. );
  41. // Toggle code container width on click
  42. $('#code-widen-button').click(function() {
  43. var url = window.location.href.replace(/https:\/\/github.com\/.+\/.+\/pull\/[\d]+/, '');
  44. var container = $('.container.new-discussion-timeline.experiment-repo-nav');
  45. var expanded = $(window).width() * 0.95;
  46. var diff = $('#files');
  47. var file = $('.repository-content').find('.file');
  48. if ((diff.length && diff.is(':visible')) || (file.length && file.is(':visible'))) {
  49. // If diff is in split mode don't try to widen the container
  50. if ($('#toc').find('.btn-group > a:last').hasClass('selected')) {
  51. $(this).blur();
  52. return;
  53. }
  54. if (container.width() < expanded) {
  55. container.css('width', expanded + 'px');
  56. } else {
  57. container.css('width', '980px');
  58. }
  59. } else if (url === '' || url === 'commits') {
  60. if (container.width() >= expanded) {
  61. container.css('width', '980px');
  62. }
  63. }
  64. $(this).blur();
  65. });
  66. // Toggle page with ?w=1 appended to the url to show/hide whitespace
  67. $('#hide-whitespace-button').click(function() {
  68. if ($('#files').length && $('#files').is(':visible')) {
  69. var url = window.location.href;
  70. if (url.endsWith('?w=1') || url.endsWith('&w=1')) {
  71. window.location.href = url.slice(0, -4);
  72. } else if (url.includes('?')) {
  73. window.location.href = url + '&w=1';
  74. } else {
  75. window.location.href = url + '?w=1';
  76. }
  77. }
  78. $(this).blur();
  79. });
  80. }
  81. });