fix: contextMenus setting
This commit is contained in:
@@ -142,7 +142,11 @@ async function showFab(translator) {
|
|||||||
* @param {*} param0
|
* @param {*} param0
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
function showTransbox({ tranboxSetting = DEFAULT_TRANBOX_SETTING, transApis }) {
|
function showTransbox({
|
||||||
|
contextMenus = true,
|
||||||
|
tranboxSetting = DEFAULT_TRANBOX_SETTING,
|
||||||
|
transApis,
|
||||||
|
}) {
|
||||||
if (!tranboxSetting?.transOpen) {
|
if (!tranboxSetting?.transOpen) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -163,7 +167,11 @@ function showTransbox({ tranboxSetting = DEFAULT_TRANBOX_SETTING, transApis }) {
|
|||||||
ReactDOM.createRoot(shadowRootElement).render(
|
ReactDOM.createRoot(shadowRootElement).render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
<CacheProvider value={cache}>
|
<CacheProvider value={cache}>
|
||||||
<Slection tranboxSetting={tranboxSetting} transApis={transApis} />
|
<Slection
|
||||||
|
contextMenus={contextMenus}
|
||||||
|
tranboxSetting={tranboxSetting}
|
||||||
|
transApis={transApis}
|
||||||
|
/>
|
||||||
</CacheProvider>
|
</CacheProvider>
|
||||||
</React.StrictMode>
|
</React.StrictMode>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -95,40 +95,42 @@ export default function Action({ translator, fab }) {
|
|||||||
// 注册菜单
|
// 注册菜单
|
||||||
try {
|
try {
|
||||||
const menuCommandIds = [];
|
const menuCommandIds = [];
|
||||||
menuCommandIds.push(
|
const { contextMenus = true } = translator.setting;
|
||||||
GM.registerMenuCommand(
|
contextMenus &&
|
||||||
"Toggle Translate (Alt+q)",
|
menuCommandIds.push(
|
||||||
(event) => {
|
GM.registerMenuCommand(
|
||||||
translator.toggle();
|
"Toggle Translate (Alt+q)",
|
||||||
sendIframeMsg(MSG_TRANS_TOGGLE);
|
(event) => {
|
||||||
setShowPopup(false);
|
translator.toggle();
|
||||||
},
|
sendIframeMsg(MSG_TRANS_TOGGLE);
|
||||||
"Q"
|
setShowPopup(false);
|
||||||
),
|
},
|
||||||
GM.registerMenuCommand(
|
"Q"
|
||||||
"Toggle Style (Alt+c)",
|
),
|
||||||
(event) => {
|
GM.registerMenuCommand(
|
||||||
translator.toggleStyle();
|
"Toggle Style (Alt+c)",
|
||||||
sendIframeMsg(MSG_TRANS_TOGGLE_STYLE);
|
(event) => {
|
||||||
setShowPopup(false);
|
translator.toggleStyle();
|
||||||
},
|
sendIframeMsg(MSG_TRANS_TOGGLE_STYLE);
|
||||||
"C"
|
setShowPopup(false);
|
||||||
),
|
},
|
||||||
GM.registerMenuCommand(
|
"C"
|
||||||
"Open Menu (Alt+k)",
|
),
|
||||||
(event) => {
|
GM.registerMenuCommand(
|
||||||
setShowPopup((pre) => !pre);
|
"Open Menu (Alt+k)",
|
||||||
},
|
(event) => {
|
||||||
"K"
|
setShowPopup((pre) => !pre);
|
||||||
),
|
},
|
||||||
GM.registerMenuCommand(
|
"K"
|
||||||
"Open Setting (Alt+o)",
|
),
|
||||||
(event) => {
|
GM.registerMenuCommand(
|
||||||
window.open(process.env.REACT_APP_OPTIONSPAGE, "_blank");
|
"Open Setting (Alt+o)",
|
||||||
},
|
(event) => {
|
||||||
"O"
|
window.open(process.env.REACT_APP_OPTIONSPAGE, "_blank");
|
||||||
)
|
},
|
||||||
);
|
"O"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
menuCommandIds.forEach((id) => {
|
menuCommandIds.forEach((id) => {
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ export default function Settings() {
|
|||||||
value = limitNumber(value, 0, 4);
|
value = limitNumber(value, 0, 4);
|
||||||
break;
|
break;
|
||||||
case "contextMenus":
|
case "contextMenus":
|
||||||
sendBgMsg(MSG_CONTEXT_MENUS, { contextMenus: value });
|
isExt && sendBgMsg(MSG_CONTEXT_MENUS, { contextMenus: value });
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
@@ -214,6 +214,19 @@ export default function Settings() {
|
|||||||
</Select>
|
</Select>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
|
||||||
|
<FormControl size="small">
|
||||||
|
<InputLabel>{i18n("add_context_menus")}</InputLabel>
|
||||||
|
<Select
|
||||||
|
name="contextMenus"
|
||||||
|
value={contextMenus}
|
||||||
|
label={i18n("add_context_menus")}
|
||||||
|
onChange={handleChange}
|
||||||
|
>
|
||||||
|
<MenuItem value={false}>{i18n("disable")}</MenuItem>
|
||||||
|
<MenuItem value={true}>{i18n("enable")}</MenuItem>
|
||||||
|
</Select>
|
||||||
|
</FormControl>
|
||||||
|
|
||||||
<FormControl size="small">
|
<FormControl size="small">
|
||||||
<InputLabel>{i18n("detect_lang_remote")}</InputLabel>
|
<InputLabel>{i18n("detect_lang_remote")}</InputLabel>
|
||||||
<Select
|
<Select
|
||||||
@@ -248,19 +261,6 @@ export default function Settings() {
|
|||||||
|
|
||||||
{isExt ? (
|
{isExt ? (
|
||||||
<>
|
<>
|
||||||
<FormControl size="small">
|
|
||||||
<InputLabel>{i18n("add_context_menus")}</InputLabel>
|
|
||||||
<Select
|
|
||||||
name="contextMenus"
|
|
||||||
value={contextMenus}
|
|
||||||
label={i18n("add_context_menus")}
|
|
||||||
onChange={handleChange}
|
|
||||||
>
|
|
||||||
<MenuItem value={false}>{i18n("disable")}</MenuItem>
|
|
||||||
<MenuItem value={true}>{i18n("enable")}</MenuItem>
|
|
||||||
</Select>
|
|
||||||
</FormControl>
|
|
||||||
|
|
||||||
<FormControl size="small">
|
<FormControl size="small">
|
||||||
<InputLabel>{i18n("if_clear_cache")}</InputLabel>
|
<InputLabel>{i18n("if_clear_cache")}</InputLabel>
|
||||||
<Select
|
<Select
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { sleep } from "../../libs/utils";
|
|||||||
import { isGm } from "../../libs/client";
|
import { isGm } from "../../libs/client";
|
||||||
import { MSG_OPEN_TRANBOX, DEFAULT_TRANBOX_SHORTCUT } from "../../config";
|
import { MSG_OPEN_TRANBOX, DEFAULT_TRANBOX_SHORTCUT } from "../../config";
|
||||||
|
|
||||||
export default function Slection({ tranboxSetting, transApis }) {
|
export default function Slection({ contextMenus, tranboxSetting, transApis }) {
|
||||||
const [showBox, setShowBox] = useState(false);
|
const [showBox, setShowBox] = useState(false);
|
||||||
const [showBtn, setShowBtn] = useState(false);
|
const [showBtn, setShowBtn] = useState(false);
|
||||||
const [selectedText, setSelText] = useState("");
|
const [selectedText, setSelText] = useState("");
|
||||||
@@ -88,15 +88,16 @@ export default function Slection({ tranboxSetting, transApis }) {
|
|||||||
// 注册菜单
|
// 注册菜单
|
||||||
try {
|
try {
|
||||||
const menuCommandIds = [];
|
const menuCommandIds = [];
|
||||||
menuCommandIds.push(
|
contextMenus &&
|
||||||
GM.registerMenuCommand(
|
menuCommandIds.push(
|
||||||
"Translate Selected Text (Alt+S)",
|
GM.registerMenuCommand(
|
||||||
(event) => {
|
"Translate Selected Text (Alt+S)",
|
||||||
handleTranbox();
|
(event) => {
|
||||||
},
|
handleTranbox();
|
||||||
"S"
|
},
|
||||||
)
|
"S"
|
||||||
);
|
)
|
||||||
|
);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
menuCommandIds.forEach((id) => {
|
menuCommandIds.forEach((id) => {
|
||||||
@@ -106,7 +107,7 @@ export default function Slection({ tranboxSetting, transApis }) {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("[registerMenuCommand]", err);
|
console.log("[registerMenuCommand]", err);
|
||||||
}
|
}
|
||||||
}, [handleTranbox]);
|
}, [handleTranbox, contextMenus]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
Reference in New Issue
Block a user