OP.GG 去广告

OP.GG去广告

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください。
// ==UserScript==
// @name         OP.GG 去广告
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  OP.GG去广告
// @author       Blazing
// @match        https://www.op.gg/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    const blockedUrlPatterns = [
        /.*\.googlesyndication\.com/,
        /.*\.gstatic\.com/,
        /.*\.t13\.io/,
        /.*\.adsafeprotected\.com/,
        /.*\.googletagmanager\.com/,
        /.*\.clean\.gg/,
        /.*\.google\.com/,
        /.*\.vntsm\.com/
    ];

    const isBlocked = (url) => blockedUrlPatterns.some(pattern => pattern.test(url));

    const originalFetch = window.fetch;
    window.fetch = function(...args) {
        if (isBlocked(args[0])) {
            console.log('Blocked request to:', args[0]);
            return Promise.reject(new Error('Blocked by userscript'));
        }
        return originalFetch.apply(this, args);
    };

    const originalXHR = window.XMLHttpRequest.prototype.open;
    window.XMLHttpRequest.prototype.open = function(method, url, ...rest) {
        if (isBlocked(url)) {
            console.log('Blocked request to:', url);
            return;
        }
        return originalXHR.apply(this, [method, url, ...rest]);
    };

    const classesToHide = [
        'premium-banner premium-banner--home css-1lzz9go evso9ty0',
        'css-1flley8 eetdkr15',
        'premium-banner__absolute-wrapper',
        'vm-skin vm-skin-left',
        'vm-skin vm-skin-right',
        'vm-footer-content',
        'css-187a9cv eetdkr10',
        'css-suuv7k eetdkr13',
        'css-8kcwtz eetdkr14',
        'vm-placement css-71yq36 eetdkr17',
        'eetdkr11',
        'eetdkr12',
        'trv-player-container',
        'ats-glia-wrapper',
    ];

    const hideElements = () => {
        classesToHide.forEach(className => {
            document.querySelectorAll(`.${className.split(' ').join('.')}`).forEach(el => {
                el.style.display = 'none';
            });
        });
    };

    hideElements();

    new MutationObserver(hideElements).observe(document.body, {
        childList: true,
        subtree: true
    });
})();