MichaelB / healio.com-no-limit

// ==UserScript==
// @name		healio.com-no-limit
// @description		Removes subscribe notification from https://www.healio.com
// @copyright		2022, MichaelB
// @license		MIT
// @version		2.0.0
// @author		MichaelB
// @match		https://www.healio.com/*
// @run-at		document-idle
// ==/UserScript==

(function () {
    'use strict';

    const makeDomListener = (params) => {
        const self = {
            listener: null,
            domListenerCallback: params.domListenerCallback,
        };
        return {
            listen: listen(self),
        };
    };
    const listen = (self) => () => {
        if (self.listener) {
            throw new Error("[DOM Listener] Already inited.");
        }
        self.listener = new MutationObserver(self.domListenerCallback.callback);
        self.listener.observe(document.body, {
            childList: true,
            attributes: false,
            subtree: true,
            characterData: false,
        });
    };

    const makeDomListenerCallback = () => {
        return {
            callback: callback(),
        };
    };
    const callback = () => (mutations) => {
        const element = getElement(mutations);
        if (!element) {
            return;
        }
        element.remove();
    };
    const getElement = (mutations) => {
        return [...mutations].reduce((acc, mutation) => {
            if (acc !== null) {
                return acc;
            }
            const element = [...mutation.addedNodes].find((element) => element.className === "modal register-modal");
            if (!element) {
                return acc;
            }
            return element;
        }, null);
    };

    const main = () => {
        const domListenerCallback = makeDomListenerCallback();
        const domListener = makeDomListener({ domListenerCallback });
        domListener.listen();
    };

    main();

})();