index.js
/**
 * Method 2. Synchronous. Has a lower performance for pages with a lot of elements being inserted,
 * but triggers callback immediately after element insert.
 * This method is based on MutationObserver.
 * Fires callback once element is appended to the document.
 * @param {HTMLElement} element - Element to be appended
 * @param {function} callback - Append event handler
 */
Method 2. Synchronous. Has a lower performance for pages with a lot of elements being inserted,
but triggers callback immediately after element insert.
This method is based on MutationObserver.
Fires callback once element is appended to the document.
@param {HTMLElement} element - Element to be appended
@param {function} callback - Append event handler
Method 2 . Synchronous . Has a lower performance for pages with a lot of elements being inserted but triggers callback immediately after element insert . This method is based on MutationObserver . Fires callback once element is appended to the document . @param { HTMLElement } element - Element to be appended @param { function } callback - Append event handler
function onceAppendedSync (element, callback) {
    if (isAppended(element)) {
        callback();
        return;
    }
    const MutationObserver =
        window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
    if (!MutationObserver)
        return useDeprecatedMethod(element, callback);
    const observer = new MutationObserver((mutations) => {
        if (mutations[0].addedNodes.length === 0)
            return;
        if (Array.prototype.indexOf.call(mutations[0].addedNodes, element) === -1)
            return;
        observer.disconnect();
        callback();
    });
    observer.observe(document.body, {
        childList: true,
        subtree: true
    });
}
function onceAppendedSync ( element , callback ) { if ( isAppended ( element ) ) { callback ( ) ; return ; } const MutationObserver = window . MutationObserver || window . WebKitMutationObserver || window . MozMutationObserver ; if ( ! MutationObserver ) return useDeprecatedMethod ( element , callback ) ; const observer = new MutationObserver ( ( mutations ) => { if ( mutations [ 0 ] . addedNodes . length === 0 ) return ; if ( Array . prototype . indexOf . call ( mutations [ 0 ] . addedNodes , element ) === - 1 ) return ; observer . disconnect ( ) ; callback ( ) ; } ) ; observer . observe ( document . body , { childList : true , subtree : true } ) ; }
Method 2.
Method 2 .