Fix Aternos Load Speed

Blocks the slow header-bidding script on Aternos.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Fix Aternos Load Speed
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Blocks the slow header-bidding script on Aternos.
// @author       Dax
// @match        https://aternos.org/server/
// @match        https://aternos.org/servers/
// @run-at       document-start
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    const targetDomain = 'hb.vntsm.com';

    const nativeCreateElement = document.createElement;
    document.createElement = function(tagName, options) {
        const el = nativeCreateElement.call(document, tagName, options);
        if (tagName.toLowerCase() === 'script') {
            const originalSetAttribute = el.setAttribute;
            el.setAttribute = function(name, value) {
                if (name === 'src' && value.includes(targetDomain)) {
                    return;
                }
                return originalSetAttribute.call(el, name, value);
            };
            Object.defineProperty(el, 'src', {
                set: function(value) {
                    if (value.includes(targetDomain)) {
                        return;
                    }
                    this.setAttribute('src', value);
                },
                get: function() {
                    return this.getAttribute('src');
                }
            });
        }
        return el;
    };

    const observer = new MutationObserver((mutations) => {
        for (const mutation of mutations) {
            for (const node of mutation.addedNodes) {
                if (node.tagName === 'SCRIPT' && node.src && node.src.includes(targetDomain)) {
                    node.type = 'javascript/blocked';
                    node.parentElement.removeChild(node);
                }
            }
        }
    });

    observer.observe(document.documentElement, {
        childList: true,
        subtree: true
    });
})();