Hello everyone,
I have a question. I’m currently designing the homepage for my vault, and I would like to add a button for a specific command.
It’s about Longform—I want the button to take me directly to my project, just like the command “Longform: Jump to project” does.
Is this even possible?
I already tried creating a solution with the help of an AI, but unfortunately, it didn’t work. My JavaScript knowledge is very basic—I know what const
, let
, if
, and while
mean and how to use them, but that’s about it. So, I’m a complete beginner .
// Button erstellen
const buttonContainer = this.container.createEl("button", {
text: "Zu Longform-Projekten wechseln",
cls: "longform-button",
});
// Stil für den Button
buttonContainer.style.backgroundColor = "#4CAF50"; // Grüne Farbe
buttonContainer.style.color = "white";
buttonContainer.style.padding = "10px 20px";
buttonContainer.style.border = "none";
buttonContainer.style.borderRadius = "5px";
buttonContainer.style.cursor = "pointer";
buttonContainer.style.fontSize = "14px";
buttonContainer.style.margin = "10px 0";
// Hover-Effekt
buttonContainer.addEventListener("mouseover", () => {
buttonContainer.style.backgroundColor = "#45a049"; // Dunkleres Grün
});
buttonContainer.addEventListener("mouseout", () => {
buttonContainer.style.backgroundColor = "#4CAF50"; // Zurück zu normalem Grün
});
// Klick-Event hinzufügen
buttonContainer.addEventListener("click", async () => {
try {
// Longform-Befehl ausführen
const longformCommand = "longform:jump-to-project"; // Der spezifische Befehl für Longform
const commandExists = app.commands.listCommands().some(cmd => cmd.id === longformCommand);
if (commandExists) {
// Befehl ausführen
await app.commands.executeCommandById(longformCommand);
new Notice("Longform-Projekte erfolgreich geöffnet!");
} else {
new Notice("Longform-Befehl wurde nicht gefunden. Stelle sicher, dass das Plugin installiert und aktiviert ist.");
}
} catch (error) {
console.error(error);
new Notice("Fehler beim Öffnen der Longform-Projekte. Siehe Konsole für Details.");
}
});