/**
 * Prevent AG Grid from injecting Google Fonts (bundled Vazirmatn is used instead).
 */
(function () {
    'use strict';

    var blocked = /fonts\.googleapis\.com|fonts\.gstatic\.com/;

    function stripExternalFonts(node) {
        if (!node || node.nodeType !== 1) {
            return;
        }
        if (node.tagName === 'LINK' && node.href && blocked.test(node.href)) {
            if (node.parentNode) {
                node.parentNode.removeChild(node);
            }
            return;
        }
        if (node.tagName === 'STYLE' && node.textContent && blocked.test(node.textContent)) {
            if (node.parentNode) {
                node.parentNode.removeChild(node);
            }
        }
    }

    if (typeof MutationObserver === 'undefined' || !document.head) {
        return;
    }

    new MutationObserver(function (mutations) {
        mutations.forEach(function (mutation) {
            Array.prototype.forEach.call(mutation.addedNodes, stripExternalFonts);
        });
    }).observe(document.head, { childList: true });
})();
