Youtube Collapse Sidebar

collapse youtube sidebar

当前为 2023-06-19 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Youtube Collapse Sidebar
  3. // @version 0.9
  4. // @description collapse youtube sidebar
  5. // @namespace https://greasyfork.org/users/821661
  6. // @match https://www.youtube.com/
  7. // @match https://www.youtube.com/results?*
  8. // @match https://www.youtube.com/@*
  9. // @icon https://cdn-icons-png.flaticon.com/512/7711/7711100.png
  10. // @author hdyzen
  11. // @run-at document-start
  12. // @inject-into page
  13. // @unwrap
  14. // @license MIT
  15.  
  16. // ==/UserScript==
  17. (function () {
  18. ("use strict");
  19.  
  20. window.addEventListener("DOMContentLoaded", function () {
  21. const sections = document.querySelector("#sections");
  22.  
  23. function clickGuide() {
  24. document.querySelector("#guide-button").click();
  25. }
  26.  
  27. const observer = new MutationObserver(function (mutations) {
  28. mutations.forEach(function (mutation) {
  29. if (mutation.type === "childList" && document.querySelector("#sections")) {
  30. clickGuide();
  31. observer.disconnect();
  32. }
  33. });
  34. });
  35.  
  36. observer.observe(document.body, {
  37. childList: true,
  38. });
  39. });
  40. })();