Only translate text when specified key pressed (#254)

This commit is contained in:
Nutr1t07 2021-01-07 17:37:07 +08:00 committed by GitHub
parent 25b8ade213
commit a6db23f5fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 82 additions and 0 deletions

View file

@ -95,6 +95,30 @@
"isDisabledInTextFieldsCaptionLabel": {
"message": "Don't display translation button or panel when selecting text in a text field."
},
"ifOnlyTranslateWhenShiftPressedLabel": {
"message": "Translate on specified key pressed"
},
"ifOnlyTranslateWhenShiftPressedCaptionLabel": {
"message": "Only display translation on Shift key pressed"
},
"specifiedKeyLabel": {
"message": "Specified Key"
},
"specifyKeyLabel": {
"message": "Specify Key"
},
"shiftLabel": {
"message": "Shift"
},
"ctrlLabel": {
"message": "Ctrl"
},
"altLabel": {
"message": "Alt"
},
"cmdLabel": {
"message": "Command"
},
"disableUrlListLabel": {
"message": "URL list to disable translation"
},

View file

@ -38,6 +38,26 @@ const handleMouseUp = async e => {
if (isInContentEditable()) return;
}
if (getSettings("ifOnlyTranslateWhenShiftPressed")) {
const spKey = getSettings("specifiedKey")
switch(spKey){
case "shift":
if (!e.shiftKey) return;
break;
case "alt":
if (!e.altKey) return;
break;
case "ctrl":
if (!e.ctrlKey) return;
break;
case "cmd":
if (!e.metaKey) return;
break;
default:
break;
}
}
const clickedPosition = { x: e.clientX, y: e.clientY };
const selectedPosition = getSelectedPosition();
showTranslateContainer(selectedText, selectedPosition, clickedPosition);

View file

@ -87,6 +87,44 @@ export default [
}
]
},
{
title: "specifiedKeyLabel",
captions: [],
type: "none",
childElements:[
{
id: "ifOnlyTranslateWhenShiftPressed",
title: "ifOnlyTranslateWhenShiftPressedLabel",
captions: ["ifOnlyTranslateWhenShiftPressedCaptionLabel"],
type: "checkbox",
default: false
},
{
id: "specifiedKey",
title: "specifiedKeyLabel",
captions: [],
type: "select",
default: "shift",
options: [
{
name: "shiftLabel",
value: "shift"
},
{
name: "ctrlLabel",
value: "ctrl"
},
{
name: "altLabel",
value: "alt"
},
{
name: "cmdLabel",
value: "cmd"
}]
}
]
},
{
id: "ifChangeSecondLangOnPage",
title: "ifChangeSecondLangLabel",