yomichan icon indicating copy to clipboard operation
yomichan copied to clipboard

[Feature Request] Simple Web API

Open tchin25 opened this issue 4 years ago • 3 comments

Although something like #262 is a massive undertaking, a simpler API could be implemented first for browsers.

For instance, something like:

  • The ability to window.postMessage() a word to lookup
  • The ability to listen to an event that emits JSON data of a word that's looked up

This would allow web apps and other extensions to use Yomichan's lookup and deinflection features. There really isn't any Japanese dictionary API that supports deinflection except for Jisho's which has been in beta for the past 6 years, so this can fill that niche.

If we're worried about security, it could be something that's disabled by default or be behind a whitelist.

tchin25 avatar May 02 '21 01:05 tchin25

I suppose this is possible, but it's a separate category of API compared to #262. There are some potential technical issues with it:

  • The search results are dependent on user settings.
  • Race conditions to determine if Yomichan is active.
  • The backend data format has no guarantees that it will not change across versions.

What would the use case be for this?

toasted-nutbread avatar May 12 '21 22:05 toasted-nutbread

What would the use case be for this?

On a website like LingQ where you have a situation where you have to manually add your own definitions to new words, an auto-complete feature using Yomichan would be nice. Within my own projects, I have a basic web app that already uses AnkiConnect to bulk-add cards, and it would be nice to also be able to bulk-add the definitions as well without worrying about rate-limiting an external API. It's definitely more of a QOL thing; I wouldn't expect a web app to have Yomichan as a dependency to work properly.

Something like I'm suggesting is technically possible if the user has the shadow dom disabled and I watch Yomichan's iframe for changes and webscrape it, but that seems like the definition of jank.

tchin25 avatar May 14 '21 06:05 tchin25

Thinking some more about it, it doesn't seem like this would cause any significant issues if this was implemented as an opt-in feature. It would probably take some combination of allowed-origins and API keys to make it acceptably secure.

The main point is that there wouldn't be a guarantee about the API not changing with new versions, since it would basically be exposing the internal APIs. So the input/output data structures could change, even if we controlled for varying user settings.

That said, I'll see if I can look more into this sometime to see if there are any other potential issues.

Something like I'm suggesting is technically possible if the user has the shadow dom disabled and I watch Yomichan's iframe for changes and webscrape it, but that seems like the definition of jank.

You wouldn't be able to access the internals of the iframe anyways due to security/cross-origin.

toasted-nutbread avatar May 14 '21 23:05 toasted-nutbread