YouTube Ads and Pop-ups Remover

Removes ads and pop-ups from YouTube for a better viewing experience.

当前为 2024-02-23 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube Ads and Pop-ups Remover
  3. // @namespace http://samuelaraujo.pt
  4. // @version 1.0
  5. // @license MIT
  6. // @description Removes ads and pop-ups from YouTube for a better viewing experience.
  7. // @author Your Name
  8. // @match https://www.youtube.com/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Remove video advertisements
  16. function removeVideoAds() {
  17. const ads = document.querySelectorAll('.ad-showing');
  18. ads.forEach(ad => ad.remove());
  19. }
  20.  
  21. // Remove pop-ups
  22. function removePopups() {
  23. const popups = document.querySelectorAll('.style-scope ytd-enforcement-message-view-model');
  24. popups.forEach(popup => popup.remove());
  25. }
  26.  
  27. // Remove page advertisements
  28. function removePageAds() {
  29. const pageAds = document.querySelectorAll('.style-scope.ytd-display-ad-renderer');
  30. pageAds.forEach(ad => ad.remove());
  31. }
  32.  
  33. // Check if the page is YouTube
  34. if (window.location.hostname === 'www.youtube.com') {
  35. // Remove ads and pop-ups when the DOM is ready
  36. document.addEventListener('DOMContentLoaded', function() {
  37. removeVideoAds();
  38. removePopups();
  39. removePageAds();
  40. });
  41. }
  42. })();