Commit pirate JS files

This commit is contained in:
2026-04-02 17:39:02 -06:00
parent 7b15a0eb9c
commit d287f8a443
49 changed files with 19149 additions and 0 deletions

75
js/AsyncResourceLoader.js Normal file
View File

@@ -0,0 +1,75 @@
/*
Copyright (c) 2023-forever Douglas Malnati. All rights reserved.
See the /faq/tos page for details.
(If this generated header is stamped on a file which is a 3rd party file or under a different license or copyright, then ignore this copyright statement and use that file's terms.)
*/
///////////////////////////////////////////////////////////////////////////////
// Cache subsequent loads for the same resource, which all takes their own
// load time, even when the url is the same.
///////////////////////////////////////////////////////////////////////////////
export class AsyncResourceLoader
{
static url__scriptPromise = new Map();
static AsyncLoadScript(url)
{
if (this.url__scriptPromise.has(url) == false)
{
let p = new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = url;
script.async = true;
script.onload = () => {
resolve();
};
script.onerror = (message) => {
reject(new Error(message));
}
document.body.appendChild(script);
});
this.url__scriptPromise.set(url, p);
}
let p = this.url__scriptPromise.get(url);
return p;
}
static url__stylesheetPromise = new Map();
static AsyncLoadStylesheet(url)
{
if (this.url__stylesheetPromise.has(url) == false)
{
let p = new Promise((resolve, reject) => {
const link = document.createElement('link');
link.rel = "stylesheet";
link.href = url;
link.async = true;
link.onload = () => {
resolve();
};
link.onerror = (message) => {
reject(new Error(message));
};
document.body.appendChild(link);
});
this.url__stylesheetPromise.set(url, p);
}
let p = this.url__stylesheetPromise.get(url);
return p;
}
}