Voxiom Adblocker

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);
})();