YouTube Focus Mode

Put YouTube in focus mode! Hides all unasked for content (recommendations, subscriptions, related, etc.) on the home, watch, and search results pages.

  1. // ==UserScript==
  2. // @name YouTube Focus Mode
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.6
  5. // @description Put YouTube in focus mode! Hides all unasked for content (recommendations, subscriptions, related, etc.) on the home, watch, and search results pages.
  6. // @author EmeraldSlash
  7. // @match *://*.youtube.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // Controls which features are enabled, and which elements should be deleted
  15. const DELETE = {
  16. HOME_PAGE_FEED: true, // Video recommendations that show up on the home page
  17. WATCH_PAGE_RELATED: true, // Related videos displayed in a vertical list on the bottom right
  18. WATCH_PAGE_UP_NEXT: false, // Up next video
  19. VIDEO_VIDEOWALL: true, // Video recommendations that show up in a grid in the video display when a video finishes
  20. SEARCH_RESULTS_SHELVES: true, // Removes intrusive shelves in search results: "Shorts", "For you", "Previously watched", "People recently watched", etc.
  21. }
  22. const FOCUS_HOME_PAGE_SEARCH_BAR = true // Focus the home page search bar when visiting the page
  23.  
  24. // Selectors for each of the features and elements to be deleted
  25. const SELECTORS = {
  26. HOME_PAGE_FEED: ["[page-subtype='home']"],
  27. WATCH_PAGE_RELATED: ["#items > yt-related-chip-cloud-renderer", "#items > ytd-item-section-renderer", "#related > ytd-watch-next-secondary-results-renderer"],
  28. WATCH_PAGE_UP_NEXT: ["#items > ytd-compact-autoplay-renderer"],
  29. VIDEO_VIDEOWALL: [".ytp-endscreen-content"],
  30. SEARCH_RESULTS_SHELVES: ["ytd-reel-shelf-renderer", "ytd-shelf-renderer"],
  31. }
  32. const HOME_PAGE_SEARCH_BAR_SELECTOR = "input#search"
  33.  
  34. // import library for detecting added elements
  35. // insertion-query v1.0.3 (2016-01-20)
  36. // license:MIT
  37. // Zbyszek Tenerowicz <naugtur@gmail.com> (http://naugtur.pl/)
  38. var insertionQ=function(){"use strict";function a(a,b){var d,e="insQ_"+g++,f=function(a){(a.animationName===e||a[i]===e)&&(c(a.target)||b(a.target))};d=document.createElement("style"),d.innerHTML="@"+j+"keyframes "+e+" { from { outline: 1px solid transparent } to { outline: 0px solid transparent } }\n"+a+" { animation-duration: 0.001s; animation-name: "+e+"; "+j+"animation-duration: 0.001s; "+j+"animation-name: "+e+"; } ",document.head.appendChild(d);var h=setTimeout(function(){document.addEventListener("animationstart",f,!1),document.addEventListener("MSAnimationStart",f,!1),document.addEventListener("webkitAnimationStart",f,!1)},n.timeout);return{destroy:function(){clearTimeout(h),d&&(document.head.removeChild(d),d=null),document.removeEventListener("animationstart",f),document.removeEventListener("MSAnimationStart",f),document.removeEventListener("webkitAnimationStart",f)}}}function b(a){a.QinsQ=!0}function c(a){return n.strictlyNew&&a.QinsQ===!0}function d(a){return c(a.parentNode)?a:d(a.parentNode)}function e(a){for(b(a),a=a.firstChild;a;a=a.nextSibling)void 0!==a&&1===a.nodeType&&e(a)}function f(f,g){var h=[],i=function(){var a;return function(){clearTimeout(a),a=setTimeout(function(){h.forEach(e),g(h),h=[]},10)}}();return a(f,function(a){if(!c(a)){b(a);var e=d(a);h.indexOf(e)<0&&h.push(e),i()}})}var g=100,h=!1,i="animationName",j="",k="Webkit Moz O ms Khtml".split(" "),l="",m=document.createElement("div"),n={strictlyNew:!0,timeout:20};if(m.style.animationName&&(h=!0),h===!1)for(var o=0;o<k.length;o++)if(void 0!==m.style[k[o]+"AnimationName"]){l=k[o],i=l+"AnimationName",j="-"+l.toLowerCase()+"-",h=!0;break}var p=function(b){return h&&b.match(/[^{}]/)?(n.strictlyNew&&e(document.body),{every:function(c){return a(b,c)},summary:function(a){return f(b,a)}}):!1};return p.config=function(a){for(var b in a)a.hasOwnProperty(b)&&(n[b]=a[b])},p}();
  39.  
  40. function update() {
  41. for (var key in DELETE) {
  42. if (DELETE[key]) {
  43. var sel = SELECTORS[key]
  44. var found = false
  45. sel.forEach(function(selector) {
  46. let result = document.querySelectorAll(selector);
  47. if (result.length > 0) {
  48. found = true;
  49. result.forEach(function(element) {
  50. element.remove();
  51. })
  52. }
  53. })
  54. if (FOCUS_HOME_PAGE_SEARCH_BAR && found && key == "HOME_PAGE_FEED") {
  55. let search = document.querySelector(HOME_PAGE_SEARCH_BAR_SELECTOR);
  56. if (search) {
  57. search.focus();
  58. }
  59. }
  60. }
  61. }
  62. }
  63.  
  64. // update when user navigates
  65. document.addEventListener('yt-navigate-finish', update);
  66.  
  67. // remove elements when they get added
  68. for (var key in DELETE) {
  69. if (DELETE[key]) {
  70. var sel = SELECTORS[key]
  71. sel.forEach(function(selector) {
  72. insertionQ(selector).every(function(element) {
  73. element.remove()
  74. })
  75. })
  76. }
  77. }
  78.  
  79. // call initial update
  80. update()
  81. })();

QingJ © 2025

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