stackoverflow-toggle-sidebar

Uses a keyboard shortcut to toggle the left sidebar in stackoverflow.

目前为 2023-04-14 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name stackoverflow-toggle-sidebar
  3. // @version 0.1
  4. // @description Uses a keyboard shortcut to toggle the left sidebar in stackoverflow.
  5. // @match https://stackoverflow.com/*
  6. // @namespace https://greasyfork.org/en/users/217495-eric-toombs
  7. // ==/UserScript==
  8.  
  9.  
  10. function hide() {
  11. document.getElementById("left-sidebar").hidden = true;
  12. document.getElementById("content").style.width = "100%";
  13. document.panel_hidden = true;
  14. }
  15. function show() {
  16. document.getElementById("content").style.width = "";
  17. document.getElementById("left-sidebar").hidden = false;
  18. document.panel_hidden = false;
  19. }
  20.  
  21. hide();
  22.  
  23. document.onkeydown = async function(k) {
  24. if (k.altKey && k.which === "P".codePointAt(0)) {
  25. if (document.panel_hidden) {
  26. show();
  27. } else {
  28. hide();
  29. }
  30. }
  31. }