Voxiom Adblocker

Blocks ads, trackers, hidden/sandboxed external iframes, and Google vignette on voxiom.io

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Voxiom Adblocker
// @namespace    https://github.com/cqmbo1
// @version      1.1
// @description  Blocks ads, trackers, hidden/sandboxed external iframes, and Google vignette on voxiom.io
// @author       Cqmbo__
// @match        *://voxiom.io/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=voxiom.io
// @grant        none
// @run-at       document-start
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    const selectors = [
        '#voxiom-io_300X250_1',
        '#voxiom-io_970X250_1',
        'ad_unit',
        '#voxiom-io_300X250_3',
        '#voxiom-io_300X250_2',
        '#mys-wrapper',
        '.default-creative-container',
        '#voxiom-io_728x90_1',
        '#voxiom-io_728x90_2',
        '#voxiom-io_728x90_3',
        '#google_vignette'
    ];

    const isExternalSrc = (url) => {
        if (!url) return false;
        try {
            const u = new URL(url, location.href);
            const host = u.hostname;
            return host !== location.hostname && !host.endsWith('.' + location.hostname);
        } catch {
            return false;
        }
    };

    const hasTrackerHints = (url) => {
        if (!url) return false;
        return /(?:usync|isync|load-cookie|cs-config|headerbid|type=hb|pubcid|criteo|streamrail|yellowblue|sync|cookie)/i.test(url);
    };

    const isHiddenOrZero = (el) => {
        const style = el.getAttribute('style') || '';
        const w = el.getAttribute('width') || '';
        const h = el.getAttribute('height') || '';
        const zeroSize = (w === '0' && h === '0');
        const hiddenStyle = /display\s*:\s*none/i.test(style) ||
                            (/height\s*:\s*0(px)?/i.test(style) && /width\s*:\s*0(px)?/i.test(style));
        return zeroSize || hiddenStyle;
    };

    const isSandboxedScripts = (el) => {
        const sandbox = el.getAttribute('sandbox') || '';
        return /allow-scripts/i.test(sandbox);
    };

    const shouldBlockIframe = (iframe) => {
        const src = iframe.getAttribute('src') || '';
        return (isExternalSrc(src) && (isHiddenOrZero(iframe) || isSandboxedScripts(iframe))) || hasTrackerHints(src);
    };

    const adblocker = () => {
        document.querySelectorAll(selectors.join(',')).forEach(el => el.remove());

        document.querySelectorAll('iframe').forEach(iframe => {
            if (shouldBlockIframe(iframe)) iframe.remove();
        });

        document.querySelectorAll('#google_vignette').forEach(el => el.remove());

        if (location.href.includes('google_vignette')) {
            try { history.replaceState(null, '', location.href.replace(/[#&?]google_vignette(?:=[^&]*)?/i, '')); } catch {}
        }
    };

    const domObserver = new MutationObserver(() => adblocker());
    domObserver.observe(document.documentElement, { childList: true, subtree: true });

    adblocker();
    setInterval(adblocker, 1000);
})();