Greasy Fork is available in English.

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

Per 07-10-2017. Zie de nieuwste versie.

  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.4.3
  8. // @grant none
  9. // @locale en
  10. // ==/UserScript==
  11.  
  12. this.$ = this.jQuery = jQuery.noConflict(true);
  13.  
  14. $(function() {
  15.  
  16. function beginElement(id, label) {
  17. return '<li class="header-nav-item">' +
  18. '<a href="javascript:void(0)"' +
  19. 'id="' + id + '"' +
  20. 'class="header-nav-link tooltipped tooltipped-s js-menu-target"' +
  21. 'aria-label="' + label + '"' +
  22. 'style="margin: 5px 8px 0;"' +
  23. 'onclick="return false;">';
  24. }
  25.  
  26. var links = $('#user-links');
  27. if (links.length) {
  28. // Add buttons in the header navbar for widening and hiding whitespace
  29. links.prepend(
  30. beginElement('hide-whitespace-button', 'Hide whitespace') +
  31. '<svg height="16" width="14" style="fill:rgba(255,255,255,0.75);margin-top:6px;" 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>' +
  32. '</a></li>'
  33. ).prepend(
  34. beginElement('code-widen-button', 'Widen code container') +
  35. '<svg height="16" width="16" style="fill:rgba(255,255,255,0.75);margin-top:6px;" 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>' +
  36. '</a></li>'
  37. );
  38.  
  39. // Check if notifications button is empty
  40. var notifications = links.find('.js-header-notifications');
  41. if (notifications.length && notifications.text().trim() === '') {
  42. notifications.remove();
  43. }
  44.  
  45. // Toggle code container width on click
  46. $('#code-widen-button').click(function() {
  47. var container = $('.container.new-discussion-timeline.experiment-repo-nav');
  48. var expanded = $(window).width() * 0.95;
  49. if ($('.repository-content').find('.file').is(':visible') || ($('#files').is(':visible') && $('meta[name="diff-view"]').attr('content') === 'unified')) {
  50. // Only widen if viewing a single file or changes in unified mode
  51. container.css('width', (container.width() < expanded) ? expanded : 980);
  52. } else if (container.width() >= expanded) {
  53. // Reduce the width on a page if needed
  54. container.css('width', 980);
  55. }
  56. $(this).blur();
  57. });
  58.  
  59. // Toggle page with the w=1 query param in the url to show/hide whitespace
  60. $('#hide-whitespace-button').click(function() {
  61. if ($('#files').is(':visible')) {
  62. var url = window.location.href;
  63. if (url.includes('?w=1')) {
  64. // Check if there is more to the query and remove the whitespace query param
  65. window.location.href = url.replace((url.includes('&') ? /w=1\&/ : /\?w=1/), '');
  66. } else if (url.includes('&w=1')) {
  67. // Remove the appended whitespace query param
  68. window.location.href = url.replace(/\&w=1/, '');
  69. } else {
  70. // Add the whitespace query param
  71. var query = url.includes('?') ? '&w=1' : '?w=1';
  72. if (url.includes('#')) {
  73. // Insert before any anchors in the url
  74. window.location.href = url.slice(0, url.indexOf('#')) + query + url.substr(url.indexOf('#'));
  75. } else {
  76. // Append to the url
  77. window.location.href = url + query;
  78. }
  79. }
  80. }
  81. $(this).blur();
  82. });
  83. }
  84.  
  85. });
  86.