A
A
Astral1004982020-08-13 15:04:14
Google
Astral100498, 2020-08-13 15:04:14

Developing an extension for chrome(Word Translator)?

Good afternoon, the task is to develop an extension for chrome. the essence of which. Highlight a word on a page, translate it, and then replace it on the page. I ask for help on how to implement this, especially replacing the text inside the page. I will be grateful for any help.

Recently, yandex and google translate have become paid. Are there other free machine translation services?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Karbivnichy, 2020-08-13
@hottabxp

Chrome has a built-in translator extension (from google). Moreover, it is free:
5f352d8740e4b749809637.png
If you need to translate a lot of text, then select -> RMB -> Google translator.

especially replacing text inside the page

From javascript.com:
var a = document.getElementsByTagName('a')[0];
a.innerHTML = a.innerHTML.replace(/Play!/,'Stop!');

changes the link text.

G
Gimir, 2020-08-13
@Gimir

An interesting task, probably, I would try this:
Take the word using the context API, translate it, pass it to contentScript, replace the word.
The difficulty is to know exactly where to replace. I suppose that you need to take a whole paragraph of this word, and using the search for a substring or in some other way replace it.
I don’t know what opportunities the context API has, maybe it can or can not catch the tag.
It's just like that, thoughts)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question