//jsloader.js (function() { if(typeof XMLHttpRequest!="function") { if(typeof loadfail=="function") { loadfail("1-jsloader.js: XMLHttpRequest(type of "+(typeof XMLHttpRequest)+") is not a function"); } else { window.alert("1-jsloader.js: XMLHttpRequest(type of "+(typeof XMLHttpRequest)+") is not a function"); } return; } var scriptManager= {}; scriptManager.loadingcount=0; scriptManager.loadjs=async function(pth) { var resolve; var reject; var ret=new Promise(function(s, r) { resolve=s; reject=r; }); var xhr=new XMLHttpRequest(); var onreadystatechange=function() { if(xhr.readyState!=XMLHttpRequest.DONE) { return; } removelisteners(); if(xhr.status!=200) { onfail(); return; } console.debug("script "+pth+" fetched successfully."); try { var fn=new Function(xhr.responseText); Object.defineProperty(fn, "name", {"value":pth}); fn(); } catch(e) { console.error(e); } console.debug("script "+pth+" loaded."); scriptManager.loadingcount--; resolve(); return; }; var onfail=function() { removelisteners(); xhr.abort(); window.loadfail("script "+pth+" load failed"); reject("script "+pth+" load failed"); }; var removelisteners=function() { xhr.removeEventListener("readystatechange", onreadystatechange); xhr.removeEventListener("error", onfail); xhr.removeEventListener("abort", onfail); }; xhr.addEventListener("readystatechange", onreadystatechange); xhr.addEventListener("error", onfail); xhr.addEventListener("abort", onfail); xhr.open("GET", pth, true); xhr.send(); scriptManager.loadingcount++; return ret; }; scriptManager.isDone=function() { return scriptManager.loadingcount==0; }; scriptManager.waitAll=async function() { return new Promise(function(resolve, reject) { var i; i=setInterval(function() { if(scriptManager.loadingcount==0) { clearInterval(i); resolve(); } }, 100); }); }; window.scriptManager=scriptManager; })();