0

The google translate page allow the user to translate between different languages. https://translate.google.com.hk/?sl=en&tl=zh-TW&op=translate&hl=en

I can write a javascript clicking the microphone button to continuously translate the speech.

setInterval(function () {
        
document.getElementsByClassName('EmVfjc qs41qe lSo1Re BbO7g')[0].click();

}, 1000);

But that does not my demand as it clear the translated data. How can I get the underlying event listener for the microphone button?

Mr Chan
  • 47
  • 7
  • 1
    It seems like they are using dynamic class names. So your solution might not prove to be very robust. Instead try this selector `button[aria-label="Translate by voice"] > span > div` - it finds the button labeled "Translate by voice" but there does not seem to be a handler attached - however, if you find the first div in the first span inside the button, then the click event is handled. – soupy-norman Aug 16 '22 at 07:52
  • 1
    I'd suggest that you use the Google Translate API instead of trying to hack the frontend. https://googleapis.dev/nodejs/googleapis/45.0.0/translate/classes/Translate.html. Also, look at the answers in this thread: https://stackoverflow.com/q/35002003/12057512 – Emil Karlsson Aug 16 '22 at 07:53
  • Yes, it does work. $('button[aria-label="Translate by voice"] > span > div').click(); – Mr Chan Aug 17 '22 at 17:34
  • Is it very hard to find these event listeners ( the underlying codes ) in most case? – Mr Chan Aug 17 '22 at 17:36

0 Answers0