YouTube Branding Image Remover

Removes branding images (elements with class 'branding-img') from YouTube pages to provide a cleaner interface.

  1. // ==UserScript==
  2. // @name YouTube Branding Image Remover
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description Removes branding images (elements with class 'branding-img') from YouTube pages to provide a cleaner interface.
  6. // @author Your Name/AI
  7. // @match *://*.youtube.com/*
  8. // @grant none
  9. // @run-at document-end
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. function removeBrandingImages() {
  16. const images = document.querySelectorAll('img.branding-img');
  17. let imagesRemovedThisRun = 0;
  18.  
  19. images.forEach(img => {
  20. if (document.body.contains(img)) {
  21. img.remove();
  22. imagesRemovedThisRun++;
  23. }
  24. });
  25.  
  26. if (imagesRemovedThisRun > 0) {
  27. // console.log(`[YouTube Branding Image Remover] Removed ${imagesRemovedThisRun} branding image(s).`);
  28. }
  29. }
  30.  
  31. // Initial run
  32. removeBrandingImages();
  33.  
  34. // Observe DOM changes for dynamically loaded content
  35. const observer = new MutationObserver(function(mutationsList, observerInstance) {
  36. let potentiallyNewBrandingImages = false;
  37. for(const mutation of mutationsList) {
  38. if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
  39. for (const node of mutation.addedNodes) {
  40. if (node.nodeType === 1) {
  41. if (node.matches && node.matches('img.branding-img')) {
  42. potentiallyNewBrandingImages = true;
  43. break;
  44. }
  45. if (node.querySelector && node.querySelector('img.branding-img')) {
  46. potentiallyNewBrandingImages = true;
  47. break;
  48. }
  49. }
  50. }
  51. }
  52. if (potentiallyNewBrandingImages) break;
  53. }
  54.  
  55. if (potentiallyNewBrandingImages) {
  56. removeBrandingImages();
  57. }
  58. });
  59.  
  60. function startObserver() {
  61. if (document.body) {
  62. observer.observe(document.body, { childList: true, subtree: true });
  63. } else {
  64. document.addEventListener('DOMContentLoaded', function() {
  65. observer.observe(document.body, { childList: true, subtree: true });
  66. });
  67. }
  68. }
  69.  
  70. startObserver();
  71.  
  72. })();