Hides overlays after load, stops polling/observer once hidden
// ==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 });
});
})();