mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Remove img filter, move file loader to utils
This commit is contained in:
@ -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();
|
||||
|
Reference in New Issue
Block a user