diff --git a/doc/description.md b/doc/description.md index 39767fe4..62e5c4b0 100644 --- a/doc/description.md +++ b/doc/description.md @@ -19,6 +19,8 @@ Mouseover Translate Any Language At Once English, Russian, Japanese, Chinese and so on # Change Log +- 0.1.101 + - add source language & mouse click for tooltip (request by محمد ع. أبو الحسن) - 0.1.100 - make hijack injection tighter for support more site (request by AstudilloMarillo) - 0.1.99 diff --git a/public/_locales/am/messages.json b/public/_locales/am/messages.json index e23bfd65..b12c498f 100644 --- a/public/_locales/am/messages.json +++ b/public/_locales/am/messages.json @@ -162,7 +162,7 @@ "message": "Title " }, "appName": { - "message": "የመዳፊት መሳሪያ መሳሪያ ተርጓሚ" + "message": "የመዳፊት መሳሪያ መሳሪያ ተርጓሚ for learning language" }, "appDesc": { "message": "የመዳፊት መሣሪያ መሣሪያ ተርጓሚ የጉግል ትርጉም በመጠቀም Moyyover ጽሑፍን ይተርጉሙ" diff --git a/public/_locales/bg/messages.json b/public/_locales/bg/messages.json index 1c410c1f..812bbd4e 100644 --- a/public/_locales/bg/messages.json +++ b/public/_locales/bg/messages.json @@ -162,7 +162,7 @@ "message": "Title " }, "appName": { - "message": "Преводач на мишка with romanization" + "message": "Преводач на мишка : manga translator" }, "appDesc": { "message": "Превода" diff --git a/public/_locales/ca/messages.json b/public/_locales/ca/messages.json index c2769eed..db5129da 100644 --- a/public/_locales/ca/messages.json +++ b/public/_locales/ca/messages.json @@ -162,7 +162,7 @@ "message": "Title " }, "appName": { - "message": "Traductor d'eines de ratolí For Google Translator" + "message": "Traductor d'eines de ratolí With Google Translator" }, "appDesc": { "message": "Traductor de Tool Tip Tra Translate Text MouseOver mitjançant Google Translate" diff --git a/public/_locales/de/messages.json b/public/_locales/de/messages.json index bfabbd2c..3f711edc 100644 --- a/public/_locales/de/messages.json +++ b/public/_locales/de/messages.json @@ -162,7 +162,7 @@ "message": "Title " }, "appName": { - "message": "Maus -Tooltip -Übersetzer" + "message": "Maus -Tooltip -Übersetzer for pdf ebook" }, "appDesc": { "message": "Maus -Tooltip -Übersetzer übersetzen Mausover -Text mit Google Translate" diff --git a/public/_locales/el/messages.json b/public/_locales/el/messages.json index 57c6469c..f9837c0c 100644 --- a/public/_locales/el/messages.json +++ b/public/_locales/el/messages.json @@ -162,7 +162,7 @@ "message": "Title " }, "appName": { - "message": "Μεταφραστής εργαλείων ποντικιού : Translate Image and Text" + "message": "Μεταφραστής εργαλείων ποντικιού : Translate Image" }, "appDesc": { "message": "Μεταφραστής εργαλείων ποντικιού Μεταφράστε κείμενο ποντικιού χρησιμοποιώντας το Google Translate" diff --git a/public/_locales/es_419/messages.json b/public/_locales/es_419/messages.json index 7bedfa75..788e8794 100644 --- a/public/_locales/es_419/messages.json +++ b/public/_locales/es_419/messages.json @@ -162,7 +162,7 @@ "message": "Title " }, "appName": { - "message": "Traductor de información sobre herramientas del mouse - Translate Manga" + "message": "Traductor de información sobre herramientas del mouse for Education" }, "appDesc": { "message": "El traductor de información sobre herramientas de mouse traducir el texto de mouseover usando Google Translate" diff --git a/public/_locales/fi/messages.json b/public/_locales/fi/messages.json index 93107a08..1583a049 100644 --- a/public/_locales/fi/messages.json +++ b/public/_locales/fi/messages.json @@ -162,7 +162,7 @@ "message": "Title " }, "appName": { - "message": "Hiiren työkaluvihje kääntäjä - Web Translate" + "message": "Hiiren työkaluvihje kääntäjä : TTS Translator" }, "appDesc": { "message": "Hiiren työkaluvihje kääntäjä Käännä hiirensiirtoteksti Google Translate -sovelluksella" diff --git a/public/_locales/fr/messages.json b/public/_locales/fr/messages.json index 02f6b914..45e15ee0 100644 --- a/public/_locales/fr/messages.json +++ b/public/_locales/fr/messages.json @@ -162,7 +162,7 @@ "message": "Titre " }, "appName": { - "message": "Traduction Souris Info-bulle" + "message": "Traduction Souris Info-bulle : Learn Language" }, "appDesc": { "message": "Traduire le texte pointé par la souris à l'aide de différent moteur de traduction" diff --git a/public/_locales/gu/messages.json b/public/_locales/gu/messages.json index d327f225..28490e20 100644 --- a/public/_locales/gu/messages.json +++ b/public/_locales/gu/messages.json @@ -162,7 +162,7 @@ "message": "Title " }, "appName": { - "message": "માઉસ ટૂલટિપ અનુવાદક for learning language" + "message": "માઉસ ટૂલટિપ અનુવાદક : TTS" }, "appDesc": { "message": "ગૂગલ ટ્રાન્સલેશનનો ઉપયોગ કરીને માઉસ ટૂલટિપ અનુવાદક માઉસઓવર ટેક્સ્ટનું ભાષાંતર કરે છે" diff --git a/public/_locales/hi/messages.json b/public/_locales/hi/messages.json index 6cb0ba8a..ac54246c 100644 --- a/public/_locales/hi/messages.json +++ b/public/_locales/hi/messages.json @@ -162,7 +162,7 @@ "message": "Title " }, "appName": { - "message": "माउस टूलटिप अनुवादक With TTS Voice Speech translator" + "message": "माउस टूलटिप अनुवादक With Voice Speech translator" }, "appDesc": { "message": "माउस टूलटिप ट्रांसलेटर अनुवाद करें माउसओवर पाठ Google अनुवाद का उपयोग करके" diff --git a/public/_locales/hu/messages.json b/public/_locales/hu/messages.json index 074e7980..edc653d1 100644 --- a/public/_locales/hu/messages.json +++ b/public/_locales/hu/messages.json @@ -162,7 +162,7 @@ "message": "Title " }, "appName": { - "message": "Egér ToolTip fordító : subtitle & epub reader translator" + "message": "Egér ToolTip fordító : Subtitle Epub Reader Translator" }, "appDesc": { "message": "Egér ToolTip Translator fordítása MouseOver szöveget a Google Translate segítségével" diff --git a/public/_locales/it/messages.json b/public/_locales/it/messages.json index cb55be07..cbc117f1 100644 --- a/public/_locales/it/messages.json +++ b/public/_locales/it/messages.json @@ -162,7 +162,7 @@ "message": "Title " }, "appName": { - "message": "Traduttore di tooltip del mouse With TTS and OCR" + "message": "Traduttore di tooltip del mouse With TTS OCR" }, "appDesc": { "message": "Traduttore di tooltip del mouse Translate Testo del mouseover usando Google Translate" diff --git a/public/_locales/kn/messages.json b/public/_locales/kn/messages.json index bea558d3..0121a60f 100644 --- a/public/_locales/kn/messages.json +++ b/public/_locales/kn/messages.json @@ -162,7 +162,7 @@ "message": "Title " }, "appName": { - "message": "ಮೌಸ್ ಟೂಲ್ಟಿಪ್ ಅನುವಾದಕ : Select to Translate" + "message": "ಮೌಸ್ ಟೂಲ್ಟಿಪ್ ಅನುವಾದಕ: Select to Translate" }, "appDesc": { "message": "ಮೌಸ್ ಟೂಲ್ಟಿಪ್ ಅನುವಾದಕ ಗೂಗಲ್ ಅನುವಾದವನ್ನು ಬಳಸಿಕೊಂಡು ಮೌಸೋವರ್ ಪಠ್ಯವನ್ನು ಅನುವಾದಿಸಿ" diff --git a/public/_locales/lt/messages.json b/public/_locales/lt/messages.json index d7dd5635..1ec40012 100644 --- a/public/_locales/lt/messages.json +++ b/public/_locales/lt/messages.json @@ -162,7 +162,7 @@ "message": "Title " }, "appName": { - "message": "Pelės patarimų vertėjas : Translate Youtube and Manga " + "message": "Pelės patarimų vertėjas : Translate Youtube" }, "appDesc": { "message": "Pelės patarimo vertėjas vertėjas versti pelės viršų" diff --git a/public/_locales/lv/messages.json b/public/_locales/lv/messages.json index e25e270e..5cc1880e 100644 --- a/public/_locales/lv/messages.json +++ b/public/_locales/lv/messages.json @@ -162,7 +162,7 @@ "message": "Title " }, "appName": { - "message": "Peles rīku padomu tulkotājs : Translate epub viewer" + "message": "Peles rīku padomu tulkotājs : Translate Manga, Epub Viewer" }, "appDesc": { "message": "Peles rīka padomu tulkotājs tulkot peles pārsniegšanas tekstu, izmantojot Google tulkojumu" diff --git a/public/_locales/ml/messages.json b/public/_locales/ml/messages.json index 919b64a4..796cedb3 100644 --- a/public/_locales/ml/messages.json +++ b/public/_locales/ml/messages.json @@ -162,7 +162,7 @@ "message": "Title " }, "appName": { - "message": "മൗസ് ടൂൾടിപ്പ് പരിഭാഷകൻ : translate pdf ebook subtitle" + "message": "മൗസ് ടൂൾടിപ്പ് പരിഭാഷകൻ : translate pdf subtitle" }, "appDesc": { "message": "മ mouse സ് ടൂൾടിപ്പ് ട്രാൻസ്ലേറ്റർ വിവർത്തനം ചെയ്യുക മസോവർ ടെക്സ്റ്റ് Google വിവർത്തനം ഉപയോഗിച്ച്" diff --git a/public/_locales/ms/messages.json b/public/_locales/ms/messages.json index 0d22f9e8..00d9a4f1 100644 --- a/public/_locales/ms/messages.json +++ b/public/_locales/ms/messages.json @@ -162,7 +162,7 @@ "message": "Title " }, "appName": { - "message": "Penterjemah Tooltip Mouse for Education Learning" + "message": "Penterjemah Tooltip Mouse for PDF GOOGLE DOCS" }, "appDesc": { "message": "Penterjemah Tooltip Mouse Terjemahkan Teks Mouseover Menggunakan Google Translate" diff --git a/public/_locales/nl/messages.json b/public/_locales/nl/messages.json index f8d06eea..096747c3 100644 --- a/public/_locales/nl/messages.json +++ b/public/_locales/nl/messages.json @@ -162,7 +162,7 @@ "message": "Title " }, "appName": { - "message": "Muise -gereedschap vertaler with translate ebook viewer" + "message": "Muise -gereedschap vertaler with translate chatgpt, ebook viewer" }, "appDesc": { "message": "Muis Toltip Translator vertaalt mouseover -tekst met behulp van Google Translate" diff --git a/public/_locales/no/messages.json b/public/_locales/no/messages.json index ae16fc1b..c3fe3692 100644 --- a/public/_locales/no/messages.json +++ b/public/_locales/no/messages.json @@ -162,7 +162,7 @@ "message": "Title " }, "appName": { - "message": "Mus ToolTip Translator : translate writing text" + "message": "Mus ToolTip Translator : PDF, Manga" }, "appDesc": { "message": "Mus ToolTip Translator Translate Mouseover -tekst ved hjelp av Google Translate" diff --git a/public/_locales/pt_BR/messages.json b/public/_locales/pt_BR/messages.json index a33ff0c8..ca095fa9 100644 --- a/public/_locales/pt_BR/messages.json +++ b/public/_locales/pt_BR/messages.json @@ -162,7 +162,7 @@ "message": "Title " }, "appName": { - "message": "Tradutor da dica de ferramenta do mouse" + "message": "Tradutor da dica de ferramenta do mouse With PDF Viewer" }, "appDesc": { "message": "Mouse Tooltip Tradutor Traduzir Texto do MouseOver usando o Google Translate" diff --git a/public/_locales/ro/messages.json b/public/_locales/ro/messages.json index 7026ca26..aa026d46 100644 --- a/public/_locales/ro/messages.json +++ b/public/_locales/ro/messages.json @@ -162,7 +162,7 @@ "message": "Title " }, "appName": { - "message": "Traducător de instrumente de mouse : Learn Language" + "message": "Traducător de instrumente de mouse for TTS PDF" }, "appDesc": { "message": "Traducător de instrumente de mouse -ul traduce textul mouseover folosind Google Translate" diff --git a/public/_locales/sk/messages.json b/public/_locales/sk/messages.json index 8cdb34e3..fed2ee6f 100644 --- a/public/_locales/sk/messages.json +++ b/public/_locales/sk/messages.json @@ -162,7 +162,7 @@ "message": "Title " }, "appName": { - "message": "Prekladateľ myši With PDF Viewer and Speech Voice Reader" + "message": "Prekladateľ myši : Voice Speech Reader Translator" }, "appDesc": { "message": "Prekladač prekladateľ myši prekladač Mouseover text pomocou prekladu Google" diff --git a/public/_locales/sr/messages.json b/public/_locales/sr/messages.json index bfa0e88b..5122e332 100644 --- a/public/_locales/sr/messages.json +++ b/public/_locales/sr/messages.json @@ -162,7 +162,7 @@ "message": "Title " }, "appName": { - "message": "Моусе Тоолтип Транслатор : OCR Translator" + "message": "Моусе Тоолтип Транслатор : Manga OCR Translator" }, "appDesc": { "message": "Моусе Тоолтип преводилац Преведи текст миша помоћу Гоогле Транслате" diff --git a/public/_locales/ta/messages.json b/public/_locales/ta/messages.json index a08116a1..dfd3f68e 100644 --- a/public/_locales/ta/messages.json +++ b/public/_locales/ta/messages.json @@ -162,7 +162,7 @@ "message": "Title " }, "appName": { - "message": "சுட்டி உதவிக்குறிப்பு மொழிபெயர்ப்பாளர் With PDF Reader and ebook reader translator" + "message": "சுட்டி உதவிக்குறிப்பு மொழிபெயர்ப்பாளர் With PDF ebook reader" }, "appDesc": { "message": "மவுஸ் உதவிக்குறிப்பு மொழிபெயர்ப்பாளர் கூகிள் மொழிபெயர்ப்பைப் பயன்படுத்தி மவுஸ்ஓவர் உரையை மொழிபெயர்க்கவும்" diff --git a/public/_locales/te/messages.json b/public/_locales/te/messages.json index 5569eee8..85b06929 100644 --- a/public/_locales/te/messages.json +++ b/public/_locales/te/messages.json @@ -162,7 +162,7 @@ "message": "Title " }, "appName": { - "message": "మౌస్ టూల్టిప్ అనువాదకుడు : Web Translator" + "message": "మౌస్ టూల్టిప్ అనువాదకుడు : Translate manga" }, "appDesc": { "message": "మౌస్ టూల్టిప్ అనువాదకుడు గూగుల్ అనువాదం ఉపయోగించి మౌస్‌ఓవర్ వచనాన్ని అనువదించండి" diff --git a/public/_locales/vi/messages.json b/public/_locales/vi/messages.json index 42be8734..c901d3a2 100644 --- a/public/_locales/vi/messages.json +++ b/public/_locales/vi/messages.json @@ -162,7 +162,7 @@ "message": "Title " }, "appName": { - "message": "Chuột Tooltip Translator" + "message": "Chuột Tooltip Translator with PDF TTS" }, "appDesc": { "message": "Chuột Tooltip Translator Dịch văn bản Mouseover bằng Google Dịch" diff --git a/src/contentScript.js b/src/contentScript.js index 7c806ebf..911a4288 100644 --- a/src/contentScript.js +++ b/src/contentScript.js @@ -7,6 +7,7 @@ import tippy, { followCursor, hideAll } from "tippy.js"; import { encode } from "he"; import matchUrl from "match-url-wildcard"; import delay from "delay"; +import { waitUntil } from "async-wait-until"; import { debounce } from "throttle-debounce"; // import * as GoogleDocsUtils from "google-docs-utils"; @@ -24,7 +25,8 @@ var mouseTarget = null; var activatedWord = null; var mouseMoved = false; var mouseMovedCount = 0; -var keyDownList = {}; //use key down for enable translation partially +var keyDownList = { always: true }; //use key down for enable translation partially +var keyDownReleaseList = {}; var style; let selectedText = ""; var destructionEvent = "destructmyextension_MouseTooltipTranslator"; // + chrome.runtime.id; @@ -33,11 +35,13 @@ const { signal } = controller; var mouseoverInterval; var writingField = 'input[type="text"], input[type="search"], input:not([type]), textarea, [contenteditable="true"], [role=textbox], [spellcheck]'; -var isYoutubeDetected = false; +var isYoutubeOn = false; var delayTime = 700; var isBlobPdf = false; var prevWordParam = []; var isGoogleDoc = false; +var mouseKeyMap = ["ClickLeft", "ClickMiddle", "ClickRight"]; +var prevTooltipText = ""; //tooltip core====================================================================== $(async function initMouseTooltipTranslator() { @@ -98,21 +102,25 @@ function startTextSelectDetector() { //process detected word async function processWord(word, actionType, range) { prevWordParam = Array.prototype.slice.call(arguments); //record args + word = util.filterWord(word); //filter out one that is url,no normal char + var isTooltipOn = keyDownList[setting["showTooltipWhen"]]; + var isTtsOn = keyDownList[setting["TTSWhen"]]; + applyReleaseKeydownList(); // skip if mouse target is tooltip + //hide tooltip, if activated word exist and current word is none + //do nothing, if no new word or no word change, or if isTooltipOn isTtsOn both are down + //if isTooltipOn is off, hide tooltip if (checkMouseTargetIsTooltip()) { return; - } - word = util.filterWord(word); //filter out one that is url,no normal char - - //hide tooltip, if activated word exist and current word is none - //do nothing, if no new word or no word change - if (!word && activatedWord) { + } else if (!word && activatedWord) { activatedWord = word; hideTooltip(); return; } else if (activatedWord == word || !word) { return; + } else if (!isTooltipOn) { + hideTooltip(); } //stage current processing word @@ -140,16 +148,19 @@ async function processWord(word, actionType, range) { //if tooltip is on or activation key is pressed, show tooltip //if current word is recent activatedWord - if ( - setting["showTooltipWhen"] == "always" || - keyDownList[setting["showTooltipWhen"]] - ) { - var tooltipText = wrapInlineHtml( - translatedText, - transliteration, - targetLang - ); - showTooltip(tooltipText); + if (isTooltipOn) { + var tooltipTransliteration = + setting["useTransliteration"] == "true" ? transliteration : ""; + var tooltipLang = + setting["showSourceLang"] == "true" + ? util.langListOpposite[sourceLang] + : ""; + var tooltipText = wrapRtlHtml(translatedText, targetLang); + tooltipText += concatTooltipText(tooltipTransliteration, tooltipLang); + var resetPrevTooltip = prevTooltipText != tooltipText; + prevTooltipText = tooltipText; + + showTooltip(tooltipText, resetPrevTooltip); requestRecordTooltipText( word, translatedText, @@ -158,12 +169,10 @@ async function processWord(word, actionType, range) { actionType ); highlightText(range); - } else { - hideTooltip(); } //if use_tts is on or activation key is pressed, do tts - if (setting["TTSWhen"] == "always" || keyDownList[setting["TTSWhen"]]) { + if (isTtsOn) { var wordWithoutEmoji = util.filterEmoji(word); requestTTS(wordWithoutEmoji, sourceLang, translatedText, targetLang); } @@ -198,10 +207,12 @@ function highlightText(range) { } function restartWordProcess() { - // mouseover text will be trigger when no activate word + //trigger mouseover text by reset activate word //restart selected text activatedWord = null; - processWord(...prevWordParam); + if (selectedText) { + processWord(...prevWordParam); + } } function getDetectType() { @@ -238,14 +249,14 @@ function checkWindowFocus() { return mouseMoved && document.visibilityState == "visible"; } -function showTooltip(text) { - hideTooltip(true); //reset tooltip arrow +function showTooltip(text, resetPrevTooltip) { + hideTooltip(resetPrevTooltip); //reset tooltip arrow tooltip?.setContent(text); tooltip?.show(); } -function hideTooltip(immediately = false) { - if (immediately) { +function hideTooltip(resetPrevTooltip = false) { + if (resetPrevTooltip) { hideAll({ duration: 0 }); //hide all tippy } tooltip?.hide(); @@ -270,26 +281,27 @@ async function translateWithReverse(word, sourceLang, targetLang, reverseLang) { return response; } -function wrapInlineHtml(translatedText, transliteration, targetLang) { - var text = ` ${encode(translatedText)} `; +function wrapRtlHtml(translatedText, targetLang) { + var text = `${encode( + translatedText + )}`; + return text; +} - if (transliteration && setting["useTransliteration"] == "true") { - text += ` -

