Removes Pornhub ads while preserving floating Like/Favorite controls
// ==UserScript==
// @name Peach Video AdBlock
// @namespace com.local.peach
// @version 1.0.1
// @description Removes Pornhub ads while preserving floating Like/Favorite controls
// @author Peach
// @match *://pornhub.com/*
// @match *://*.pornhub.com/*
// @match *://pornhubpremium.com/*
// @match *://*.pornhubpremium.com/*
// @run-at document-start
// @grant none
// @license MIT
// ==/UserScript==
(function () {
'use strict';
const EMPTY_SELECTOR = 'div.clearfix.noBottom';
const HIDE_ONLY_SELECTOR = '.abovePlayerButtonsWrapper,.ctasActionMenuWrap';
const HIDE_ONLY_SELECTORS = [
'.abovePlayerButtonsWrapper',
'.ctasActionMenuWrap'
];
const CLEANUP_SELECTORS = [
'.ad-tabSplit',
'.watchpageAd',
'.removeCTABtn',
'iframe[data-spot-id="981"]',
'iframe[data-spot-id="985"]',
'.adsRemoveButtonWrapper',
'.adsRemoveButton',
'.videoAdWrapper',
'.video-ad-container',
'.video-ad-overlay',
'.adOverlay',
'.bottomNav',
'.bottomNav a[data-event="header_paid_tabs"]',
'.bottomNav .js-liveCam',
'.tjLinksWrapper',
'.tj-inban-icon',
'a[href*="trafficjunky.com"]',
'a.eudsaLink[href*="tabinfo"]',
'.stickyTooltipWrapper',
'#mobileHeader',
'#tabFilters',
'.js-mainFooter'
];
function addEarlyStyle() {
if (document.getElementById('peach-video-adblock-style')) {
return;
}
const style = document.createElement('style');
style.id = 'peach-video-adblock-style';
style.textContent = CLEANUP_SELECTORS.concat(HIDE_ONLY_SELECTORS).join(',') + '{display:none!important;}';
(document.head || document.documentElement).appendChild(style);
}
function removeElement(element) {
try {
if (element && element.matches(HIDE_ONLY_SELECTOR)) {
return;
}
} catch (_) {}
if (element && element.parentNode) {
element.parentNode.removeChild(element);
}
}
function cleanEmpty(root = document) {
try {
root.querySelectorAll(EMPTY_SELECTOR).forEach(element => {
if (element.matches(HIDE_ONLY_SELECTOR)) {
return;
}
if (!element.textContent.trim() && element.children.length === 0) {
removeElement(element);
}
});
} catch (_) {}
}
function isAdIframe(iframe) {
if (!iframe || iframe.tagName !== 'IFRAME') {
return false;
}
const spotId = iframe.getAttribute('data-spot-id') || '';
const src = iframe.getAttribute('src') || '';
const srcdoc = iframe.getAttribute('srcdoc') || '';
return (
spotId === '981' ||
spotId === '985' ||
/trafficjunky/i.test(src) ||
/trafficjunky|deep_click|ad delivery system/i.test(srcdoc)
);
}
function clean(root = document) {
if (!root || !root.querySelectorAll) {
return;
}
for (const selector of CLEANUP_SELECTORS) {
try {
root.querySelectorAll(selector).forEach(removeElement);
} catch (_) {}
}
try {
root.querySelectorAll('iframe').forEach(iframe => {
if (isAdIframe(iframe)) {
removeElement(iframe);
}
});
} catch (_) {}
}
function cleanNode(node) {
if (!node || node.nodeType !== Node.ELEMENT_NODE) {
return;
}
try {
if (node.matches(HIDE_ONLY_SELECTOR)) {
return;
}
} catch (_) {}
for (const selector of CLEANUP_SELECTORS) {
try {
if (node.matches(selector)) {
removeElement(node);
return;
}
} catch (_) {}
}
if (node.tagName === 'IFRAME' && isAdIframe(node)) {
removeElement(node);
return;
}
clean(node);
cleanEmpty(node);
try {
if (
node.matches(EMPTY_SELECTOR) &&
!node.textContent.trim() &&
node.children.length === 0
) {
removeElement(node);
}
} catch (_) {}
}
function start() {
if (!document.documentElement) {
setTimeout(start, 5);
return;
}
addEarlyStyle();
clean();
cleanEmpty();
const observer = new MutationObserver(mutations => {
for (const mutation of mutations) {
for (const node of mutation.addedNodes) {
cleanNode(node);
}
}
});
observer.observe(document.documentElement, {
childList: true,
subtree: true
});
setInterval(() => {
clean();
cleanEmpty();
}, 1500);
}
start();
})();