Search code examples
javascriptgoogle-chromepluginstextfieldadd-on

plugin : force google translate to translate injected text


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


Solution

  • 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 }))