lichartee/main.js
2023-12-30 21:47:55 +01:00

58 lines
1.1 KiB
JavaScript

/*
* 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()