CleanifyAternos

Gets rid of ads and sponsor stuff on Aternos

이 스크립트를 설치하려면 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         CleanifyAternos
// @namespace    https://soluzid.github.io/
// @version      1.0
// @description  Gets rid of ads and sponsor stuff on Aternos
// @author       Luz
// @match        *://*.aternos.org/*
// @grant        none
// @run-at       document-start
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    const removeSelectors = [
        '[data-gamera-placement-container]',
        '.placement',
        '#placement-right-skyscraper',
        '.responsive-leaderboard',
        '.server-b-tutorials',
        '.exaroton-header-leaderboard',
        '.boost-cta-box',
        '.ad-label-wrapper',
        '.ad-label',
        '.ad-replacement',
        'iframe[id^="google_ads_iframe_"]',
        '[data-google-query-id]',
        '[data-integralas-id]'
    ];

    const hideSelectors = [
        '.responsive-sky-scraper'
    ];

    const removeSelector = removeSelectors.join(',');
    const hideSelector = hideSelectors.join(',');

    function removeAds(root) {
        if (root.nodeType !== Node.ELEMENT_NODE) {
            return;
        }

        if (root.matches(removeSelector)) {
            root.remove();
            return;
        }

        root.querySelectorAll(removeSelector).forEach(function(element) {
            element.remove();
        });
    }

    function hideAdContainers(root) {
        if (root.nodeType !== Node.ELEMENT_NODE) {
            return;
        }

        if (root.matches(hideSelector)) {
            root.style.setProperty('display', 'none', 'important');
        }

        root.querySelectorAll(hideSelector).forEach(function(element) {
            element.style.setProperty('display', 'none', 'important');
        });
    }

    function clean(root) {
        if (root.nodeType !== Node.ELEMENT_NODE) {
            return;
        }

        removeAds(root);
        hideAdContainers(root);
    }

    function cleanExisting() {
        document.querySelectorAll(removeSelector).forEach(function(element) {
            element.remove();
        });

        document.querySelectorAll(hideSelector).forEach(function(element) {
            element.style.setProperty('display', 'none', 'important');
        });
    }

    function addHideStyle() {
        if (!document.documentElement) {
            return;
        }

        if (document.getElementById('cleanify-aternos-style')) {
            return;
        }

        const style = document.createElement('style');

        style.id = 'cleanify-aternos-style';
        style.textContent =
            hideSelector + ' { display: none !important; }';

        document.documentElement.appendChild(style);
    }

    const observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            mutation.addedNodes.forEach(function(node) {
                if (node.nodeType === Node.ELEMENT_NODE) {
                    clean(node);
                }
            });
        });
    });

    function start() {
        addHideStyle();

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

        cleanExisting();

        setInterval(function() {
            cleanExisting();
        }, 3000);
    }

    if (document.documentElement) {
        start();
    } else {
        const startupObserver = new MutationObserver(function() {
            if (!document.documentElement) {
                return;
            }

            startupObserver.disconnect();
            start();
        });

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