-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hooks for plugin creation and custom js injection at the various stages of yomitan lifecycle #567
Comments
Unclear what exactly is meant by a "hook" here. Are you imagining that other web extensions interact with Yomitan via something like this? Or are you thinking some more along the lines of web pages connecting to Yomitan (#522)? It's also not clear what you would expect these callbacks to be able to do, which may affect scope and feasibility of how something like this would even begin to be approached. This also has the potential to introduce pretty significant timing overhead in the application if there are async API hooks running at high-bandwidth code paths. There are also other challenges with regards to where this code actually runs. For example, |
I think that it's my bad to include any kind of terminology here without spending enough time with the code. The intention of this ticket is to discuss the possibility of creating plugins to Yomitan. How exactly to organize the extension points, should they be synchronous or asynchronous, etc. – I'm not yet qualified to say that. I've had in mind a simple system similar to what have been done in Wordpress. The js code of yomitan can have calls like that:
When the frontend is initialized, the extensions register their callbacks like that:
I imagine that callback functions are stored in a map like that:
and the I'm not at all married to that particular implementation though, it's just one of the ways I saw people organize plugins. |
The idea of more extensibility for the extension is very interesting, don't get me wrong. I just want to make it be known that it may not be as simple as extensions for e.g. Wordpress might be, due to the nature of the web extension security model. The biggest challenge I see is being able to do things that actually modify the extension page. As it stands, I'm not sure other extensions have any way of modifying the DOM without proxying commands into the Yomitan extension itself, same for access to the JavaScript state internals. So the hooks are possible, I'm just not sure what people would want to do with them. |
These are two questions. First: what the plugins would be useful for.
I was thinking about the following categories of plugins:
Overall, writing a plugin is typically much easier than contributing to the core, where there are all considerations of the scope of the change, accessibility, cross-platform, touch screens, i18n, corner cases, testing and CI, to name a few. Writing a plugin does not require all of that because the the core team is not responsible for the plugins. I saw a lot of times how plugin developers got more and more familiarized with the code, ending up being core contributors. |
Second question: how to deliver the custom code to yomitan? The custom css is now delivered to yomitan from within the extension. Where can the user input custom js?
|
Just to give a quick feasibility assessment, this option is not possible. Function/eval is the only way to invoke custom JS and web extensions don't allow it. |
It would be great to introduce hooks in yomitan for a plugin creation. Here is what I can think of immediately:
beforeWordScanned(text, word)
- called when a user hovers over a text while holding a hotkey.beforeWordStemmed
- called before the word is turned into its dictionary formbeforeWordSentForRequest(word)
- called before Yomitan starts searching the word in the databasebeforePopupRendered
,... etc.
Why is this important?
We saw on countless examples that plugin infrastructure promotes creativity and increases engagement of the community. Think of anki plugins, vim, emacs and VSCode plugins, IntelliJ IDEA, chrome and Firefox.
The text was updated successfully, but these errors were encountered: