Hide Pornhub Age Disclaimer

Hides overlays after load, stops polling/observer once hidden

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Hide Pornhub Age Disclaimer
// @namespace    https://github.com/danmaclann
// @version      1.04
// @license      MIT
// @description  Hides overlays after load, stops polling/observer once hidden
// @author       danmaclann
// @match        https://*.pornhub.com/*
// @grant        none
// @run-at       document-start
// @icon         https://ei.phncdn.com/www-static/favicon.ico
// ==/UserScript==

(function() {
    'use strict';

    // Block modal immediately visually so it never flashes on screen
    const style = document.createElement('style');
    style.textContent = `
        #modalWrapMTubes,
        #ageDisclaimerMainBG {
            display: none !important;
        }
        #modalWrapMTubes *,
        #ageDisclaimerMainBG * {
            display: none !important;
        }
    `;
    (document.head || document.documentElement).appendChild(style);

    console.log('Pornhub age gate blocker injected');

    function autoConfirm() {
        // Target the exact Enter button from your HTML
        const enterBtn = document.querySelector('.gtm-event-age-verification.js-closeAgeModal.buttonOver18[data-label="over18_enter"]') ||
                        document.querySelector('button[data-label="over18_exit"]') ||
                        document.querySelector('#modalWrapMTubes button');

        if (enterBtn) {
            // Hide modal
            const modal = document.getElementById('modalWrapMTubes');
            if (modal) {
                modal.remove();
                console.log('Modal removed via button check');
            }
            return true;
        }

        const modal = document.getElementById('modalWrapMTubes');
        if (modal) {
            modal.remove();
            console.log('Modal removed directly');
            return true;
        }

        return false;
    }

    // 1. Try immediately (in case the DOM is already ready)
    if (autoConfirm()) return;

    // 2. Poll aggressively while the page is loading
    const interval = setInterval(() => {
        if (autoConfirm()) {
            clearInterval(interval);
            console.log('Interval stopped.');
        }
    }, 50); // Every 50ms

    // Failsafe: Stop polling after 10 seconds to prevent infinite loops
    // if the user is already logged in and the modal never spawns.
    setTimeout(() => clearInterval(interval), 10000);

    // 3. Watch DOM changes for delayed React/Vue/AJAX injections
    const observer = new MutationObserver((mutations, obs) => {
        if (autoConfirm()) {
            obs.disconnect();
            console.log('Observer stopped. Script finished.');
        }
    });

    document.addEventListener('DOMContentLoaded', () => {
        // Only start observing the body once it actually exists
        observer.observe(document.body, { childList: true, subtree: true });
    });

})();