Youtube Collapse Sidebar

collapse youtube sidebar

目前为 2023-06-07 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Youtube Collapse Sidebar
  3. // @version 0.5
  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://i.ibb.co/VxF8nPm/8212733.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. function clickGuideButton() {
  21. const guideButton = document.querySelector("#guide-button");
  22. if (guideButton) {
  23. guideButton.click();
  24. }
  25. }
  26.  
  27. // Função de callback para o MutationObserver
  28. function mutationCallback(mutationsList, observer) {
  29. for (let mutation of mutationsList) {
  30. if (
  31. mutation.type === "childList" &&
  32. document.querySelector("#sections")
  33. ) {
  34. clickGuideButton(); // Executa a função para clicar no botão de guia
  35. observer.disconnect(); // Para de observar as mutações quando o elemento desejado é encontrado
  36. break;
  37. }
  38. }
  39. }
  40.  
  41. // Cria o MutationObserver
  42. const observer = new MutationObserver(mutationCallback);
  43.  
  44. // Configura as opções do MutationObserver
  45. const observerConfig = {
  46. childList: true,
  47. subtree: true,
  48. };
  49.  
  50. // Observa as mudanças no DOM
  51. observer.observe(document.documentElement, observerConfig);
  52. })();