Greasy Fork

Greasy Fork is available in English.

[🔍Bypass Age & Anti-Detected🔒] AdGuard For YouTube - YouTube 广告拦截器

[🔍Bypass Age & Anti-Detected🔒] AdGuard For YouTube屏蔽所有YouTube广告,让您无需干扰、快速且私密地观看视频。

// ==UserScript==
// @name:zh-CN      [🔍Bypass Age & Anti-Detected🔒] AdGuard For YouTube - YouTube 广告拦截器
// @name:es        [🔍Bypass Age & Anti-Detected🔒] AdGuard For YouTube - Bloqueador de Anuncios de YouTube
// @name:hi        [🔍Bypass Age & Anti-Detected🔒] AdGuard For YouTube - YouTube विज्ञापन ब्लॉकर
// @name           [🔍Bypass Age & Anti-Detected🔒] AdGuard For YouTube
// @name:vi        [🔍Bypass Age & Anti-Detected🔒] AdGuard For YouTube - Công cụ bỏ qua quảng cáo
// @namespace      https://twisk.com
// @version        1.1.2
// @description:zh-CN   [🔍Bypass Age & Anti-Detected🔒] AdGuard For YouTube屏蔽所有YouTube广告,让您无需干扰、快速且私密地观看视频。
// @description:es       [🔍Bypass Age & Anti-Detected🔒] AdGuard For YouTube bloquea todos los anuncios de YouTube, permitiéndote ver videos sin interrupciones y de forma privada.
// @description:hi       [🔍Bypass Age & Anti-Detected🔒] AdGuard For YouTube सभी YouTube विज्ञापनों को ब्लॉक करता है, जिससे आप बिना रुकावट, तेज़ और निजी तरीके से वीडियो देख सकते हैं।
// @description         [🔍Bypass Age & Anti-Detected🔒] AdGuard For YouTube blocks all YouTube ads, letting you watch videos uninterrupted, faster, and privately for a smooth, ad-free viewing experience, boost your FPS while streaming videos.
// @description:vi      [🔍Bypass Age & Anti-Detected🔒] AdGuard For YouTube chặn tất cả YouTube quảng cáo, tạo trải nghiệm xem video nhanh hơn, bảo mật hơn, không quảng cáo.
// @author             airpl4ne
// @author w_irylis
// @icon               https://i.ibb.co/k6kVh2wf/Untitled-design.png
// @match              https://www.youtube.com/*
// @match              https://m.youtube.com/*
// @grant              none
// @license            MIT
// @noframes
// ==/UserScript==

// 💲Free Adblocker API at our Discord : https://discord.gg/Gvmd7deFtS
// 💦Free-To-Use , No Money Cost !