-
${encode(transliteration)}
- `; +function concatTooltipText(...texts) { + texts = texts.filter((text) => text); + var concatText = ""; + for (var text of texts) { + concatText += `
${encode(text)}`; } - - return text; + return concatText; } //Translate Writing feature========================================================================================== -async function translateWriting(keyInput) { +async function translateWriting() { //check current focus is write box if ( - setting["keyDownTranslateWriting"] != keyInput || + !keyDownList[setting["keyDownTranslateWriting"]] || !getFocusedWritingBox() ) { return; @@ -359,6 +371,9 @@ function loadEventListener() { //detect activation hold key pressed addEventHandler("keydown", handleKeydown); addEventHandler("keyup", handleKeyup); + addEventHandler("mousedown", handleMouseKeyDown); + addEventHandler("mouseup", handleMouseKeyUp); + //detect tab switching to reset env addEventHandler("blur", handleBlur); } @@ -377,46 +392,57 @@ function handleMousemove(e) { function handleKeydown(e) { //if user pressed ctrl+f ctrl+a, hide tooltip - if ((e.code == "KeyF" || e.code == "KeyA") && e.ctrlKey) { + if (/KeyA|KeyF/.test(e.code) && e.ctrlKey) { mouseMoved = false; hideTooltip(); - return; - } - if (e.key == "Escape") { + } else if (e.code == "Escape") { requestStopTTS(); + } else if (e.key == "Alt") { + e.preventDefault(); // prevent alt site unfocus } - // check already pressed or key is not setting key - if ( - keyDownList[e.code] || - ![ - setting["showTooltipWhen"], - setting["TTSWhen"], - setting["keyDownDetectSwap"], - setting["keyDownTranslateWriting"], - setting["keyDownOCR"], - ].includes(e.code) - ) { - return; + holdKeydownList(e.code); +} + +function handleKeyup(e) { + releaseKeydownList(e.code); +} + +function handleMouseKeyDown(e) { + holdKeydownList(mouseKeyMap[e.button]); +} +function handleMouseKeyUp(e) { + releaseKeydownList(mouseKeyMap[e.button]); +} + +function holdKeydownList(key) { + // skip text key + if (key && !keyDownList[key] && !/Key|Digit|Numpad/.test(key)) { + keyDownList[key] = true; + restartWordProcess(); + translateWriting(); } +} - //reset status to restart process with keybind - keyDownList[e.code] = true; - restartWordProcess(); - translateWriting(e.code); - if (e.key == "Alt") { - e.preventDefault(); // prevent alt site unfocus +function releaseKeydownList(key) { + if (keyDownList[key]) { + keyDownReleaseList[key] = false; + // keyDownList[key] = false; + } + if (selectedText) { + applyReleaseKeydownList(); } } -function handleKeyup(e) { - if (keyDownList.hasOwnProperty(e.code)) { - keyDownList[e.code] = false; +function applyReleaseKeydownList() { + for (var key in keyDownReleaseList) { + keyDownList[key] = keyDownReleaseList[key]; } + keyDownReleaseList = {}; } function handleBlur(e) { - keyDownList = {}; //reset key press + keyDownList = { always: true }; //reset key press mouseMoved = false; mouseMovedCount = 0; selectedText = ""; @@ -528,8 +554,7 @@ function applyStyleSetting() { animation: setting["tooltipAnimation"], }); - style.html( - ` + var cssText = ` .tippy-box[data-theme~="custom"] { font-size: ${setting["tooltipFontSize"]}px !important; max-width: ${setting["tooltipWidth"]}px !important; @@ -573,32 +598,33 @@ function applyStyleSetting() { border: 2px solid CornflowerBlue; color: transparent !important; background: none !important; - } - ` + - (isYoutubeDetected - ? ` - #ytp-caption-window-container .ytp-caption-segment { - cursor: text !important; - user-select: text !important; - } - .caption-visual-line{ - display: flex !important; - align-items: stretch !important; - } - .captions-text .caption-visual-line:first-of-type:after { - content: '⣿⣿'; - background-color: #000000b8; - display: inline-block; - vertical-align: top; - opacity:0; - transition: opacity 0.7s ease-in-out; - } - .captions-text:hover .caption-visual-line:first-of-type:after { - opacity:1; - } - ` - : "") - ); + }`; + + cssText += isYoutubeOn + ? ` + #ytp-caption-window-container .ytp-caption-segment { + cursor: text !important; + user-select: text !important; + } + .caption-visual-line{ + display: flex !important; + align-items: stretch !important; + } + .captions-text .caption-visual-line:first-of-type:after { + content: '⣿⣿'; + background-color: #000000b8; + display: inline-block; + vertical-align: top; + opacity:0; + transition: opacity 0.7s ease-in-out; + } + .captions-text:hover .caption-visual-line:first-of-type:after { + opacity:1; + } + ` + : ""; + + style.html(cssText); } // url check and element env=============================================================== @@ -692,14 +718,15 @@ async function checkYoutube() { ) { return; } - isYoutubeDetected = true; + isYoutubeOn = true; await util.injectScript("youtube.js"); initYoutubePlayer(); addCaptionButtonListener(); } async function addCaptionButtonListener() { - await delay(2000); + await waitUntil(() => $(".ytp-subtitles-button").get(0)); + $(".ytp-subtitles-button").on("click", (e) => { handleCaptionOnOff(); }); @@ -723,7 +750,7 @@ function playPlayer() { util.postMessage({ type: "playPlayer" }); } function initYoutubePlayer() { - if (isYoutubeDetected) { + if (isYoutubeOn) { util.postMessage({ type: "initYoutubePlayer", targetLang: setting["translateTarget"], @@ -734,7 +761,7 @@ function initYoutubePlayer() { } function checkMouseTargetIsYoutubeSubtitle() { - if (!isYoutubeDetected || !$(mouseTarget).is(".ytp-caption-segment")) { + if (!isYoutubeOn || !$(mouseTarget).is(".ytp-caption-segment")) { return; } // make subtitle selectable diff --git a/src/popup.vue b/src/popup.vue index 2f8f66fe..b17f6429 100644 --- a/src/popup.vue +++ b/src/popup.vue @@ -238,115 +238,9 @@ import * as util from "/src/util"; import { isProxy, toRaw } from "vue"; -var langList = { - Afrikaans: "af", - Albanian: "sq", - Amharic: "am", - Arabic: "ar", - Armenian: "hy", - Azerbaijani: "az", - Basque: "eu", - Belarusian: "be", - Bengali: "bn", - Bosnian: "bs", - Bulgarian: "bg", - Catalan: "ca", - Cebuano: "ceb", - Chichewa: "ny", - "Chinese Simplified": "zh-CN", - "Chinese Traditional": "zh-TW", - Corsican: "co", - Croatian: "hr", - Czech: "cs", - Danish: "da", - Dutch: "nl", - English: "en", - Esperanto: "eo", - Estonian: "et", - Filipino: "tl", - Finnish: "fi", - French: "fr", - Frisian: "fy", - Galician: "gl", - Georgian: "ka", - German: "de", - Greek: "el", - Gujarati: "gu", - "Haitian Creole": "ht", - Hausa: "ha", - Hawaiian: "haw", - Hebrew: "iw", - Hindi: "hi", - Hmong: "hmn", - Hungarian: "hu", - Icelandic: "is", - Igbo: "ig", - Indonesian: "id", - Irish: "ga", - Italian: "it", - Japanese: "ja", - Javanese: "jw", - Kannada: "kn", - Kazakh: "kk", - Khmer: "km", - Korean: "ko", - "Kurdish (Kurmanji)": "ku", - Kyrgyz: "ky", - Lao: "lo", - Latin: "la", - Latvian: "lv", - Lithuanian: "lt", - Luxembourgish: "lb", - Macedonian: "mk", - Malagasy: "mg", - Malay: "ms", - Malayalam: "ml", - Maltese: "mt", - Maori: "mi", - Marathi: "mr", - Mongolian: "mn", - "Myanmar (Burmese)": "my", - Nepali: "ne", - Norwegian: "no", - Pashto: "ps", - Persian: "fa", - Polish: "pl", - Portuguese: "pt", - Punjabi: "pa", - Romanian: "ro", - Russian: "ru", - Samoan: "sm", - "Scots Gaelic": "gd", - Serbian: "sr", - Sesotho: "st", - Shona: "sn", - Sindhi: "sd", - Sinhala: "si", - Slovak: "sk", - Slovenian: "sl", - Somali: "so", - Spanish: "es", - Sundanese: "su", - Swahili: "sw", - Swedish: "sv", - Tajik: "tg", - Tamil: "ta", - Telugu: "te", - Thai: "th", - Turkish: "tr", - Ukrainian: "uk", - Urdu: "ur", - Uyghur: "ug", - Uzbek: "uz", - Vietnamese: "vi", - Welsh: "cy", - Xhosa: "xh", - Yiddish: "yi", - Yoruba: "yo", - Zulu: "zu", -}; +var langList = util.langList; var langListWithAuto = util.concatJson({ Auto: "auto" }, langList); //copy lang and add auto -var langListOpposite = util.swapJsonKeyValue(langList); +var langListOpposite = util.langListOpposite; var toggleList = { On: "true", @@ -363,6 +257,9 @@ var keyList = { "Shift Right": "ShiftRight", "Meta Left": "MetaLeft", "Meta Right": "MetaRight", + "Click Left": "ClickLeft", + "Click Middle": "ClickMiddle", + "Click Right": "ClickRight", }; var ocrLangList = { @@ -668,6 +565,10 @@ var advancedTabData = { description: "Highlight Mouseover Text (Experimental)", optionList: toggleList, }, + showSourceLang: { + description: "Show Source Language (Experimental)", + optionList: toggleList, + }, }; var excludeTabData = { diff --git a/src/util/index.js b/src/util/index.js index 60182558..083403ff 100644 --- a/src/util/index.js +++ b/src/util/index.js @@ -23,6 +23,8 @@ var defaultData = { translateReverseTarget: "null", useTransliteration: "false", highlightMouseoverText: "false", + showSourceLang: "false", + // graphic tooltipFontSize: "14", tooltipWidth: "200", @@ -337,6 +339,115 @@ var bingTtsVoiceList = { zu: ["zu-ZA-ThandoNeural", "zu-ZA-ThembaNeural"], }; +export var langList = { + Afrikaans: "af", + Albanian: "sq", + Amharic: "am", + Arabic: "ar", + Armenian: "hy", + Azerbaijani: "az", + Basque: "eu", + Belarusian: "be", + Bengali: "bn", + Bosnian: "bs", + Bulgarian: "bg", + Catalan: "ca", + Cebuano: "ceb", + Chichewa: "ny", + "Chinese Simplified": "zh-CN", + "Chinese Traditional": "zh-TW", + Corsican: "co", + Croatian: "hr", + Czech: "cs", + Danish: "da", + Dutch: "nl", + English: "en", + Esperanto: "eo", + Estonian: "et", + Filipino: "tl", + Finnish: "fi", + French: "fr", + Frisian: "fy", + Galician: "gl", + Georgian: "ka", + German: "de", + Greek: "el", + Gujarati: "gu", + "Haitian Creole": "ht", + Hausa: "ha", + Hawaiian: "haw", + Hebrew: "iw", + Hindi: "hi", + Hmong: "hmn", + Hungarian: "hu", + Icelandic: "is", + Igbo: "ig", + Indonesian: "id", + Irish: "ga", + Italian: "it", + Japanese: "ja", + Javanese: "jw", + Kannada: "kn", + Kazakh: "kk", + Khmer: "km", + Korean: "ko", + "Kurdish (Kurmanji)": "ku", + Kyrgyz: "ky", + Lao: "lo", + Latin: "la", + Latvian: "lv", + Lithuanian: "lt", + Luxembourgish: "lb", + Macedonian: "mk", + Malagasy: "mg", + Malay: "ms", + Malayalam: "ml", + Maltese: "mt", + Maori: "mi", + Marathi: "mr", + Mongolian: "mn", + "Myanmar (Burmese)": "my", + Nepali: "ne", + Norwegian: "no", + Pashto: "ps", + Persian: "fa", + Polish: "pl", + Portuguese: "pt", + Punjabi: "pa", + Romanian: "ro", + Russian: "ru", + Samoan: "sm", + "Scots Gaelic": "gd", + Serbian: "sr", + Sesotho: "st", + Shona: "sn", + Sindhi: "sd", + Sinhala: "si", + Slovak: "sk", + Slovenian: "sl", + Somali: "so", + Spanish: "es", + Sundanese: "su", + Swahili: "sw", + Swedish: "sv", + Tajik: "tg", + Tamil: "ta", + Telugu: "te", + Thai: "th", + Turkish: "tr", + Ukrainian: "uk", + Urdu: "ur", + Uyghur: "ug", + Uzbek: "uz", + Vietnamese: "vi", + Welsh: "cy", + Xhosa: "xh", + Yiddish: "yi", + Yoruba: "yo", + Zulu: "zu", +}; +export var langListOpposite = swapJsonKeyValue(langList); + var googleTranslateTtsLangList = [ "af", "sq",