fix: contextMenus setting

This commit is contained in:
Gabe Yuan
2023-12-15 11:43:01 +08:00
parent 34adb2660b
commit 7e014e7385
4 changed files with 72 additions and 61 deletions

View File

@@ -6,7 +6,7 @@ import { sleep } from "../../libs/utils";
import { isGm } from "../../libs/client";
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 [showBtn, setShowBtn] = useState(false);
const [selectedText, setSelText] = useState("");
@@ -88,15 +88,16 @@ export default function Slection({ tranboxSetting, transApis }) {
// 注册菜单
try {
const menuCommandIds = [];
menuCommandIds.push(
GM.registerMenuCommand(
"Translate Selected Text (Alt+S)",
(event) => {
handleTranbox();
},
"S"
)
);
contextMenus &&
menuCommandIds.push(
GM.registerMenuCommand(
"Translate Selected Text (Alt+S)",
(event) => {
handleTranbox();
},
"S"
)
);
return () => {
menuCommandIds.forEach((id) => {
@@ -106,7 +107,7 @@ export default function Slection({ tranboxSetting, transApis }) {
} catch (err) {
console.log("[registerMenuCommand]", err);
}
}, [handleTranbox]);
}, [handleTranbox, contextMenus]);
return (
<>