Remove img filter, move file loader to utils

This commit is contained in:
city-unit
2023-08-21 11:21:32 -04:00
parent 7177fec50c
commit c7d9eb39f5
3 changed files with 36 additions and 34 deletions

View File

@ -597,6 +597,38 @@ export async function saveBase64AsFile(base64Data, characterName, filename = "",
}
}
/**
* Loads either a CSS or JS file and appends it to the appropriate document section.
*
* @param {string} url - The URL of the file to be loaded.
* @param {string} type - The type of file to load: "css" or "js".
* @returns {Promise} - Resolves when the file has loaded, rejects if there's an error or invalid type.
*/
export function loadFileToDocument(url, type) {
return new Promise((resolve, reject) => {
let element;
if (type === "css") {
element = document.createElement("link");
element.rel = "stylesheet";
element.href = url;
} else if (type === "js") {
element = document.createElement("script");
element.src = url;
} else {
reject("Invalid type specified");
return;
}
element.onload = resolve;
element.onerror = reject;
type === "css"
? document.head.appendChild(element)
: document.body.appendChild(element);
});
}
export function createThumbnail(dataUrl, maxWidth, maxHeight) {
return new Promise((resolve, reject) => {
const img = new Image();