☰

MissAV Ad Cleaner

Remove MissAV advertisements, iframes and popup ads.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴、Greasemonkey 油猴子 或 Violentmonkey 暴力猴,才能安装此脚本。

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴 或 Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴 或 Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

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

})();