Hide Youtube left sidebar items

Adds a list of check-boxes to the bottom-most of the left sidebar for toggling visibility. (items that can be hidden are: Explore, Subscriptions, Subscriptions list, Library, History, Your videos, Watch later, More from Youtube)

当前为 2021-07-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Hide Youtube left sidebar items
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description Adds a list of check-boxes to the bottom-most of the left sidebar for toggling visibility. (items that can be hidden are: Explore, Subscriptions, Subscriptions list, Library, History, Your videos, Watch later, More from Youtube)
  6. // @author babyrager
  7. // @icon https://www.google.com/s2/favicons?domain=greasyfork.org
  8. // @grant none
  9. // @include https://youtube.com/*
  10. // @include https://www.youtube.com/*
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. window.addEventListener("load", function(){
  17.  
  18. var namespace = 'hide-yt-stuff-';
  19. function clickHide(){
  20. var key = namespace+this.getAttribute('data-hide-yt-key');
  21. if(this.checked){
  22. localStorage.setItem(key, 'is_checked');
  23. hideStuff(this.getAttribute('data-hide-yt-key'), true);
  24. }else{
  25. localStorage.removeItem(key);
  26. hideStuff(this.getAttribute('data-hide-yt-key'), false);
  27. }
  28. }
  29.  
  30. function hideStuff(key, flag){
  31. var display_type = 'block';
  32. if(flag){
  33. display_type = 'none';
  34. }
  35. if(key == 'subscription'){
  36. document.querySelectorAll('a.yt-simple-endpoint').forEach(function(item){
  37. if(item.getAttribute('title') == 'Subscriptions'){
  38. item.style.display = display_type;
  39. }
  40. });
  41. }
  42. else if(key == 'subscription-list'){
  43. document.querySelectorAll('yt-formatted-string.ytd-guide-section-renderer').forEach(function(item){
  44. if(item.innerHTML.toLowerCase().trim() == 'subscriptions'){
  45. item.parentNode.parentNode.style.display = display_type;
  46. }
  47. });
  48. }
  49. else if(key == 'explore'){
  50. document.querySelectorAll('a.yt-simple-endpoint').forEach(function(item){
  51. if(item.getAttribute('title') == 'Explore'){
  52. item.style.display = display_type;
  53. }
  54. });
  55. }else if(key == 'library'){
  56. document.querySelectorAll('a.yt-simple-endpoint').forEach(function(item){
  57. if(item.getAttribute('title') == 'Library'){
  58. item.style.display = display_type;
  59. }
  60. });
  61. }else if(key == 'history'){
  62. document.querySelectorAll('a.yt-simple-endpoint').forEach(function(item){
  63. if(item.getAttribute('title') == 'History'){
  64. item.style.display = display_type;
  65. }
  66. });
  67. }
  68. else if(key == 'your-videos'){
  69. document.querySelectorAll('a.yt-simple-endpoint').forEach(function(item){
  70. if(item.getAttribute('title') == 'Your videos'){
  71. item.style.display = display_type;
  72. }
  73. });
  74. }else if(key == 'watch-later'){
  75. document.querySelectorAll('a.yt-simple-endpoint').forEach(function(item){
  76. if(item.getAttribute('title') == 'Watch later'){
  77. item.style.display = display_type;
  78. }
  79. });
  80. }else if(key == 'liked-videos'){
  81. //doesn't work if it is hidden in the menu on page load, comment if you came up with a fix
  82.  
  83. /*document.querySelectorAll('a.yt-simple-endpoint').forEach(function(item){
  84. if(item.getAttribute('title') == 'Liked videos'){
  85. item.style.display = display_type;
  86. }
  87. });*/
  88. }else if(key == 'more-from-youtube'){
  89. setTimeout(function(){
  90. document.querySelectorAll('yt-formatted-string.ytd-guide-section-renderer').forEach(function(item){
  91. if(item.innerHTML.toLowerCase().trim() == 'more from youtube'){
  92. item.parentNode.parentNode.style.display = display_type;
  93. }
  94. });
  95. },100);
  96. }
  97. }
  98.  
  99. var obj = document.createElement('div');
  100. var str = '<div>';
  101. obj.innerHTML += '<div style="margin-left:20px;display:flex;align-items:center"><input type="checkbox" data-hide-yt-key="subscription">Hide subscription</div>';
  102. obj.innerHTML += '<div style="margin-left:20px;display:flex;align-items:center"><input type="checkbox" data-hide-yt-key="subscription-list">Hide subscription list</div>';
  103. obj.innerHTML += '<div style="margin-left:20px;display:flex;align-items:center"><input type="checkbox" data-hide-yt-key="explore">Hide explore</div>';
  104. obj.innerHTML += '<div style="margin-left:20px;display:flex;align-items:center"><input type="checkbox" data-hide-yt-key="library">Hide library</div>';
  105. obj.innerHTML += '<div style="margin-left:20px;display:flex;align-items:center"><input type="checkbox" data-hide-yt-key="history">Hide history</div>';
  106. obj.innerHTML += '<div style="margin-left:20px;display:flex;align-items:center"><input type="checkbox" data-hide-yt-key="your-videos">Hide your videos</div>';
  107. obj.innerHTML += '<div style="margin-left:20px;display:flex;align-items:center"><input type="checkbox" data-hide-yt-key="watch-later">Hide watch later</div>';
  108. //obj.innerHTML += '<div style="margin-left:20px;display:flex;align-items:center"><input type="checkbox" data-hide-yt-key="liked-videos">Hide liked videos</div>';
  109. obj.innerHTML += '<div style="margin-left:20px;display:flex;align-items:center"><input type="checkbox" data-hide-yt-key="more-from-youtube">Hide more from youtube</div>';
  110. obj.innerHTML +='<div style="margin-bottom: 40px"></div>';
  111. str+='</div>';
  112.  
  113. document.querySelector('#footer').appendChild(obj);
  114. document.querySelectorAll('[data-hide-yt-key]').forEach(function(item){
  115. var key = namespace+item.getAttribute('data-hide-yt-key');
  116. if(localStorage.getItem(key) == 'is_checked'){
  117. item.checked = true;
  118. hideStuff(item.getAttribute('data-hide-yt-key'), true);
  119. }
  120. });
  121. document.querySelectorAll('[data-hide-yt-key]').forEach(function(item){
  122. item.addEventListener('change', clickHide);
  123. });
  124. });
  125. })();