fix save rule
This commit is contained in:
@@ -79,58 +79,54 @@ export default function Action({ translator, fab }) {
|
|||||||
}, [translator]);
|
}, [translator]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// 注册菜单
|
if (!isGm) {
|
||||||
const menuCommandIds = [];
|
return;
|
||||||
if (isGm) {
|
|
||||||
try {
|
|
||||||
menuCommandIds.push(
|
|
||||||
GM.registerMenuCommand(
|
|
||||||
"Toggle Translate (Alt+q)",
|
|
||||||
(event) => {
|
|
||||||
translator.toggle();
|
|
||||||
setShowPopup(false);
|
|
||||||
},
|
|
||||||
"Q"
|
|
||||||
),
|
|
||||||
GM.registerMenuCommand(
|
|
||||||
"Toggle Style (Alt+c)",
|
|
||||||
(event) => {
|
|
||||||
translator.toggleStyle();
|
|
||||||
setShowPopup(false);
|
|
||||||
},
|
|
||||||
"C"
|
|
||||||
),
|
|
||||||
GM.registerMenuCommand(
|
|
||||||
"Open Menu (Alt+k)",
|
|
||||||
(event) => {
|
|
||||||
setShowPopup((pre) => !pre);
|
|
||||||
},
|
|
||||||
"K"
|
|
||||||
),
|
|
||||||
GM.registerMenuCommand(
|
|
||||||
"Open Setting (Alt+o)",
|
|
||||||
(event) => {
|
|
||||||
window.open(process.env.REACT_APP_OPTIONSPAGE, "_blank");
|
|
||||||
},
|
|
||||||
"O"
|
|
||||||
)
|
|
||||||
);
|
|
||||||
} catch (err) {
|
|
||||||
console.log("[registerMenuCommand]", err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return () => {
|
// 注册菜单
|
||||||
if (isGm) {
|
try {
|
||||||
try {
|
const menuCommandIds = [];
|
||||||
menuCommandIds.forEach((id) => {
|
menuCommandIds.push(
|
||||||
GM.unregisterMenuCommand(id);
|
GM.registerMenuCommand(
|
||||||
});
|
"Toggle Translate (Alt+q)",
|
||||||
} catch (err) {
|
(event) => {
|
||||||
//
|
translator.toggle();
|
||||||
}
|
setShowPopup(false);
|
||||||
}
|
},
|
||||||
};
|
"Q"
|
||||||
|
),
|
||||||
|
GM.registerMenuCommand(
|
||||||
|
"Toggle Style (Alt+c)",
|
||||||
|
(event) => {
|
||||||
|
translator.toggleStyle();
|
||||||
|
setShowPopup(false);
|
||||||
|
},
|
||||||
|
"C"
|
||||||
|
),
|
||||||
|
GM.registerMenuCommand(
|
||||||
|
"Open Menu (Alt+k)",
|
||||||
|
(event) => {
|
||||||
|
setShowPopup((pre) => !pre);
|
||||||
|
},
|
||||||
|
"K"
|
||||||
|
),
|
||||||
|
GM.registerMenuCommand(
|
||||||
|
"Open Setting (Alt+o)",
|
||||||
|
(event) => {
|
||||||
|
window.open(process.env.REACT_APP_OPTIONSPAGE, "_blank");
|
||||||
|
},
|
||||||
|
"O"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
menuCommandIds.forEach((id) => {
|
||||||
|
GM.unregisterMenuCommand(id);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
} catch (err) {
|
||||||
|
console.log("[registerMenuCommand]", err);
|
||||||
|
}
|
||||||
}, [translator]);
|
}, [translator]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -21,7 +21,12 @@ export default function Header({ setShowPopup }) {
|
|||||||
<IconButton onClick={handleHomepage}>
|
<IconButton onClick={handleHomepage}>
|
||||||
<HomeIcon />
|
<HomeIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<Box>
|
<Box
|
||||||
|
sx={{
|
||||||
|
userSelect: "none",
|
||||||
|
WebkitUserSelect: "none",
|
||||||
|
}}
|
||||||
|
>
|
||||||
{`${process.env.REACT_APP_NAME} v${process.env.REACT_APP_VERSION}`}
|
{`${process.env.REACT_APP_NAME} v${process.env.REACT_APP_VERSION}`}
|
||||||
</Box>
|
</Box>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|||||||
@@ -80,13 +80,12 @@ export default function Popup({ setShowPopup, translator: tran }) {
|
|||||||
|
|
||||||
const handleSaveRule = async () => {
|
const handleSaveRule = async () => {
|
||||||
try {
|
try {
|
||||||
let host = window.location.host;
|
let href = window.location.href;
|
||||||
if (isExt) {
|
if (isExt) {
|
||||||
const tab = await getTabInfo();
|
const tab = await getTabInfo();
|
||||||
const url = new URL(tab.url);
|
href = tab.url;
|
||||||
host = url.host;
|
|
||||||
}
|
}
|
||||||
saveRule({ ...rule, pattern: host });
|
saveRule({ ...rule, pattern: href });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("[save rule]", err);
|
console.log("[save rule]", err);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user