Bye Bye YouTube Ads - (Undetected by YouTube's anti-AdBlocker)

Fastest + Lightest YouTube AdBlocker which actually works

当前为 2025-05-09 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Bye Bye YouTube Ads - (Undetected by YouTube's anti-AdBlocker)
  3. // @version 2.0
  4. // @description Fastest + Lightest YouTube AdBlocker which actually works
  5. // @author DishantX
  6. // @match *://www.youtube.com/*
  7. // @exclude *://www.youtube.com/*/music*
  8. // @exclude *://music.youtube.com/*
  9. // @exclude *://m.youtube.com/*
  10. // @icon https://tenor.com/view/manifest-meditate-pepe-gif-12464108004541162266
  11. // @icon64 https://tenor.com/view/manifest-meditate-pepe-gif-12464108004541162266
  12. // @license MIT
  13. // @namespace https://greasyfork.org/users/1467023
  14. // ==/UserScript==
  15.  
  16. (() => {
  17. 'use strict';
  18.  
  19. // 1. Inject only ad-overlay CSS (no panel removals).
  20. const style = document.createElement('style');
  21. style.textContent = [
  22. '.ytp-ad-overlay.ytp-overlay-loading', // in-video overlays
  23. '.ytp-featured-product' // featured product promos
  24. ].join(',') + ' { display: none !important; }';
  25. document.head.appendChild(style);
  26.  
  27. // 2. Click “Skip Ad” when it appears
  28. function clickSkip() {
  29. const btn = document.querySelector('button.ytp-ad-skip-button, button.ytp-ad-skip-button-modern');
  30. if (btn) btn.click();
  31. return !!btn;
  32. }
  33.  
  34. // 3. Jump past unskippable ads
  35. function jumpAd() {
  36. const v = document.querySelector('video');
  37. if (v && isFinite(v.duration)) v.currentTime = v.duration;
  38. }
  39.  
  40. // 4. Observe only the player’s 'ad-showing' class
  41. const player = document.getElementById('movie_player');
  42. if (player) {
  43. const obs = new MutationObserver(muts => {
  44. if (player.classList.contains('ad-showing')) {
  45. if (!clickSkip()) jumpAd();
  46. }
  47. });
  48. obs.observe(player, { attributes: true, attributeFilter: ['class'] });
  49. }
  50. })();