function main(node) {
    if (!node || !node.dataset.id || node.dataset.process) return;
    node.dataset.process = true;

    const imageNode = node.querySelector('.gutendraw-image');
    if (!imageNode) return;

    const g = GutendrawShortcode;
    const id = node.dataset.id;

    fetch(`${g.api.public_url}/images/${id}`)
        .then(response => response.json())
        .then(response => {
            imageNode.innerHTML = response.image;
            node.classList.add('gutendraw-ready');
            delete node.dataset.process;
        });
}

document.addEventListener( 'DOMContentLoaded', () => {
    const nodes = document.querySelectorAll('.gutendraw');
    for(const node of nodes) {
        main(node);
    }
});