commit 627e42defa16997cdf63138ec29180c60c59e961 Author: OverPoweredDev Date: Wed Jun 23 14:01:09 2021 +0530 fixed a couple problems in translation It wasn't formatting the translated text right. Also a few problems in calling the right function diff --git a/src/content/content.js b/src/content/content.js index 2495726..56f2383 100644 --- a/src/content/content.js +++ b/src/content/content.js @@ -10,18 +10,3 @@ function addHoverElements(settings) { } } -async function getTranslation(inputText, sourceLanguage, targetLanguage) { - let outputText; - let langPair = ""; - langPair = langPair.concat(sourceLanguage, "|", targetLanguage); - - let url = new URL(getTranslationEndpoint()); - let params = {langpair: langPair, q: inputText, format: "html"}; - url.search = new URLSearchParams(params).toString(); - - outputText = await fetch(url) - .then(response => response.json()) - .then(data => data.responseData.translatedText); - - return outputText; -} diff --git a/src/content/hover.css b/src/content/hover.css index e0edaa3..6b9e8da 100644 --- a/src/content/hover.css +++ b/src/content/hover.css @@ -112,4 +112,10 @@ [data-tooltip]:hover:after { display: block; z-index: 50; +} + +[data-tooltip]:hover{ + animation-delay: 100ms; + -moz-animation-delay: 100ms; + -webkit-animation-delay: 100ms; } \ No newline at end of file diff --git a/src/content/hover.js b/src/content/hover.js index 95296ff..a11a4de 100644 --- a/src/content/hover.js +++ b/src/content/hover.js @@ -1,4 +1,8 @@ function addHoverTag(targetLanguage) { + // (?![^<]*?>)([A-z0-9']+) + // - (?![^<]*?>) to not consider any html tags. or rather, to not consider anything wrapped in <>. But since all <'s are coded as < in html, it only affects tags + // - ([A-z0-9']+) apart from tags, we consider all words, numbers or words containing "'" + $('p').each(function () { $(this).html($(this).html().replace(/(?![^<]*?>)([A-z0-9']+)/g , '$1')); }); @@ -8,22 +12,23 @@ function addHoverTag(targetLanguage) { let self = $(this) setTimeoutConst = setTimeout(async function () { let text = self.attr('data-tooltip'); - let translation = await getTranslation(text, 'eng', targetLanguage); - self.attr('data-tooltip', translation); + if(self.text() === text) { + let translation = await translate(text, 'eng', targetLanguage); + self.attr('data-tooltip', translation); + } }, 1000); }, function() { clearTimeout(setTimeoutConst); }); - } -async function getTranslation(inputText, sourceLanguage, targetLanguage) { +async function translate(inputText, sourceLanguage, targetLanguage) { let outputText; let langPair = ""; langPair = langPair.concat(sourceLanguage, "|", targetLanguage); let url = new URL(getTranslationEndpoint()); - let params = {langpair: langPair, q: inputText, format: "html"}; + let params = {langpair: langPair, q: inputText, deformat: "html"}; url.search = new URLSearchParams(params).toString(); outputText = await fetch(url)