☰

BoyfriendTV Mobile Cleaner

Removes ad blocks, promo widgets, and forces videos to open in the current tab without popups.

Terá de instalar uma extensão como Tampermonkey, Greasemonkey ou Violentmonkey para instalar este script.

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

Terá de instalar uma extensão como Tampermonkey ou Violentmonkey para instalar este script.

Terá de instalar uma extensão como Tampermonkey ou Userscripts para instalar este script.

Terá de instalar uma extensão como Tampermonkey para instalar este script.

Terá de instalar uma extensão de gestão de scripts de utilizador para instalar este script.

(Já tenho um gestor de scripts de utilizador, deixe-me instalá-lo!)

Terá de instalar uma extensão como Stylus para instalar este estilo.

Terá de instalar uma extensão como Stylus para instalar este estilo.

Terá de instalar uma extensão como Stylus para instalar este estilo.

Terá de instalar uma extensão de gestão de estilos de utilizador para instalar este estilo.

Terá de instalar uma extensão de gestão de estilos de utilizador para instalar este estilo.

Terá de instalar uma extensão de gestão de estilos de utilizador para instalar este estilo.

(Já tenho um gestor de estilos de utilizador, deixe-me instalá-lo!)

// ==UserScript==
// @name         BoyfriendTV Mobile Cleaner
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Removes ad blocks, promo widgets, and forces videos to open in the current tab without popups.
// @match        *://*.boyfriendtv.com/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    // Function to remove all identified ad elements
    const removeAds = () => {
        // A list of CSS selectors targeting the various ad types
        const adSelectors = [
            '.content-block.no-popup', // Original homepage ad blocks
            '#wgt-360',                // Specific ID for the FapHouse video widget
            '.wgt-container',          // Class for video widget containers
            'a.fh-line',               // The "GET ACCESS" text banner link
            '.info-wrap',              // The wrapper for sponsored text links and iframes
            '.zn-label'                // The tiny "Ad" indicator spans
        ];

        adSelectors.forEach(selector => {
            document.querySelectorAll(selector).forEach(ad => {
                // If the ad is the text banner link, remove its parent container to keep the DOM clean
                if (ad.classList.contains('fh-line') && ad.parentElement && ad.parentElement.tagName === 'DIV') {
                    ad.parentElement.remove();
                } else {
                    ad.remove();
                }
            });
        });
    };

    // Function to fix link behavior and prevent popups
    const fixLinks = () => {
        // 1. Remove the trigger class from the wrapper
        document.querySelectorAll('.js-pop').forEach(el => {
            el.classList.remove('js-pop');
        });

        // 2. Target the actual video links
        const videoLinks = document.querySelectorAll('a[href^="/videos/"]');
        videoLinks.forEach(link => {
            // Remove target="_blank" just in case the site injects it
            link.removeAttribute('target');

            // Intercept the click to guarantee standard navigation
            link.addEventListener('click', function(e) {
                e.preventDefault();
                e.stopPropagation(); // Stop the site's scripts from seeing this click
                window.location.href = this.href;
            }, true); // 'true' uses the capture phase, firing before other scripts
        });

        // Disable the global popunder variables defined in their inline scripts
        if (typeof window.popunder !== 'undefined') {
            window.popunder = null;
        }
        if (typeof window.videoPopunder !== 'undefined') {
            window.videoPopunder = null;
        }
    };

    // Main execution function
    const runCleanup = () => {
        removeAds();
        fixLinks();
    };

    // Run when the DOM is fully loaded
    window.addEventListener('DOMContentLoaded', runCleanup);

    // Set up a MutationObserver to catch elements loaded dynamically (like infinite scroll or delayed ad injections)
    const observer = new MutationObserver((mutations) => {
        let shouldRun = false;
        for (const mutation of mutations) {
            if (mutation.addedNodes.length > 0) {
                shouldRun = true;
                break;
            }
        }
        if (shouldRun) {
            runCleanup();
        }
    });

    // Start observing the body for injected nodes as soon as it exists
    const startObserver = setInterval(() => {
        if (document.body) {
            observer.observe(document.body, { childList: true, subtree: true });
            clearInterval(startObserver);
        }
    }, 50);

})();