Cat-Printer/www/loader.js
2022-04-17 03:20:37 +08:00

39 lines
1.1 KiB
JavaScript

/**
* Satisfy both development and old-old webView need
*/
(function() {
var fallbacks = [
// main scripts, which we will directly modify
'i18n-ext.js', 'i18n.js', 'image.js', 'main.js',
// "compatibility" script, produced with eg. typescript tsc
'main.comp.js'
];
var trial_count = 0;
/**
* Try to load next "fallback" script,
* until we see the "main" variable (ie. success)
* fail if nothing is left to load.
* This is recursive. Just call once.
*/
function try_load() {
var script = document.createElement('script');
script.addEventListener('load', function() {
if (typeof main === 'undefined') {
script.remove();
try_load();
} else {
console.log('Success');
}
});
var path = fallbacks[trial_count++];
if (!path) throw new Error('All fallback scripts were tried');
script.src = path;
console.log('Trying script: ' + path);
document.body.appendChild(script);
}
try_load();
})();