How to get into scripting #4619
-
I have a hard time getting into Scripting. I have seen the examples in Trilium Demo but they are not really explained or commented. I also found https://github.com/Nriver/awesome-trilium which has a few more extensions to learn from. However, learning by picking apart existing implementations is not really a great way to learn. Are there real tutorials somewhere? The https://github.com/zadam/trilium/wiki/Scripts section is also more a random example as far as I can say. Currently, I am looking for a tutorial on how to add a button to a note that on a press shows a message (for example a number between 1 and 6). The JavaScript would be something like: function getRandomArbitrary(min, max) {
return Math.random() * (max - min) + min;
}
async function helloWorld() {
alert("The number is: " + getRandomArbitrary(1,6));
} but of course I am unaware of how to link this with Trilium properly. I thought about using widgets, but as I haven't found proper documentation (https://github.com/zadam/trilium/wiki/Custom-widget also just another example) on that class I only saw the weight examples which doesn't use a button and is uncommented. Thank you in advance! PS: On a second look I now found https://github.com/zadam/trilium/wiki/Widget-Basics which might be a bit more helpful, but in general the quetstion still stands: Are there real tutorials somewhere? Is this the best place to ask questions or is there an active scripting community somewhere? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
There are no real tutorials (yet), I had intended to write more but life gets in the way. The important part is the prerequisite of knowing JavaScript, and DOM manipulation. After that, the Trilium part of things is pretty straightforward and documented. |
Beta Was this translation helpful? Give feedback.
I missed the reference to https://zadam.github.io/trilium/frontend_api/FrontendScriptApi.html which basically answers all my questions.