Mochi

Custom JavaScript fields for dynamic content generation

I'd request a feature that allows users to define custom dynamic fields using JavaScript (or other scripting languages).

Currently, Mochi offers some very helpful built-in dynamic fields, but I'd like to be able to define my own logic. For example:

  • send custom API requests
  • perform custom string manipulation (e.g., regex parsing, transformations)
  • randomize the order of the content every time I review

What I'm envisioning is similar to how the current "AI text generator" field works: a field in the template editor where I can input JavaScript code that takes the field value(s) as input and returns a modified string.

Since script tags aren't rendered in Mochi's HTML, this kind of functionality would be a powerful workaround and enable highly customized workflows.

Of course, I understand there are security concerns with allowing arbitrary code execution. But even a limited, sandboxed environment (like Web Workers or a subset of JavaScript) would be helpful for users who want to fully customize their experience!

I actually started a branch for this feature a loooong time ago but never released it. https://x.com/MochiCardsApp/status/1712345101039755608

I'd like to clean it up and release it as a beta feature soon.

I was trying to figure out if there was a way to do this very thing today. I am learning Clojure and would like to input some code as the value to an input tag and pass that value to the AI generator to determine if the code is valid and satisfies the solution to a question above the input