RyotaUshio / obsidian-pdf-plus

The most Obsidian-native PDF annotation, viewing & editing tool ever. Comes with optional Vim keybindings.
https://ryotaushio.github.io/obsidian-pdf-plus/
MIT License
470 stars 11 forks source link

[Feature] User-defined commands with arbitrary JavaScript & provide a helper library #159

Open RyotaUshio opened 2 months ago

RyotaUshio commented 2 months ago

Allow the user to add their own custom context menu item that can trigger arbitrary JavaScript. It will be also beneficial to provide some commonly used functions as a library so that everyone can use them without reinventing the wheel.

An example I have in mind is a context menu item "Add to dictionary". It will create a new note in the English/Dictionary folder whose title is set to the selected text. The note content could be initialized with a link to the text selection.

RyotaUshio commented 2 months ago

By the way, this can be already achieved by the following custom link copy format:

{{ app.vault.create('English/Dictionary/' + text.trim() + '.md', linkWithDisplay).then((file) => app.workspace.getLeaf(true).openFile(file)), '' }}
N3C2L commented 2 months ago

Great idea to power up the context menu even more! The add to dictionary function could be really useful to learn new words & creating new .md files with it for remembering!

I'd be glad if you could add something like this to the library:

  1. Copy selected text and insert it into the obsidian search sidebar
  2. Copy selected text and search the internet browser with it
RyotaUshio commented 2 months ago

Macros (#145) will be addressed as a part of this feature.

RyotaUshio commented 2 months ago

We don't need to limit ourselves to context menus; it would be better if we could define custom commands that can be triggered from anywhere like any other Obsidian commands. These commands can be added to the context menu, too.

This way, #174 also can be resolved by this feature.