docsrs-toggle-panel

Uses a keyboard shortcut to toggle the left panel in docs.rs.

  1. // ==UserScript==
  2. // @name docsrs-toggle-panel
  3. // @version 0.1
  4. // @description Uses a keyboard shortcut to toggle the left panel in docs.rs.
  5. // @match https://*.docs.rs/*
  6. // @match https://doc.rust-lang.org/nightly/*
  7. // @namespace https://greasyfork.org/en/users/217495-eric-toombs
  8. // @license MIT
  9. // ==/UserScript==
  10.  
  11.  
  12. function hide() {
  13. document.getElementsByClassName("sidebar")[0].hidden = true;
  14. document.panel_hidden = true;
  15. }
  16. function show() {
  17. document.getElementsByClassName("sidebar")[0].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. }