(function() {
    'use strict';

    let adBlockCount = 0;

    // Enhanced CSS with modern UI
    function applyEnhancedStyles() {
        const style = document.createElement('style');
        style.textContent = `
            /* Enhanced notification styling with animations */
            .nextshield-notification {
                position: fixed;
                top: 20px;
                right: 20px;
                padding: 16px 24px;
                background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
                color: #fff;
                border-radius: 12px;
                box-shadow: 0 8px 32px rgba(31, 38, 135, 0.37);
                backdrop-filter: blur(8px);
                border: 1px solid rgba(255, 255, 255, 0.18);
                z-index: 10000;
                font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
                font-size: 14px;
                font-weight: 500;
                opacity: 0;
                transform: translateX(100%) scale(0.9);
                transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
                min-width: 280px;
                max-width: 400px;
            }

            .nextshield-notification.show {
                opacity: 1;
                transform: translateX(0) scale(1);
            }

            .nextshield-notification.ad-blocked {
                background: linear-gradient(135deg, #ff6b6b 0%, #ee5a52 100%);
            }

            .nextshield-notification.success {
                background: linear-gradient(135deg, #51cf66 0%, #40c057 100%);
            }

            .nextshield-notification.info {
                background: linear-gradient(135deg, #339af0 0%, #228be6 100%);
            }

            .nextshield-notification::before {
                content: '';
                position: absolute;
                left: 0;
                top: 0;
                height: 100%;
                width: 4px;
                background: rgba(255, 255, 255, 0.8);
                border-radius: 12px 0 0 12px;
            }

            /* Ad block counter */
            .nextshield-counter {
                position: fixed;
                bottom: 20px;
                right: 20px;
                padding: 12px 20px;
                background: rgba(0, 0, 0, 0.8);
                color: #fff;
                border-radius: 25px;
                font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
                font-size: 12px;
                font-weight: 600;
                z-index: 9999;
                backdrop-filter: blur(10px);
                border: 1px solid rgba(255, 255, 255, 0.1);
                opacity: 0;
                transform: translateY(100%);
                transition: all 0.3s ease;
                display: flex;
                align-items: center;
                gap: 8px;
            }

            .nextshield-counter.show {
                opacity: 1;
                transform: translateY(0);
            }

            .nextshield-counter::before {
                content: '🛡️';
                font-size: 16px;
            }

            /* Notification icons */
            .notification-icon {
                display: inline-block;
                margin-right: 8px;
                font-size: 16px;
            }

            /* Progress bar for notifications */
            .notification-progress {
                position: absolute;
                bottom: 0;
                left: 0;
                height: 3px;
                background: rgba(255, 255, 255, 0.3);
                border-radius: 0 0 12px 12px;
                animation: progressBar 3s linear forwards;
            }

            @keyframes progressBar {
                from { width: 100%; }
                to { width: 0%; }
            }

            /* Pulse effect for ad blocks */
            .nextshield-notification.pulse {
                animation: pulse 0.6s ease-in-out;
            }

            @keyframes pulse {
                0%, 100% { transform: translateX(0) scale(1); }
                50% { transform: translateX(0) scale(1.05); }
            }
        `;
        document.head.appendChild(style);
    }

    // Enhanced notification system
    function showEnhancedNotification(message, type = 'info', duration = 3000) {
        const notification = document.createElement('div');
        notification.className = `nextshield-notification ${type}`;

        const icons = {
            'ad-blocked': '🚫',
            'success': '✅',
            'info': 'ℹ️',
            'warning': '⚠️'
        };

        notification.innerHTML = `
            <span class="notification-icon">${icons[type] || icons.info}</span>
            ${message}
            <div class="notification-progress"></div>
        `;

        document.body.appendChild(notification);

        // Show animation
        setTimeout(() => {
            notification.classList.add('show');
            if (type === 'ad-blocked') {
                notification.classList.add('pulse');
                updateAdCounter();
            }
        }, 100);

        // Hide animation
        setTimeout(() => {
            notification.classList.remove('show');
            setTimeout(() => notification.remove(), 400);
        }, duration);
    }

    // Ad counter system
    function updateAdCounter() {
        adBlockCount++;

        let counter = document.querySelector('.nextshield-counter');
        if (!counter) {
            counter = document.createElement('div');
            counter.className = 'nextshield-counter';
            document.body.appendChild(counter);
        }

        counter.textContent = `${adBlockCount} ads blocked`;
        counter.classList.add('show');

        // Hide counter after 5 seconds of inactivity
        clearTimeout(window.counterTimeout);
        window.counterTimeout = setTimeout(() => {
            counter.classList.remove('show');
        }, 5000);
    }

    // boost your video fps
    function enhanceVideoQuality() {
        const player = document.querySelector('video');
        if (!player || player.dataset.qualityEnhanced) return;

        // Access YouTube player API
        const ytPlayer = document.querySelector('#movie_player');
        if (!ytPlayer || !ytPlayer.getAvailableQualityLevels) return;

        // Mark as enhanced to prevent repeated attempts
        player.dataset.qualityEnhanced = 'true';

        // Get available quality levels
        const qualities = ytPlayer.getAvailableQualityLevels();
        // Prioritize highest quality (e.g., 'hd2160' for 4K, 'hd1080' for 1080p)
        const preferredQualities = ['hd2160', 'hd1440', 'hd1080', 'hd720', 'large', 'medium', 'small'];
        let selectedQuality = null;

        for (const quality of preferredQualities) {
            if (qualities.includes(quality)) {
                selectedQuality = quality;
                break;
            }
        }

        if (selectedQuality) {
            ytPlayer.setPlaybackQualityRange(selectedQuality);
            showEnhancedNotification(`Video quality set to ${selectedQuality}!`, 'success');
        } else {
            showEnhancedNotification('No higher quality available.', 'info');
        }

        // Attempt to prioritize high FPS (e.g., 60fps) by checking available streams
        // Note: YouTube's API doesn't directly expose FPS, so we infer from quality labels
        const playbackData = ytPlayer.getVideoData();
        if (playbackData && playbackData.isLive) {
            showEnhancedNotification('Live stream detected; FPS optimization skipped.', 'info');
            return;
        }

        // Re-check available qualities after setting to ensure high FPS
        const qualityLabels = ytPlayer.getAvailableQualityLevels();
        const highFpsQuality = qualityLabels.find(q => q.includes('1080p60') || q.includes('720p60'));
        if (highFpsQuality && highFpsQuality !== selectedQuality) {
            ytPlayer.setPlaybackQualityRange(highFpsQuality);
            showEnhancedNotification(`Switched to ${highFpsQuality} for higher FPS!`, 'success');
        }
    }

    // Ad-blocking functions with enhanced notifications
    function removeAntiAdblockPopup() {
        document.querySelectorAll('tp-yt-paper-dialog').forEach(dlg => {
            const isAdblockWarning =
                dlg.querySelector('a[href*="support.google.com"]') ||
                /adblock|allow\s*ads|blocker/i.test(dlg.innerText);

            if (isAdblockWarning) {
                console.log("[NextShield] Anti-adblock popup detected → removing.");
                dlg.remove();
                document.body.style.overflow = "auto";
                showEnhancedNotification('Anti-adblock popup blocked!', 'ad-blocked');
            }
        });

        const backdrop = document.querySelector('tp-yt-iron-overlay-backdrop.opened');
        if (backdrop) {
            backdrop.remove();
            document.body.style.overflow = "auto";
        }
    }

    function bypassAgeRestriction() {
        const ageDialog = document.querySelector('ytd-enforcement-message-view-model');
        const player = document.querySelector('video');

        if (ageDialog) {
            ageDialog.remove();
            showEnhancedNotification('Age restriction bypassed!', 'success');
        }

        if (player && player.paused && player.readyState === 0) {
            const isAgeBlocked = !!document.querySelector('ytd-player .ytd-watch-flexy[ad-blocked]');
            const videoId = new URLSearchParams(window.location.search).get('v');
            if (isAgeBlocked && videoId) {
                window.location.href = `https://www.youtube-nocookie.com/embed/${videoId}?autoplay=1`;
            }
        }
    }

    function skipAds() {
        const pipMode = document.querySelector('ytd-pip-container, ytd-miniplayer-player-container');
        const adVideo = document.querySelector('.ad-showing video');
        if (adVideo && adVideo.duration) {
            adVideo.currentTime = adVideo.duration;
            adVideo.muted = true;
            showEnhancedNotification('Video ad skipped instantly!', 'ad-blocked');
        }
        const skipBtn = document.querySelector('.ytp-ad-skip-button, .ytp-ad-skip-button-modern');
        if (skipBtn) {
            skipBtn.click();
            showEnhancedNotification('Skip button clicked!', 'ad-blocked');
        }

        if (document.querySelector('.ad-showing')) {
            setTimeout(skipAds, 500);
        }
    }

    function removeAdBanners() {
        const selectors = [
            '#player-ads', '#masthead-ad', '.ytp-ad-overlay-container',
            '.ytp-ad-image-overlay', '.yt-mealbar-promo-renderer',
            '.ytp-featured-product', 'ytd-merch-shelf-renderer', 'ytd-in-feed-ad-layout-renderer',
            'ytd-engagement-panel-section-list-renderer'
        ];

        let removedCount = 0;
        selectors.forEach(sel => {
            const elements = document.querySelectorAll(sel);
            elements.forEach(el => {
                el.remove();
                removedCount++;
            });
        });

        if (removedCount > 0) {
            showEnhancedNotification(`${removedCount} ad banner${removedCount > 1 ? 's' : ''} removed!`, 'ad-blocked');
        }
    }

    function keepVideoPlayingEarly() {
        const video = document.querySelector('video');
        if (!video || video.dataset.keepPlayingEarly) return;

        video.dataset.keepPlayingEarly = "true";

        const onPause = () => {
            if (video.currentTime <= 5) {
                video.play().then(() => {
                    showEnhancedNotification('Video auto-resumed!', 'success');
                }).catch(err => {
                    console.warn("[NextShield] Could not auto-play:", err);
                });
            }
        };
        video.removeEventListener('pause', onPause);
        video.addEventListener('pause', onPause);
    }

    // Initialize functionality
    applyEnhancedStyles();

    // Show welcome message
    setTimeout(() => {
        showEnhancedNotification('NextShield activated! Ad-blocking enabled.', 'success', 2000);
    }, 1000);

    let debounceTimeout;
    const observer = new MutationObserver(() => {
        clearTimeout(debounceTimeout);
        debounceTimeout = setTimeout(() => {
            removeAntiAdblockPopup();
            bypassAgeRestriction();
            skipAds();
            removeAdBanners();
            keepVideoPlayingEarly();
            enhanceVideoQuality();
        }, 50); // Faster response time
    });

    observer.observe(document.body, { childList: true, subtree: true, attributes: true });

    // Initial execution
    removeAntiAdblockPopup();
    bypassAgeRestriction();
    skipAds();
    removeAdBanners();
    keepVideoPlayingEarly();

    // Additional interval for persistent ad blocking
    setInterval(() => {
        removeAntiAdblockPopup();
        skipAds();
        removeAdBanners();
    }, 500);
})();