Add option to disable translation in text fields
This commit is contained in:
parent
6f43d626f0
commit
4a6f907c73
|
@ -85,6 +85,12 @@
|
||||||
"ifChangeSecondLangOnPageCaptionLabel": {
|
"ifChangeSecondLangOnPageCaptionLabel": {
|
||||||
"message": "Detects the language of the selected text, and if it is the same as the default target language, translate it into the second language."
|
"message": "Detects the language of the selected text, and if it is the same as the default target language, translate it into the second language."
|
||||||
},
|
},
|
||||||
|
"isDisabledInTextFieldsLabel": {
|
||||||
|
"message": "Disable translation in text fields"
|
||||||
|
},
|
||||||
|
"isDisabledInTextFieldsCaptionLabel": {
|
||||||
|
"message": "Don't display translation button or panel when selecting text in a text field."
|
||||||
|
},
|
||||||
"disableUrlListLabel": {
|
"disableUrlListLabel": {
|
||||||
"message": "URL list to disable translation"
|
"message": "URL list to disable translation"
|
||||||
},
|
},
|
||||||
|
|
|
@ -34,6 +34,10 @@ const handleMouseUp = async e => {
|
||||||
prevSelectedText = selectedText;
|
prevSelectedText = selectedText;
|
||||||
if (selectedText.length === 0) return;
|
if (selectedText.length === 0) return;
|
||||||
|
|
||||||
|
if (getSettings("isDisabledInTextFields")) {
|
||||||
|
if (isInContentEditable()) return;
|
||||||
|
}
|
||||||
|
|
||||||
const clickedPosition = { x: e.clientX, y: e.clientY };
|
const clickedPosition = { x: e.clientX, y: e.clientY };
|
||||||
const selectedPosition = getSelectedPosition();
|
const selectedPosition = getSelectedPosition();
|
||||||
showTranslateContainer(selectedText, selectedPosition, clickedPosition);
|
showTranslateContainer(selectedText, selectedPosition, clickedPosition);
|
||||||
|
@ -82,6 +86,13 @@ const getSelectedPosition = () => {
|
||||||
return selectedPosition;
|
return selectedPosition;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isInContentEditable = () => {
|
||||||
|
const element = document.activeElement;
|
||||||
|
if (element.tagName === "INPUT" || element.tagName === "TEXTAREA") return true;
|
||||||
|
if (element.contentEditable === "true") return true;
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
const handleKeyDown = e => {
|
const handleKeyDown = e => {
|
||||||
if (e.key === "Escape") {
|
if (e.key === "Escape") {
|
||||||
removeTranslatecontainer();
|
removeTranslatecontainer();
|
||||||
|
|
|
@ -94,14 +94,21 @@ export default [
|
||||||
type: "checkbox",
|
type: "checkbox",
|
||||||
default: false
|
default: false
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: "isDisabledInTextFields",
|
||||||
|
title: "isDisabledInTextFieldsLabel",
|
||||||
|
captions: ["isDisabledInTextFieldsCaptionLabel"],
|
||||||
|
type: "checkbox",
|
||||||
|
default: false,
|
||||||
|
new: true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
id: "disableUrlList",
|
id: "disableUrlList",
|
||||||
title: "disableUrlListLabel",
|
title: "disableUrlListLabel",
|
||||||
captions: ["disableUrlListCaptionLabel"],
|
captions: ["disableUrlListCaptionLabel"],
|
||||||
type: "textarea",
|
type: "textarea",
|
||||||
default: "",
|
default: "",
|
||||||
placeholder: "https://example.com/*\nhttps://example.net/*",
|
placeholder: "https://example.com/*\nhttps://example.net/*"
|
||||||
new: true
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue