From 91694279c06e5adca5447a00518727b64dab3855 Mon Sep 17 00:00:00 2001 From: daniel k Date: Mon, 5 Feb 2024 17:51:50 +0900 Subject: [PATCH] fix google doc writing --- src/background.js | 3 ++- src/contentScript.js | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/background.js b/src/background.js index da7f745f..7bed38c3 100644 --- a/src/background.js +++ b/src/background.js @@ -97,13 +97,14 @@ async function translateWithReverse({ if ( !response.isBroken && targetLang == response.sourceLang && + // text == response.translatedText && reverseLang != "null" && targetLang != reverseLang ) { response = await translate({ text, sourceLang: response.sourceLang, - reverseLang, + targetLang: reverseLang, }); } return response; diff --git a/src/contentScript.js b/src/contentScript.js index 6dd50b1a..84909373 100644 --- a/src/contentScript.js +++ b/src/contentScript.js @@ -286,7 +286,7 @@ async function translateWriting() { // if is google doc do not check writing box if ( !keyDownList[setting["keyDownTranslateWriting"]] || - !util.getFocusedWritingBox() + (!util.getFocusedWritingBox() && !util.isGoogleDoc()) ) { return; } @@ -342,7 +342,11 @@ async function insertText(text) { if (!text) { return; } - pasteTextInputBox(text); + if (util.isGoogleDoc()) { + pasteTextGoogleDoc(text); + } else { + pasteTextInputBox(text); + } await delay(10); if (hasSelection()) { document.execCommand("insertText", false, text); @@ -355,7 +359,7 @@ function pasteTextInputBox(text) { } function pasteTextGoogleDoc(text) { // https://github.com/matthewsot/docs-plus - var el = document.getElementsByClassName("docs-texteventtarget-iframe")[0]; + var el = document.getElementsByClassName("docs-texteventtarget-iframe")?.[0]; el = el.contentDocument.querySelector("[contenteditable=true]"); pasteText(el, text); }