'use strict';


let addedNodes, mutationobserver;

function init() {

    addedNodes = [];
    mutationobserver = new MutationObserver(function (mutations) {
        mutations.forEach(function (mutation) {
            if (mutation.type === 'childList' && mutation.removedNodes) {

                mutation.addedNodes.forEach((n) => {
                    if (n instanceof HTMLElement) {
                        addedNodes.push(n);
                    }
                })
            }
        });
    });
}

/**
 *
 */
export function initMutationObserverForTesting() {

    if (mutationobserver === undefined) {
        init()
    }

    mutationobserver.observe(document.querySelector('head'), {childList: true});
}

/**
 *
 */
export function cleanupDOMFromTesting() {
    mutationobserver.disconnect();

    for (const n of addedNodes) {
        n.remove();
    }
}