Youtube: Hide Recommended Videos

Hide the recommended videos section

  1. // ==UserScript==
  2. // @name Youtube: Hide Recommended Videos
  3. // @namespace https://github.com/Zren
  4. // @version 2
  5. // @description Hide the recommended videos section
  6. // @icon https://youtube.com/favicon.ico
  7. // @author Zren
  8. // @include http*://*.youtube.com/*
  9. // @include http*://youtube.com/*
  10. // @include http*://*.youtu.be/*
  11. // @include http*://youtu.be/*
  12. // @run-at document-start
  13. // ==/UserScript==
  14.  
  15. //--- Utils
  16. function observe(selector, config, callback) {
  17. var observer = new MutationObserver(function(mutations) {
  18. mutations.forEach(function(mutation){
  19. callback(mutation);
  20. });
  21. });
  22. var target = document.querySelector(selector);
  23. observer.observe(target, config);
  24. return observer;
  25. }
  26.  
  27. var documentLoaded = false;
  28. function tickUntilLoad(callback) {
  29. function tick() {
  30. callback();
  31. if (!documentLoaded) {
  32. window.requestAnimationFrame(tick);
  33. }
  34. }
  35. callback();
  36. window.requestAnimationFrame(tick);
  37. }
  38.  
  39. function watchBodyForChanged(callback) {
  40. callback();
  41. observe('body', {
  42. attributes: true,
  43. }, function(mutation) {
  44. if (mutation.attributeName === 'class') {
  45. callback();
  46. }
  47. });
  48. }
  49.  
  50. //---
  51. function getParent(e, selector) {
  52. var e2 = e.parentNode;
  53. while (e2) {
  54. if (e2.matches(selector)) {
  55. return e2;
  56. }
  57. e2 = e2.parentNode;
  58. }
  59. return null;
  60. }
  61.  
  62. function hideSection(url) {
  63. var a = document.querySelector('.shelf-title-row a[href="' + url + '"]');
  64. if (a) {
  65. var section = getParent(a, '.item-section');
  66. section.style.display = 'none';
  67. }
  68. }
  69.  
  70. function hideStuff() {
  71. hideSection("/feed/recommended");
  72. //hideSection("/feed/history"); // Watch it Again
  73. //hideSection("/user/IGNentertainment"); // IGN
  74. }
  75.  
  76. tickUntilLoad(hideStuff);
  77. document.addEventListener('DOMContentLoaded', function(){
  78. documentLoaded = true;
  79. hideStuff();
  80. watchBodyForChanged(hideStuff);
  81. });

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址