#include utility.js

const MamiEEPROM = function() {
    //
};
MamiEEPROM.init = (function() {
    let initialised = false;
    
    return () => {
        return new Promise((resolve, reject) => {
            if(initialised)
                return new Promise(resolve => resolve());

            const script = $e({
                tag: 'script',
                attrs: {
                    charset: 'utf-8',
                    type: 'text/javascript',
                    src: `${futami.get('eeprom2')}/scripts/eepromv1a.js`,
                    onload: () => {
                        initialised = true;
                        resolve();
                    },
                    onerror: () => {
                        $r(script);
                        console.error('Failed to load EEPROM script!');
                        reject();
                    },
                },
            });

            document.body.appendChild(script);
        });
    };
})();
