Youtube compact sidebar+

Add more buttons in compact sidebar/mini guide

  1. // ==UserScript==
  2. // @name Youtube compact sidebar+
  3. // @name:pt-BR Youtube barra lateral+
  4. // @namespace https://greasyfork.org/users/821661
  5. // @match https://www.youtube.com/*
  6. // @grant GM_xmlhttpRequest
  7. // @grant GM_registerMenuCommand
  8. // @grant GM_setValue
  9. // @grant GM_getValue
  10. // @grant GM_addStyle
  11. // @grant GM_addStyle
  12. // @run-at document-body
  13. // @version 0.4
  14. // @author hdyzen
  15. // @description Add more buttons in compact sidebar/mini guide
  16. // @description:pt-BR Adiciona mais botões a barra lateral
  17. // @license GPL-3.0
  18. // ==/UserScript==
  19. 'use strict';
  20.  
  21. // Labels
  22. const labels = {
  23. home: 'Home',
  24. shorts: 'Shorts',
  25. subscriptions: 'Subscriptions',
  26. you: 'You',
  27. yourChannel: 'Channel',
  28. history: 'History',
  29. playlists: 'Playlists',
  30. yourVideos: 'Videos',
  31. watchLater: 'Later',
  32. liked: 'Liked',
  33. download: 'Download',
  34. };
  35.  
  36. // Render commands menu
  37. function renderMenuCommands() {
  38. Object.entries(labels).forEach(([key, label]) => {
  39. const state = getStates(key);
  40.  
  41. displayItems(key, state);
  42. GM_registerMenuCommand(`${state ? '✅' : '❌'} ${label}`, e => stateToggle(key, state), { id: key, autoClose: false });
  43. });
  44. }
  45. renderMenuCommands();
  46.  
  47. // States toggle
  48. function stateToggle(key, state) {
  49. const statesNew = getStates();
  50. statesNew[key] = !state;
  51. GM_setValue('states', statesNew);
  52. renderMenuCommands();
  53. }
  54.  
  55. // Display items
  56. function displayItems(key, state) {
  57. const body = document.body;
  58.  
  59. if (!state) {
  60. body.classList.add(key);
  61. } else {
  62. body.classList.remove(key);
  63. }
  64. }
  65.  
  66. // Get states
  67. function getStates(key) {
  68. const states = GM_getValue('states');
  69. const statesDefault = {
  70. home: true,
  71. shorts: true,
  72. subscriptions: true,
  73. you: true,
  74. yourChannel: true,
  75. history: true,
  76. playlists: true,
  77. yourVideos: true,
  78. watchLater: true,
  79. liked: true,
  80. download: true,
  81. };
  82.  
  83. if (key) return states?.[key] !== undefined ? states[key] : statesDefault[key];
  84. else return statesDefault;
  85. }
  86.  
  87. // Patch JSON.parse
  88. const originalParse = JSON.parse;
  89.  
  90. JSON.parse = function (text) {
  91. const result = originalParse(text);
  92. const item = result?.items?.[0]?.guideSectionRenderer?.items?.[3]?.guideCollapsibleSectionEntryRenderer?.sectionItems;
  93.  
  94. if (item) {
  95. item.forEach(item => {
  96. if (item.guideEntryRenderer) item.guideEntryRenderer.isPrimary = true;
  97. if (item.guideDownloadsEntryRenderer) item.guideDownloadsEntryRenderer.alwaysShow = true;
  98. });
  99. }
  100.  
  101. return result;
  102. };
  103.  
  104. // Styles
  105. GM_addStyle(`
  106. ytd-mini-guide-renderer.ytd-app {
  107. overflow: auto;
  108.  
  109. }
  110. .home ytd-mini-guide-entry-renderer:has(> a[href="/"]) {
  111. display: none !important;
  112. }
  113. .shorts ytd-mini-guide-entry-renderer:has(> a[title="Shorts"]) {
  114. display: none !important;
  115. }
  116. .subscriptions ytd-mini-guide-entry-renderer:has(> a[href="/feed/subscriptions"]) {
  117. display: none !important;
  118. }
  119. .you ytd-mini-guide-entry-renderer:has(> a[href="/feed/you"]) {
  120. display: none !important;
  121. }
  122. .yourChannel ytd-mini-guide-entry-renderer:has(> a[href^="/channel/"]) {
  123. display: none !important;
  124. }
  125. .history ytd-mini-guide-entry-renderer:has(> a[href="/feed/history"]) {
  126. display: none !important;
  127. }
  128. .playlists ytd-mini-guide-entry-renderer:has(> a[href="/feed/playlists"]) {
  129. display: none !important;
  130. }
  131. .yourVideos ytd-mini-guide-entry-renderer:has(> a[href^="https://studio.youtube.com/"]) {
  132. display: none !important;
  133. }
  134. .watchLater ytd-mini-guide-entry-renderer:has(> a[href="/playlist?list=WL"]) {
  135. display: none !important;
  136. }
  137. .liked ytd-mini-guide-entry-renderer:has(> a[href="/playlist?list=LL"]) {
  138. display: none !important;
  139. }
  140. .download ytd-mini-guide-entry-renderer:has(> a[href="/feed/downloads"]) {
  141. display: none !important;
  142. }
  143. `);