fix save rule

This commit is contained in:
Gabe Yuan
2023-09-12 17:20:56 +08:00
parent 5e8743dbb7
commit 56281f9e82
3 changed files with 55 additions and 55 deletions

View File

@@ -79,10 +79,13 @@ export default function Action({ translator, fab }) {
}, [translator]); }, [translator]);
useEffect(() => { useEffect(() => {
if (!isGm) {
return;
}
// 注册菜单 // 注册菜单
const menuCommandIds = [];
if (isGm) {
try { try {
const menuCommandIds = [];
menuCommandIds.push( menuCommandIds.push(
GM.registerMenuCommand( GM.registerMenuCommand(
"Toggle Translate (Alt+q)", "Toggle Translate (Alt+q)",
@@ -115,22 +118,15 @@ export default function Action({ translator, fab }) {
"O" "O"
) )
); );
} catch (err) {
console.log("[registerMenuCommand]", err);
}
}
return () => { return () => {
if (isGm) {
try {
menuCommandIds.forEach((id) => { menuCommandIds.forEach((id) => {
GM.unregisterMenuCommand(id); GM.unregisterMenuCommand(id);
}); });
} catch (err) {
//
}
}
}; };
} catch (err) {
console.log("[registerMenuCommand]", err);
}
}, [translator]); }, [translator]);
useEffect(() => { useEffect(() => {

View File

@@ -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>

View File

@@ -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);
} }