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

当前为 2016-01-23 提交的版本,查看 最新版本

  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.1
  8. // @grant none
  9. // @locale en
  10. // ==/UserScript==
  11.  
  12. this.$ = this.jQuery = jQuery.noConflict(true);
  13.  
  14. $(function() {
  15. if ($('#user-links').length) {
  16. // Add buttons in the header navbar for widening and hiding whitespace
  17. $('#user-links').prepend('<li class="header-nav-item"><a href="javascript:void(0)" id="hide-whitespace-button" class="header-nav-link tooltipped tooltipped-s" aria-label="Hide whitespace" onclick="return false;"><span class="octicon octicon-circle-slash"></span></a></li>');
  18. $('#user-links').prepend('<li class="header-nav-item"><a href="javascript:void(0)" id="code-widen-button" class="header-nav-link tooltipped tooltipped-s" aria-label="Widen code container" onclick="return false;"><span class="octicon octicon-mirror "></span></a></li>');
  19. // Toggle code container width on click
  20. $('#code-widen-button').click(function(e) {
  21. if ($('#files').length || $('.repository-content').find('.file').length) {
  22. // If diff is in split mode don't try to widen the container
  23. if ($('#toc').find('.btn-group > a:last').hasClass('selected')) {
  24. $(this).blur();
  25. return;
  26. }
  27. var container = $('.container.new-discussion-timeline.experiment-repo-nav');
  28. var expanded = $(window).width() * 0.95;
  29. if (container.width() < expanded) {
  30. container.css('width', expanded + 'px');
  31. } else {
  32. container.css('width', '980px');
  33. }
  34. }
  35. $(this).blur();
  36. });
  37. // Toggle page with ?w=1 appended to the url to show/hide whitespace
  38. $('#hide-whitespace-button').click(function(e) {
  39. if ($('#files').length && $('#files').is(':visible')) {
  40. var url = window.location.href;
  41. if (url.endsWith('?w=1') || url.endsWith('&w=1')) {
  42. window.location.href = url.slice(0, -4);
  43. } else if (url.includes('?')) {
  44. window.location.href = url + '&w=1';
  45. } else {
  46. window.location.href = url + '?w=1';
  47. }
  48. }
  49. $(this).blur();
  50. });
  51. }
  52. });

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址