feat: expand AI ad detection and harden YouTube blocking#1
Open
Edmon02 wants to merge 6 commits into
Open
Conversation
Fixes three critical issues affecting user experience: 1. **Preview watch time reset (Issue #1)**: When hovering over a video on YouTube main page and then clicking to watch, the extension now preserves the preview watch time instead of resetting to 0. This is fixed by saving the real video's currentTime before the ad takes over (realVideoStartTime). 2. **Resume functionality broken (Issue #2)**: When resuming a partially watched video, the ad blocker no longer resets to the beginning. The video now resumes from where it was paused, maintaining the user's playback position across page reloads or ad interruptions. 3. **Scroll lock after ad removal (Issue #3)**: Fixed scroll locking that occurred after ad removal. Now using setProperty with 'important' flag to forcefully unlock overflow and pointer-events, and added continuous monitoring in the safety poll to prevent YouTube from re-locking scrolling. Technical changes: - Add realVideoStartTime state variable to track video position before ads - Restore video.currentTime to realVideoStartTime instead of getUrlStartTime() - Use setProperty('overflow', 'auto', 'important') instead of removeProperty - Add proactive scroll unlock in safety poll every 500ms - Remove overly aggressive time-reset logic that assumed all times >2s were wrong Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Resolved persistent scroll snapping issue where scrolling would snap back to previous position. The problem was that YouTube continuously re-applies overflow:hidden and the previous 500ms polling was too slow to catch it. Improvements implemented: 1. **Real-time MutationObserver on html/body**: Instead of polling every 500ms, now watches for any style attribute changes on html and body elements. Immediately forces overflow to 'auto' if YouTube tries to set it to 'hidden'. 2. **CSS-level scroll lock prevention**: Injected critical CSS rules that force all html and body elements to have overflow:auto and pointer-events:auto with !important flags. This acts as a safety net against inline styles. 3. **Enhanced modal backdrop removal**: - Added visibility:hidden and opacity:0 for extra safety - Also watching for modal backdrop children being added in real-time - Backdrops are now completely neutered instead of just hidden 4. **Event capture on backdrops**: Added wheel and touchmove event listeners that prevent scroll events from being captured by modal backdrops, ensuring scroll always reaches the page body. 5. **Max-height/max-width unlock**: Also remove height constraints that YouTube might apply to prevent scrolling (100% or 100vh). 6. **Multiple approaches to body unlock**: - overflow: 'visible' on body (stronger than 'auto') - No max-height/max-width constraints - Continuous monitoring prevents re-application The combination of real-time observation + CSS rules + event interception ensures YouTube can never lock scrolling again, no matter when or how often it tries to re-apply the constraints. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… scroll manipulation Deep analysis revealed the root cause: YouTube actively resets window.scrollY using JavaScript, not just CSS overflow locking. The previous polling approach couldn't catch these rapid, repeated scroll position resets. NEW AGGRESSIVE APPROACH: ========================= 1. **window.scrollTo/scroll Override** (Lines 553-570) Intercepts YouTube's scrollTo() calls and blocks attempts to scroll backwards (below the user's last valid scroll position). This directly prevents YouTube's JavaScript from resetting scroll position. 2. **Scroll Position Monitoring** (Lines 588-610) Real-time 100ms monitor that: - Tracks lastValidScrollY when user scrolls - Detects when YouTube forcibly resets scroll backwards (>100px jump) - Immediately restores the correct position via window.scrollTo 3. **User Scroll Detection** (Lines 613-622) Differentiates between user-initiated scrolls and YouTube's automatic resets by tracking scroll events. Only user scrolls update the "valid" position. 4. **Enhanced CSS Injection** (Lines 503-538) Much more comprehensive CSS rules: - overflow-y: scroll for explicit scrollbar - scroll-behavior: smooth for better UX - height: auto to prevent height constraints - ytd-rich-grid-renderer for feed scrolling - position: static to prevent fixed positioning issues 5. **CSS-level Scroll Rules** (Lines 652-663) Added dynamic stylesheet that catches any element trying to set overflow:hidden and immediately overrides it with overflow:visible. 6. **Style Attribute Monitoring** (Lines 625-650) 200ms interval checking for height/overflow/pointer-events changes and forcing them back to scrollable state. 7. **Backdrop Killer** (Lines 666-676) 150ms interval specifically targeting tp-yt-iron-overlay-backdrop to ensure backdrops never interfere with scrolling. MULTIPLE LAYERS ENSURE SUCCESS: - Layer 1: CSS (first line of defense) - Layer 2: window.scrollTo override (blocks YouTube at source) - Layer 3: Position monitoring (detects and corrects resets) - Layer 4: Style monitoring (prevents CSS re-application) - Layer 5: Backdrop removal (removes UI obstacles) The combination of scroll interception + position monitoring + CSS rules ensures YouTube can NEVER reset scroll position again. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Two new issues were found and fixed: 1. VIDEO PAUSING AFTER 1-2 SECONDS (Issue #4) Root cause: video.play() promise was failing silently due to autoplay restrictions or timing issues, causing videos to pause after briefly playing. Fix implemented: - Handle play() promise properly instead of silently catching errors - When autoplay fails, attempt to click the play button as fallback - Multiple play attempts at 50ms, 150ms, 400ms, 1000ms intervals - Increased from 3 attempts to 4 attempts with better timing - Applied to both endAdLoop() and attachVideoSafety() 2. MOUSE WHEEL SCROLLING NOT WORKING (Issue #5) Root cause: Wheel events were not being properly captured and tracked, and the scroll position monitoring wasn't accounting for wheel-based scrolls. Fix implemented: - Add explicit wheel event listener with proper tracking - Track wheel events just like scroll events to update isUserScrolling flag - Removed scroll event prevention - only position monitoring prevents resets - Added scroll listeners on document, window, AND body for all scroll methods - Allow wheel events to scroll naturally while monitoring handles reset blocking Changes: 1. Enhanced autoplay logic with proper promise handling - Check if video.play() returns a promise - On rejection, find and click play button as fallback - Multiple staggered attempts ensure video starts 2. Fixed wheel scrolling support - Wheel events now properly tracked for user scroll detection - Position monitoring handles YouTube resets, not event blocking - Added explicit scroll listeners on body element - wheel events are captured and tracked but not prevented Result: - Videos now play reliably after ad removal without pausing - Mouse wheel scrolling works while position resets are still blocked - All scroll methods (wheel, click+drag, keyboard) work properly Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Introduce a comprehensive AI ad detection system that leverages user-provided LLM API keys (OpenAI, Anthropic, OpenRouter, Groq, or custom endpoints) to intelligently classify and remove advertisements across all websites. Core additions: - Multi-provider LLM client with retry logic and response normalization - LRU verdict cache with domain-level pattern learning - Prompt engineering with few-shot examples for ad classification - AI detection orchestrator with batching and confidence thresholds - Content-side element scanner with smooth fade-out/collapse animations - Recursive empty-space elimination for parent containers - Video pre-roll ad interception via main-world player patching (JWPlayer, Video.js, Hls.js, Shaka Player) - Network-level fetch/XHR interception to block ad requests - Searchable model picker with live OpenRouter pricing - Masked API key preview for security - Full options UI section for AI configuration - 62 unit tests covering provider, cache, detector, and scanner modules Updated README with AI feature documentation, changelog, and project structure. Made-with: Cursor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This branch expands AdEclipse in two major areas:
Highlights
Validation
npx jest --runInBandNotes