☰

MissAV Ad Cleaner

Remove MissAV advertisements, iframes and popup ads.

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

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

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

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

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

You will need to install a user script manager extension 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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         MissAV Ad Cleaner
// @namespace    http://tampermonkey.net/
// @version      1.1
// @author       ChatGPT
// @license      MIT
// @description  Remove MissAV advertisements, iframes and popup ads.
// @include      /^https?:\/\/missav[^/]*\//
// @run-at       document-start
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    const selector = 'iframe, #html-ads, #inpage, #SCSpotScript';

    // Block popup advertisements.
    const open = window.open;
    window.open = function (url, ...args) {
        try {
            const u = new URL(url, location.href);
            if (u.origin === location.origin &&
                u.pathname === '/pop' &&
                u.searchParams.has('url')) return null;
        } catch {}
        return open.call(this, url, ...args);
    };

    // Hide ad elements immediately.
    const style = document.createElement('style');
    style.textContent = `${selector} {
        display: none !important;
        visibility: hidden !important;
    }`;

    const clean = node => {
        if (node.nodeType !== 1 && node !== document) return;

        if (node.nodeType === 1 && node.matches(selector)) {
            node.remove();
            return;
        }

        node.querySelectorAll?.(selector).forEach(el => el.remove());
    };

    // Watch dynamically inserted elements.
    new MutationObserver(records => {
        if (document.documentElement && !style.isConnected) {
            document.documentElement.appendChild(style);
        }

        for (const record of records) {
            record.addedNodes.forEach(clean);
        }
    }).observe(document, {
        childList: true,
        subtree: true
    });

    // Initial cleanup.
    if (document.documentElement) {
        document.documentElement.appendChild(style);
    }
    clean(document);

})();