Remove Ads and Block Popups on mkvcinemas

Removes ads, prevents popups, and blocks unwanted redirects on mkvcinemas

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Remove Ads and Block Popups on mkvcinemas
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Removes ads, prevents popups, and blocks unwanted redirects on mkvcinemas
// @author       Hasan-Abbas
// @match        https://mkvcinemas.*/** 
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    // A function to remove an element if it exists
    function removeElement(selector) {
        const elements = document.querySelectorAll(selector);
        elements.forEach(el => el.remove());
    }

    // Common ad-related selectors (you can expand this list based on observation)
    const adSelectors = [
        '#ad',  // Common ID for ads
        '.ads',  // Common class for ads
        '.ad-banner',  // Specific ad banners
        '.advertisement',  // Another common class
        '.popup',  // Popups
        '.video-ad',  // Video ads
        '.banner',  // Banner ads
        'iframe[src*="ads"]',  // Iframes often contain ads
        '[id*="ad"]',  // IDs that contain 'ad'
        '[class*="ad"]',  // Classes that contain 'ad'
        '[style*="display: none"]',  // Some hidden ad elements
        '.cookie-popup', // Cookie consent popups (can be ad related)
    ];

    // Run remove for each selector
    adSelectors.forEach(selector => removeElement(selector));

    // Block unwanted popups (opening new tabs or windows)
    const originalWindowOpen = window.open;
    window.open = function (url, name, specs) {
        // Prevent window.open from opening new tabs/windows (can be refined further if necessary)
        console.log("Blocked popup attempt:", url);
        return null;
    };

    // Disable links that lead to external downloads or app redirects
    const links = document.querySelectorAll('a[href*="telegram"], a[href*="download"]');
    links.forEach(link => {
        link.addEventListener('click', (e) => {
            e.preventDefault();
            console.log('Blocked redirect to', link.href);
        });
    });

    // Handle redirects by listening for location change or hijacked URLs
    const originalLocation = window.location.href;
    setInterval(() => {
        if (window.location.href !== originalLocation) {
            window.location.href = originalLocation;  // Redirect back to original page
        }
    }, 1000);

    // You might want to listen for dynamic content loading (like more ads appearing via JS)
    // If necessary, use MutationObserver to catch these dynamically loaded elements
    const observer = new MutationObserver(() => {
        adSelectors.forEach(selector => removeElement(selector));
    });

    observer.observe(document.body, { childList: true, subtree: true });

})();