mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-12-06 19:56:45 +10:30
49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import ShortcutLinks from "@/seqta/content/links.json";
|
|
import stringToHTML from "../stringToHTML";
|
|
|
|
export function addShortcuts(shortcuts: any) {
|
|
for (let i = 0; i < shortcuts.length; i++) {
|
|
const currentShortcut = shortcuts[i];
|
|
|
|
if (currentShortcut?.enabled) {
|
|
const Itemname = (currentShortcut?.name ?? "").replace(/\s/g, "");
|
|
|
|
const linkDetails = ShortcutLinks?.[Itemname as keyof typeof ShortcutLinks];
|
|
if (linkDetails) {
|
|
createNewShortcut(
|
|
linkDetails.link,
|
|
linkDetails.icon,
|
|
linkDetails.viewBox,
|
|
linkDetails.DisplayName || currentShortcut?.name,
|
|
);
|
|
} else {
|
|
console.warn(`No link details found for '${Itemname}'`);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function createNewShortcut(link: any, icon: any, viewBox: any, title: any) {
|
|
// Creates the stucture and element information for each seperate shortcut
|
|
const container = document.getElementById("shortcuts");
|
|
if (!container) return;
|
|
|
|
const shortcut = document.createElement("a");
|
|
shortcut.setAttribute("href", link);
|
|
shortcut.setAttribute("target", "_blank");
|
|
const shortcutdiv = document.createElement("div");
|
|
shortcutdiv.classList.add("shortcut");
|
|
|
|
const image = stringToHTML(
|
|
`<svg style="width:39px;height:39px" viewBox="${viewBox}"><path fill="currentColor" d="${icon}" /></svg>`,
|
|
).firstChild;
|
|
(image! as HTMLElement).classList.add("shortcuticondiv");
|
|
const text = document.createElement("p");
|
|
text.textContent = title;
|
|
shortcutdiv.append(image as HTMLElement);
|
|
shortcutdiv.append(text);
|
|
shortcut.append(shortcutdiv);
|
|
|
|
container.appendChild(shortcut);
|
|
}
|