/* * GLOBAL VARIABLE! * list of loaded scripts (only itself at start) **/ var __scripts = [ 'main.js' ]; //var __lang = 'en'; /* i18n small function */ function _(key) { return key; //return LANG[__lang][key] == undefined ? key : LANG[__lang][key]; } /* include other scripts to the html file */ async function include(src, script_list) { /* DOM operations */ let script = document.createElement('script'); script.setAttribute('src' , src ); document.getElementsByTagName('head')[0].appendChild(script); /* check if the element is added to the DOM */ let script_loaded = new Promise( (resolve, reject) => { if (script !== undefined) { script.addEventListener('load', () => { resolve(0); }); } else { reject( _( 'an error occured when adding the script element' + 'for ${src}' ) ); } } ); script_list.push(src); // the script is considered as loaded return script_loaded.then( (value) => script_list, (error) => { throw error; } ); } async function launch() { __scripts = await include('./lichartee.js', __scripts); __scripts = await include('./test.js', __scripts); } launch()