☰

BoyfriendTV Mobile Cleaner

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

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, Greasemonkey alebo Violentmonkey.

Na inštaláciu tohto skriptu budete musieť nainštalovať rozšírenie, ako je napríklad Tampermonkey alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey alebo Userscripts.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie správcu používateľských skriptov.

(Už mám správcu používateľských skriptov, nechajte ma ho nainštalovať!)

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

(Už mám správcu používateľských štýlov, nechajte ma ho nainštalovať!)

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

})();