diff --git a/src/interface/pages/settings/shortcuts.svelte b/src/interface/pages/settings/shortcuts.svelte index bd22ea96..d507a7d8 100644 --- a/src/interface/pages/settings/shortcuts.svelte +++ b/src/interface/pages/settings/shortcuts.svelte @@ -6,6 +6,7 @@ import Shortcuts from "@/seqta/content/links.json" let isLoaded = $state(false); + let fileInput = $state(null); onMount(async () => { // Wait for settingsState to be initialized @@ -35,6 +36,25 @@ let isFormVisible = $state(false); let newTitle = $state(""); let newURL = $state(""); + let newIcon = $state(null); + + function handleIconChange(event: Event) { + const file = (event.target as HTMLInputElement).files?.[0]; + if (file && file.type === "image/svg+xml") { + const reader = new FileReader(); + reader.onload = () => { + newIcon = reader.result as string; + }; + reader.readAsText(file); + } + } + + const clearIcon = () => { + newIcon = null; + if (fileInput) { + fileInput.value = ""; // Clear the file input so the same file can be re-selected + } + }; const toggleForm = () => { isFormVisible = !isFormVisible; @@ -54,11 +74,13 @@ const addNewCustomShortcut = () => { if (isValidTitle(newTitle) && isValidURL(newURL)) { - const newShortcut = { name: newTitle.trim(), url: formatUrl(newURL).trim(), icon: newTitle[0] }; + const icon = newIcon || newTitle[0]; + const newShortcut = { name: newTitle.trim(), url: formatUrl(newURL).trim(), icon }; settingsState.customshortcuts = [...settingsState.customshortcuts, newShortcut]; newTitle = ""; newURL = ""; + newIcon = null; isFormVisible = false; } else { alert("Please enter a valid title and URL."); @@ -101,14 +123,56 @@ initial={{ opacity: 0, y: -10 }} animate={{ opacity: 1, y: 0 }} transition={{ delay: 0.05, duration: 0.2 }} - class="w-full" + class="flex gap-2 w-full" > - + + + {/if} diff --git a/src/seqta/utils/CreateEnable/CreateCustomShortcutDiv.ts b/src/seqta/utils/CreateEnable/CreateCustomShortcutDiv.ts index 75a9296c..ed986657 100644 --- a/src/seqta/utils/CreateEnable/CreateCustomShortcutDiv.ts +++ b/src/seqta/utils/CreateEnable/CreateCustomShortcutDiv.ts @@ -9,23 +9,35 @@ export function CreateCustomShortcutDiv(element: any) { shortcutdiv.classList.add("shortcut"); shortcutdiv.classList.add("customshortcut"); - let image = stringToHTML( - ` - - - ${element.icon} - - - `, - ).firstChild; + let image: ChildNode | null = null; + + if (typeof element.icon === "string" && element.icon.trim().startsWith("<")) { + image = stringToHTML(element.icon).firstChild; + } else if (typeof element.icon === "string" && element.icon.startsWith("data:image")) { + const img = document.createElement("img"); + img.src = element.icon; + img.style.width = "39px"; + img.style.height = "39px"; + image = img; + } else { + image = stringToHTML( + /* html */` + + + ${element.icon} + + + `, + ).firstChild; + } (image as HTMLElement).classList.add("shortcuticondiv"); var text = document.createElement("p"); text.textContent = element.name; diff --git a/src/seqta/utils/DisableRemove/RemoveShortcutDiv.ts b/src/seqta/utils/DisableRemove/RemoveShortcutDiv.ts index 1eca2b84..5e76dc59 100644 --- a/src/seqta/utils/DisableRemove/RemoveShortcutDiv.ts +++ b/src/seqta/utils/DisableRemove/RemoveShortcutDiv.ts @@ -10,7 +10,7 @@ export function RemoveShortcutDiv(elements: any) { const textElement = shortcut.querySelector("p"); //

is a direct child of .shortcut const title = textElement ? textElement.textContent : ""; - const elementName = links[element.name as keyof typeof links].DisplayName || element.name; + const elementName = links[element.name as keyof typeof links]?.DisplayName || element.name; let shouldRemove = title === elementName;