Stackoverflow Right Sidebar Toggler

Gives you the ability to collapse right sidebar.

  1. // ==UserScript==
  2. // @name Stackoverflow Right Sidebar Toggler
  3. // @namespace https://github.com/GrumpyCrouton/Userscripts/blob/master/Right%20Sidebar%20Toggler
  4. // @version 1.0
  5. // @description Gives you the ability to collapse right sidebar.
  6. // @author GrumpyCrouton
  7. // @match *://*.stackoverflow.com/*
  8. // @match *://*.stackexchange.com/*
  9. // @match *://*.superuser.com/*
  10. // @grant GM_setValue
  11. // @grant GM_getValue
  12. // @run-at document-start
  13. // ==/UserScript==
  14. document.onreadystatechange = function() {
  15. if (document.readyState === "interactive") {
  16.  
  17. var sidebar = $('#sidebar');
  18. var content = $('#mainbar');
  19.  
  20. if ($("#left-sidebar").length > 0) { //SIDE BAR EXISTS (responsive)
  21. //body changes
  22.  
  23. //add space in left sidebar for options specific to visualcrumbs
  24. $('nav[role="navigation"] ol:first').append(' \
  25. <li> \
  26. <ol class="nav-links"> \
  27. <li class="fs-fine tt-uppercase ml8 mt24 mb4 fc-light"> \
  28. Options \
  29. </li> \
  30. <li> \
  31. <a class="pl8 js-gps-track nav-links--link -link__with-icon"> \
  32. <span id="visualcrumbs_hideRightBar" class="-link--channel-name">Toggle Right Sidebar</span> \
  33. </a> \
  34. </li> \
  35. </ol> \
  36. </li>');
  37.  
  38. manageRightBarOnLoad();
  39.  
  40. }
  41.  
  42. $("#visualcrumbs_hideRightBar").click(handleRightBarCollapse);
  43.  
  44. function handleRightBarCollapse() {
  45.  
  46. if (sidebar.is(":visible")) {
  47. GM_setValue("hideRightBar", true);
  48. content.css("width", "100%");
  49. sidebar.hide();
  50. } else {
  51. GM_setValue("hideRightBar", false);
  52. content.css("width", "");
  53. sidebar.show();
  54. }
  55. }
  56.  
  57. function manageRightBarOnLoad() {
  58. var result = GM_getValue("hideRightBar", false);
  59. if (result) {
  60. content.css("width", "100%");
  61. sidebar.hide();
  62. }
  63. }
  64.  
  65. }
  66. }