From 73092058c6135bbd60e32d4c5eeed30a60d0ed8b Mon Sep 17 00:00:00 2001 From: Gerard Parareda Date: Sat, 23 Oct 2021 16:54:35 +0200 Subject: [PATCH] Adds translations via LibreTanslate --- background.js | 17 +++++++++++++++++ popup.html | 10 +++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/background.js b/background.js index cb7a752..1019938 100644 --- a/background.js +++ b/background.js @@ -129,3 +129,20 @@ fetch('https://api.github.com/repos/fcoterroba/Advice_Me/contributors?per_page=1 footer.innerHTML = text; }) +fetch('https://libretranslate.com/languages', {}) +.then(response => response.json()) +.then(data => { + console.log(data); + languages_html = data.map(lang => {return ``}); + document.getElementById("languages-list").innerHTML = languages_html; + to_translate = document.querySelector('.phrase').innerHTML; + const res = fetch("https://libretranslate.com/translate", { + method: "POST", + body: JSON.stringify({ + q: to_translate, + source: "en", + target: document.getElementById("languages-list").value + }), + headers: { "Content-Type": "application/json" } + }).then(response => response.json()).then(data => document.querySelector('.phrase').innerHTML = data.translatedText); +}) \ No newline at end of file diff --git a/popup.html b/popup.html index 0e79be0..212ee52 100644 --- a/popup.html +++ b/popup.html @@ -1,7 +1,7 @@ - + @@ -13,6 +13,14 @@

Did you need strength to continue?

+
+ + +

+ +
+