Skip to content

Commit

Permalink
fix google doc writing
Browse files Browse the repository at this point in the history
  • Loading branch information
ttop32 committed Feb 5, 2024
1 parent ee7fdf2 commit 9169427
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions src/contentScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down

0 comments on commit 9169427

Please sign in to comment.