GitHub hide sidebar

Hides the sidebar on GitHub tickets to use all horizontal space.

  1. // ==UserScript==
  2. // @name GitHub hide sidebar
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Hides the sidebar on GitHub tickets to use all horizontal space.
  6. // @author PK Cakeout
  7. // @match https://github.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. document.addEventListener("keydown", (event) => {
  13. function parent(x) {
  14. return x && x.parentElement;
  15. }
  16.  
  17. if (!(event.key.toLowerCase() === "s" && event.ctrlKey && event.shiftKey)) {
  18. return;
  19. }
  20.  
  21. event.preventDefault();
  22. let sidebar = parent(document.getElementById("partial-discussion-sidebar"));
  23. sidebar = sidebar ||
  24. parent(document.querySelector(".flex-shrink-0.col-12.col-md-3 > .BorderGrid.BorderGrid--spacious")) ||
  25. parent(parent(document.querySelector(".flex-shrink-0.col-12.col-md-3 > div > .discussion-sidebar-item.sidebar-assignee.js-discussion-sidebar-item")));
  26.  
  27. if (!sidebar) {
  28. console.log("Tampermonkey script: Sidebar not found");
  29. return;
  30. }
  31. const mainbar = sidebar.parentElement.children[0];
  32.  
  33. // Remove col-md-9, hide sidebar with display=none
  34. const oldStyle = sidebar.getAttribute("style") || "";
  35. if (oldStyle.indexOf("display:") < 0) {
  36. sidebar.setAttribute("style", "display: none;");
  37. mainbar.setAttribute("class", mainbar.attributes.class.value.replaceAll("col-md-9", ""));
  38. } else {
  39. sidebar.setAttribute("style", "");
  40. mainbar.setAttribute("class", mainbar.attributes.class.value + " col-md-9");
  41. }
  42. });
  43. })();