Toggle ChatGPT Sidebar with Cmd+\

Toggle the sidebar in ChatGPT using Command + Backslash

  1. // ==UserScript==
  2. // @name Toggle ChatGPT Sidebar with Cmd+\
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.2
  5. // @description Toggle the sidebar in ChatGPT using Command + Backslash
  6. // @author Drewby123
  7. // @match https://chatgpt.com/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14.  
  15. let sidebarButton = null;
  16.  
  17. function updateSidebarButton() {
  18. const btn = document.querySelector('button[aria-label="Open sidebar"], button[aria-label="Close sidebar"]');
  19. if (btn) {
  20. sidebarButton = btn;
  21. }
  22. }
  23.  
  24. const observer = new MutationObserver(() => {
  25. updateSidebarButton();
  26. });
  27.  
  28. observer.observe(document.body, { childList: true, subtree: true });
  29.  
  30. // Listen for Command + \
  31. document.addEventListener('keydown', function (e) {
  32. if (e.metaKey && e.key === '\\') {
  33. e.preventDefault();
  34. if (sidebarButton) {
  35. sidebarButton.click();
  36. } else {
  37. console.warn('Sidebar toggle button not found');
  38. }
  39. }
  40. });
  41. })();