插件:强制谷歌翻译以翻译注入的文本

发布于 2025-01-23 11:09:41 字数 449 浏览 2 评论 0原文

我是一个业余程序员,最近我发现了如何为Google Chrome制作插件。 我正在使用Google翻译大量翻译在英语荷兰语和阿拉伯语之间。 现在,我正在尝试为Google Translate网站制作插件,以便根据字段IM键入的字段自动将输入字符更改为正确的字符。 (无法更改键盘布局) 长话短说:我设法将字符更改为正确的字符,但是Google翻译不会翻译文本,除非我按Enter或其他我没有更改的键。

代码有点混乱,没有添加整个内容。基本上,我使用了按键和键盘功能将正确的字符注入文本字段中。

我可以使用什么代码强制Google翻译以翻译文本?

Im an amateur programmer, and recently i discovered how to make plugins for google chrome.
Im using google translate alot to translate between english dutch and arabic.
Now im trying to make a plugin for the google translate website so it will automaticly change the input characters to the correct ones depending on the field im typing in.
(changing keyboard layout is not possible)
Long story short: I managed to change the characters to the correct ones, but google translate doesn not translate the text, unless i press enter or another key that i didnt change.

the code is a bit messy not gone add the whole thing. basicly i used the keypressed and keydown functions to inject the correct characters in the textfield.

What code can i use to force google translate to translate the text?
No translation of injected teks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别低头,皇冠会掉 2025-01-30 11:09:41

关键是要将气泡 event()构造函数的第二个参数对象的属性更改为true> True(默认值为 false )。

textarea = document.querySelector("[aria-label=Brontekst]")
textarea.value = "demo"
textarea.dispatchEvent(new Event("input", { bubbles: true }))

The key is to change the bubbles property of the second parameter object of the Event() constructor to true (the default value is false).

textarea = document.querySelector("[aria-label=Brontekst]")
textarea.value = "demo"
textarea.dispatchEvent(new Event("input", { bubbles: true }))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文