1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
export function escapeHtml(value) {
return String(value).replace(/[&<>"']/g, function (c) {
return { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c];
});
}
export function whenReady(scriptId, globalName, callback) {
const ready = () => typeof globalThis[globalName] !== "undefined";
if (ready()) {
callback();
return;
}
const script = document.getElementById(scriptId);
if (!script) {
callback();
return;
}
const run = () => {
if (ready()) callback();
};
script.addEventListener("load", () => {
script.setAttribute("data-loaded", "1");
run();
});
if (script.getAttribute("data-loaded")) run();
}