Peach Video AdBlock

Removes Pornhub ads while preserving floating Like/Favorite controls

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==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();
})();